WinCE may set the last error value even when functions succeed.

This commit is contained in:
chris_kohlhoff 2007-11-04 11:53:20 +00:00
parent e967d868b3
commit abc4444400

View File

@ -100,6 +100,10 @@ inline socket_type accept(socket_type s, socket_addr_type* addr,
}
#endif
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
clear_error(ec);
#endif
return new_s;
}
@ -114,14 +118,25 @@ inline int bind(socket_type s, const socket_addr_type* addr,
std::size_t addrlen, asio::error_code& ec)
{
clear_error(ec);
return error_wrapper(call_bind(&msghdr::msg_namelen, s, addr, addrlen), ec);
int result = error_wrapper(call_bind(
&msghdr::msg_namelen, s, addr, addrlen), ec);
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
#endif
return result;
}
inline int close(socket_type s, asio::error_code& ec)
{
clear_error(ec);
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
return error_wrapper(::closesocket(s), ec);
int result = error_wrapper(::closesocket(s), ec);
# if defined(UNDER_CE)
if (result == 0)
clear_error(ec);
# endif
return result;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
return error_wrapper(::close(s), ec);
#endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@ -130,7 +145,12 @@ inline int close(socket_type s, asio::error_code& ec)
inline int shutdown(socket_type s, int what, asio::error_code& ec)
{
clear_error(ec);
return error_wrapper(::shutdown(s, what), ec);
int result = error_wrapper(::shutdown(s, what), ec);
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
#endif
return result;
}
template <typename SockLenType>
@ -144,14 +164,24 @@ inline int connect(socket_type s, const socket_addr_type* addr,
std::size_t addrlen, asio::error_code& ec)
{
clear_error(ec);
return error_wrapper(call_connect(
int result = error_wrapper(call_connect(
&msghdr::msg_namelen, s, addr, addrlen), ec);
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
#endif
return result;
}
inline int listen(socket_type s, int backlog, asio::error_code& ec)
{
clear_error(ec);
return error_wrapper(::listen(s, backlog), ec);
int result = error_wrapper(::listen(s, backlog), ec);
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
#endif
return result;
}
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@ -217,6 +247,9 @@ inline int recv(socket_type s, buf* bufs, size_t count, int flags,
recv_buf_count, &bytes_transferred, &recv_flags, 0, 0), ec);
if (result != 0)
return -1;
# if defined(UNDER_CE)
clear_error(ec);
# endif
return bytes_transferred;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
msghdr msg = msghdr();
@ -242,6 +275,9 @@ inline int recvfrom(socket_type s, buf* bufs, size_t count, int flags,
*addrlen = (std::size_t)tmp_addrlen;
if (result != 0)
return -1;
# if defined(UNDER_CE)
clear_error(ec);
# endif
return bytes_transferred;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
msghdr msg = msghdr();
@ -268,6 +304,9 @@ inline int send(socket_type s, const buf* bufs, size_t count, int flags,
send_buf_count, &bytes_transferred, send_flags, 0, 0), ec);
if (result != 0)
return -1;
# if defined(UNDER_CE)
clear_error(ec);
# endif
return bytes_transferred;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
msghdr msg = msghdr();
@ -293,6 +332,9 @@ inline int sendto(socket_type s, const buf* bufs, size_t count, int flags,
send_buf_count, &bytes_transferred, flags, addr, addrlen, 0, 0), ec);
if (result != 0)
return -1;
# if defined(UNDER_CE)
clear_error(ec);
# endif
return bytes_transferred;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
msghdr msg = msghdr();
@ -327,6 +369,10 @@ inline socket_type socket(int af, int type, int protocol,
reinterpret_cast<const char*>(&optval), sizeof(optval));
}
# if defined(UNDER_CE)
clear_error(ec);
# endif
return s;
#elif defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__)
socket_type s = error_wrapper(::socket(af, type, protocol), ec);
@ -385,8 +431,13 @@ inline int setsockopt(socket_type s, int level, int optname,
return -1;
#else // defined(__BORLANDC__)
clear_error(ec);
return error_wrapper(call_setsockopt(&msghdr::msg_namelen,
int result = error_wrapper(call_setsockopt(&msghdr::msg_namelen,
s, level, optname, optval, optlen), ec);
# if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
# endif
return result;
#endif // defined(__BORLANDC__)
}
@ -455,6 +506,10 @@ inline int getsockopt(socket_type s, int level, int optname, void* optval,
*static_cast<DWORD*>(optval) = 1;
clear_error(ec);
}
# if defined(UNDER_CE)
if (result == 0)
clear_error(ec);
# endif
return result;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
clear_error(ec);
@ -490,8 +545,13 @@ inline int getpeername(socket_type s, socket_addr_type* addr,
std::size_t* addrlen, asio::error_code& ec)
{
clear_error(ec);
return error_wrapper(call_getpeername(
int result = error_wrapper(call_getpeername(
&msghdr::msg_namelen, s, addr, addrlen), ec);
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
#endif
return result;
}
template <typename SockLenType>
@ -508,8 +568,13 @@ inline int getsockname(socket_type s, socket_addr_type* addr,
std::size_t* addrlen, asio::error_code& ec)
{
clear_error(ec);
return error_wrapper(call_getsockname(
int result = error_wrapper(call_getsockname(
&msghdr::msg_namelen, s, addr, addrlen), ec);
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
#endif
return result;
}
inline int ioctl(socket_type s, long cmd, ioctl_arg_type* arg,
@ -517,7 +582,12 @@ inline int ioctl(socket_type s, long cmd, ioctl_arg_type* arg,
{
clear_error(ec);
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
return error_wrapper(::ioctlsocket(s, cmd, arg), ec);
int result = error_wrapper(::ioctlsocket(s, cmd, arg), ec);
# if defined(UNDER_CE)
if (result == 0)
clear_error(ec);
# endif
return result;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
return error_wrapper(::ioctl(s, cmd, arg), ec);
#endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@ -556,8 +626,13 @@ inline int select(int nfds, fd_set* readfds, fd_set* writefds,
return error_wrapper(::pselect(nfds, readfds,
writefds, exceptfds, timeout ? &ts : 0, 0), ec);
#else
return error_wrapper(::select(nfds, readfds,
int result = error_wrapper(::select(nfds, readfds,
writefds, exceptfds, timeout), ec);
# if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result >= 0)
clear_error(ec);
# endif
return result;
#endif
}
@ -568,7 +643,12 @@ inline int poll_read(socket_type s, asio::error_code& ec)
FD_ZERO(&fds);
FD_SET(s, &fds);
clear_error(ec);
return error_wrapper(::select(s, &fds, 0, 0, 0), ec);
int result = error_wrapper(::select(s, &fds, 0, 0, 0), ec);
# if defined(UNDER_CE)
if (result >= 0)
clear_error(ec);
# endif
return result;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
pollfd fds;
fds.fd = s;
@ -586,7 +666,12 @@ inline int poll_write(socket_type s, asio::error_code& ec)
FD_ZERO(&fds);
FD_SET(s, &fds);
clear_error(ec);
return error_wrapper(::select(s, 0, &fds, 0, 0), ec);
int result = error_wrapper(::select(s, 0, &fds, 0, 0), ec);
# if defined(UNDER_CE)
if (result >= 0)
clear_error(ec);
# endif
return result;
#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
pollfd fds;
fds.fd = s;
@ -743,7 +828,12 @@ inline int inet_pton(int af, const char* src, void* dest,
inline int gethostname(char* name, int namelen, asio::error_code& ec)
{
clear_error(ec);
return error_wrapper(::gethostname(name, namelen), ec);
int result = error_wrapper(::gethostname(name, namelen), ec);
#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
if (result == 0)
clear_error(ec);
#endif
return result;
}
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) \
@ -782,6 +872,9 @@ inline hostent* gethostbyaddr(const char* addr, int length, int af,
hostent* retval = error_wrapper(::gethostbyaddr(addr, length, af), ec);
if (!retval)
return 0;
# if defined(UNDER_CE)
clear_error(ec);
# endif
*result = *retval;
return retval;
#elif defined(__sun) || defined(__QNX__)
@ -830,6 +923,9 @@ inline hostent* gethostbyname(const char* name, int af, struct hostent* result,
hostent* retval = error_wrapper(::gethostbyname(name), ec);
if (!retval)
return 0;
# if defined(UNDER_CE)
clear_error(ec);
# endif
*result = *retval;
return result;
#elif defined(__sun) || defined(__QNX__)