4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 12:29:32 +08:00

* 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.
This commit is contained in:
Corinna Vinschen 2004-03-31 09:13:54 +00:00
parent ed4c5eceb0
commit 4450172a6c
3 changed files with 23 additions and 21 deletions

View File

@ -1,3 +1,14 @@
2004-03-31 Corinna Vinschen <corinna@vinschen.de>
* 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 <tpfaff@gmx.net> 2004-03-30 Thomas Pfaff <tpfaff@gmx.net>
* thread.h (pthread::init_mainthread): Add parameter forked. Set * thread.h (pthread::init_mainthread): Add parameter forked. Set

View File

@ -714,7 +714,7 @@ int
fhandler_socket::recvfrom (void *ptr, size_t len, int flags, fhandler_socket::recvfrom (void *ptr, size_t len, int flags,
struct sockaddr *from, int *fromlen) struct sockaddr *from, int *fromlen)
{ {
int res; int res = SOCKET_ERROR;
DWORD ret; DWORD ret;
flags &= MSG_WINMASK; flags &= MSG_WINMASK;
@ -728,8 +728,7 @@ fhandler_socket::recvfrom (void *ptr, size_t len, int flags,
if (is_nonblocking () || has_been_closed) if (is_nonblocking () || has_been_closed)
res = WSARecvFrom (get_socket (), &wsabuf, 1, &ret, (DWORD *) &flags, res = WSARecvFrom (get_socket (), &wsabuf, 1, &ret, (DWORD *) &flags,
from, fromlen, from, fromlen, NULL, NULL);
NULL, NULL);
else else
{ {
wsock_event wsock_evt; wsock_event wsock_evt;
@ -758,7 +757,6 @@ fhandler_socket::recvfrom (void *ptr, size_t len, int flags,
if (WSAGetLastError () == WSAEMSGSIZE) if (WSAGetLastError () == WSAEMSGSIZE)
return len; return len;
res = -1;
set_winsock_errno (); set_winsock_errno ();
} }
else else
@ -786,7 +784,7 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags, ssize_t tot)
struct sockaddr *from = (struct sockaddr *) msg->msg_name; struct sockaddr *from = (struct sockaddr *) msg->msg_name;
int *fromlen = from ? &msg->msg_namelen : NULL; int *fromlen = from ? &msg->msg_namelen : NULL;
int res; int res = SOCKET_ERROR;
if (!winsock2_active) if (!winsock2_active)
{ {
@ -812,7 +810,7 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags, ssize_t tot)
if (!buf) if (!buf)
{ {
set_errno (ENOMEM); set_errno (ENOMEM);
res = -1; res = SOCKET_ERROR;
} }
else else
{ {
@ -885,7 +883,6 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags, ssize_t tot)
if (WSAGetLastError () == WSAEMSGSIZE) if (WSAGetLastError () == WSAEMSGSIZE)
return len; return len;
res = -1;
set_winsock_errno (); set_winsock_errno ();
} }
else 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)) if (to && !get_inet_addr (to, tolen, &sin, &tolen))
return -1; return -1;
int res; int res = SOCKET_ERROR;
DWORD ret; DWORD ret;
if (!winsock2_active) if (!winsock2_active)
@ -964,10 +961,7 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags,
} }
if (res == SOCKET_ERROR) if (res == SOCKET_ERROR)
{ set_winsock_errno ();
res = -1;
set_winsock_errno ();
}
else else
res = ret; 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 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 oriented socket. In this case the process will also receive a SIGPIPE
unless MSG_NOSIGNAL is set. */ unless MSG_NOSIGNAL is set. */
if (res == -1 && get_errno () == ESHUTDOWN if (res == SOCKET_ERROR && get_errno () == ESHUTDOWN
&& get_socket_type () == SOCK_STREAM) && get_socket_type () == SOCK_STREAM)
{ {
set_errno (EPIPE); 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; struct iovec *const iov = msg->msg_iov;
const int iovcnt = msg->msg_iovlen; const int iovcnt = msg->msg_iovlen;
int res; int res = SOCKET_ERROR;
if (!winsock2_active) if (!winsock2_active)
{ {
@ -1029,7 +1023,7 @@ fhandler_socket::sendmsg (const struct msghdr *msg, int flags, ssize_t tot)
if (!buf) if (!buf)
{ {
set_errno (ENOMEM); set_errno (ENOMEM);
res = -1; res = SOCKET_ERROR;
} }
else else
{ {
@ -1101,10 +1095,7 @@ fhandler_socket::sendmsg (const struct msghdr *msg, int flags, ssize_t tot)
} }
if (res == SOCKET_ERROR) if (res == SOCKET_ERROR)
{ set_winsock_errno ();
res = -1;
set_winsock_errno ();
}
else else
res = ret; res = ret;
} }

View File

@ -53,7 +53,7 @@ extern "C"
bool bool
wsock_event::prepare (int sock, long event_mask) wsock_event::prepare (int sock, long event_mask)
{ {
SetLastError (0); WSASetLastError (0);
if ((event = WSACreateEvent ()) != WSA_INVALID_EVENT if ((event = WSACreateEvent ()) != WSA_INVALID_EVENT
&& WSAEventSelect (sock, event, event_mask) == SOCKET_ERROR) && WSAEventSelect (sock, event, event_mask) == SOCKET_ERROR)
{ {
@ -67,7 +67,7 @@ wsock_event::prepare (int sock, long event_mask)
int int
wsock_event::wait (int sock, int &closed) wsock_event::wait (int sock, int &closed)
{ {
int ret = -1; int ret = SOCKET_ERROR;
DWORD wsa_err = 0; DWORD wsa_err = 0;
WSAEVENT ev[2] = { event, signal_arrived }; WSAEVENT ev[2] = { event, signal_arrived };
switch (WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE, FALSE)) switch (WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE, FALSE))