From 4450172a6c9a97bf9ec6ec1504f0297defe47cb4 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 31 Mar 2004 09:13:54 +0000 Subject: * fhandler_socket.cc (fhandler_socket::recvfrom): Initialize res to SOCKET_ERROR. Use SOCKET_ERROR instead of -1 throughout. (fhandler_socket::recvmsg): Ditto. (fhandler_socket::sendto): Ditto. (fhandler_socket::sendmsg): Ditto. * net.cc (wsock_event::prepare): Call WSASetLastError instead of SetLastError. (wsock_event::wait): Use SOCKET_ERROR instead of -1. --- winsup/cygwin/ChangeLog | 11 +++++++++++ winsup/cygwin/fhandler_socket.cc | 29 ++++++++++------------------- winsup/cygwin/net.cc | 4 ++-- 3 files changed, 23 insertions(+), 21 deletions(-) (limited to 'winsup/cygwin') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 9227f5c..0f75ddd 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2004-03-31 Corinna Vinschen + + * fhandler_socket.cc (fhandler_socket::recvfrom): Initialize res to + SOCKET_ERROR. Use SOCKET_ERROR instead of -1 throughout. + (fhandler_socket::recvmsg): Ditto. + (fhandler_socket::sendto): Ditto. + (fhandler_socket::sendmsg): Ditto. + * net.cc (wsock_event::prepare): Call WSASetLastError instead of + SetLastError. + (wsock_event::wait): Use SOCKET_ERROR instead of -1. + 2004-03-30 Thomas Pfaff * thread.h (pthread::init_mainthread): Add parameter forked. Set diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 0c30588..ccc1bef 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -714,7 +714,7 @@ int fhandler_socket::recvfrom (void *ptr, size_t len, int flags, struct sockaddr *from, int *fromlen) { - int res; + int res = SOCKET_ERROR; DWORD ret; flags &= MSG_WINMASK; @@ -728,8 +728,7 @@ fhandler_socket::recvfrom (void *ptr, size_t len, int flags, if (is_nonblocking () || has_been_closed) res = WSARecvFrom (get_socket (), &wsabuf, 1, &ret, (DWORD *) &flags, - from, fromlen, - NULL, NULL); + from, fromlen, NULL, NULL); else { wsock_event wsock_evt; @@ -758,7 +757,6 @@ fhandler_socket::recvfrom (void *ptr, size_t len, int flags, if (WSAGetLastError () == WSAEMSGSIZE) return len; - res = -1; set_winsock_errno (); } else @@ -786,7 +784,7 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags, ssize_t tot) struct sockaddr *from = (struct sockaddr *) msg->msg_name; int *fromlen = from ? &msg->msg_namelen : NULL; - int res; + int res = SOCKET_ERROR; if (!winsock2_active) { @@ -812,7 +810,7 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags, ssize_t tot) if (!buf) { set_errno (ENOMEM); - res = -1; + res = SOCKET_ERROR; } else { @@ -885,7 +883,6 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags, ssize_t tot) if (WSAGetLastError () == WSAEMSGSIZE) return len; - res = -1; set_winsock_errno (); } else @@ -921,7 +918,7 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags, if (to && !get_inet_addr (to, tolen, &sin, &tolen)) return -1; - int res; + int res = SOCKET_ERROR; DWORD ret; if (!winsock2_active) @@ -964,10 +961,7 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags, } if (res == SOCKET_ERROR) - { - res = -1; - set_winsock_errno (); - } + set_winsock_errno (); else res = ret; @@ -976,7 +970,7 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags, EPIPE is generated if the local end has been shut down on a connection oriented socket. In this case the process will also receive a SIGPIPE unless MSG_NOSIGNAL is set. */ - if (res == -1 && get_errno () == ESHUTDOWN + if (res == SOCKET_ERROR && get_errno () == ESHUTDOWN && get_socket_type () == SOCK_STREAM) { set_errno (EPIPE); @@ -1002,7 +996,7 @@ fhandler_socket::sendmsg (const struct msghdr *msg, int flags, ssize_t tot) struct iovec *const iov = msg->msg_iov; const int iovcnt = msg->msg_iovlen; - int res; + int res = SOCKET_ERROR; if (!winsock2_active) { @@ -1029,7 +1023,7 @@ fhandler_socket::sendmsg (const struct msghdr *msg, int flags, ssize_t tot) if (!buf) { set_errno (ENOMEM); - res = -1; + res = SOCKET_ERROR; } else { @@ -1101,10 +1095,7 @@ fhandler_socket::sendmsg (const struct msghdr *msg, int flags, ssize_t tot) } if (res == SOCKET_ERROR) - { - res = -1; - set_winsock_errno (); - } + set_winsock_errno (); else res = ret; } diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 3d76a43..b53dacd 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -53,7 +53,7 @@ extern "C" bool wsock_event::prepare (int sock, long event_mask) { - SetLastError (0); + WSASetLastError (0); if ((event = WSACreateEvent ()) != WSA_INVALID_EVENT && WSAEventSelect (sock, event, event_mask) == SOCKET_ERROR) { @@ -67,7 +67,7 @@ wsock_event::prepare (int sock, long event_mask) int wsock_event::wait (int sock, int &closed) { - int ret = -1; + int ret = SOCKET_ERROR; DWORD wsa_err = 0; WSAEVENT ev[2] = { event, signal_arrived }; switch (WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE, FALSE)) -- cgit v1.1