From e120995086770858a600e650034cebb730f0c419 Mon Sep 17 00:00:00 2001 From: Conrad Scott Date: Mon, 12 Aug 2002 13:54:12 +0000 Subject: * fhandler.h (fhandler_socket::recv): Remove method. (fhandler_socket::send): Ditto. * fhandler_socket.cc (fhandler_socket::recv): Ditto. (fhandler_socket::send): Ditto. (fhandler_socket::read): Delegate to fhandler_socket::recvfrom. (fhandler_socket::write): Delegate to fhandler_socket::sendto. (fhandler_socket::sendto): Check for null `to' address. * net.cc (cygwin_sendto): Check for zero request length. (cygwin_recvfrom): Ditto. Fix signature, use void *buf. (cygwin_recv): Delegate to cygwin_recvfrom. (cygwin_send): Delegate to cygwin_sendto. --- winsup/cygwin/ChangeLog | 14 +++++++ winsup/cygwin/fhandler.h | 3 -- winsup/cygwin/fhandler_socket.cc | 87 ++++------------------------------------ winsup/cygwin/net.cc | 30 +++----------- 4 files changed, 28 insertions(+), 106 deletions(-) (limited to 'winsup') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 07d103758..473b5e3d7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2002-08-11 Conrad Scott + + * fhandler.h (fhandler_socket::recv): Remove method. + (fhandler_socket::send): Ditto. + * fhandler_socket.cc (fhandler_socket::recv): Ditto. + (fhandler_socket::send): Ditto. + (fhandler_socket::read): Delegate to fhandler_socket::recvfrom. + (fhandler_socket::write): Delegate to fhandler_socket::sendto. + (fhandler_socket::sendto): Check for null `to' address. + * net.cc (cygwin_sendto): Check for zero request length. + (cygwin_recvfrom): Ditto. Fix signature, use void *buf. + (cygwin_recv): Delegate to cygwin_recvfrom. + (cygwin_send): Delegate to cygwin_sendto. + 2002-08-11 Christopher Faylor * cygthread.cc (cygthread::cygthread): Close another race. diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index a338987d4..6237c6ca9 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -397,15 +397,12 @@ class fhandler_socket: public fhandler_base int getsockname (struct sockaddr *name, int *namelen); int getpeername (struct sockaddr *name, int *namelen); - int recv (void *ptr, size_t len, unsigned int flags); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); int recvfrom (void *ptr, size_t len, unsigned int flags, struct sockaddr *from, int *fromlen); int recvmsg (struct msghdr *msg, int flags); - int send (const void *ptr, size_t len, unsigned int flags); int write (const void *ptr, size_t len); - int sendto (const void *ptr, size_t len, unsigned int flags, const struct sockaddr *to, int tolen); int sendmsg (const struct msghdr *msg, int flags); diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 18ffac696..c93877318 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -668,47 +668,10 @@ fhandler_socket::getpeername (struct sockaddr *name, int *namelen) return res; } -int -fhandler_socket::recv (void *ptr, size_t len, unsigned int flags) -{ - int res = -1; - wsock_event wsock_evt; - LPWSAOVERLAPPED ovr; - - sigframe thisframe (mainthread); - - if (is_nonblocking () || !(ovr = wsock_evt.prepare ())) - { - debug_printf ("Fallback to winsock 1 recv call"); - if ((res = ::recv (get_socket (), (char *) ptr, len, flags)) - == SOCKET_ERROR) - { - set_winsock_errno (); - res = -1; - } - } - else - { - WSABUF wsabuf = { len, (char *) ptr }; - DWORD ret = 0; - if (WSARecv (get_socket (), &wsabuf, 1, &ret, (DWORD *)&flags, - ovr, NULL) != SOCKET_ERROR) - res = ret; - else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) - { - set_winsock_errno (); - res = -1; - } - else if ((res = wsock_evt.wait (get_socket (), (DWORD *)&flags)) == -1) - set_winsock_errno (); - } - return res; -} - int __stdcall fhandler_socket::read (void *ptr, size_t len) { - return recv (ptr, len, 0); + return recvfrom (ptr, len, 0, NULL, NULL); } int @@ -793,47 +756,10 @@ fhandler_socket::recvmsg (struct msghdr *msg, int flags) return res; } -int -fhandler_socket::send (const void *ptr, size_t len, unsigned int flags) -{ - int res = -1; - wsock_event wsock_evt; - LPWSAOVERLAPPED ovr; - - sigframe thisframe (mainthread); - - if (is_nonblocking () || !(ovr = wsock_evt.prepare ())) - { - debug_printf ("Fallback to winsock 1 send call"); - if ((res = ::send (get_socket (), (const char *) ptr, len, flags)) - == SOCKET_ERROR) - { - set_winsock_errno (); - res = -1; - } - } - else - { - WSABUF wsabuf = { len, (char *) ptr }; - DWORD ret = 0; - if (WSASend (get_socket (), &wsabuf, 1, &ret, (DWORD)flags, - ovr, NULL) != SOCKET_ERROR) - res = ret; - else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) - { - set_winsock_errno (); - res = -1; - } - else if ((res = wsock_evt.wait (get_socket (), (DWORD *)&flags)) == -1) - set_winsock_errno (); - } - return res; -} - int fhandler_socket::write (const void *ptr, size_t len) { - return send (ptr, len, 0); + return sendto (ptr, len, 0, NULL, 0); } int @@ -847,14 +773,15 @@ fhandler_socket::sendto (const void *ptr, size_t len, unsigned int flags, sigframe thisframe (mainthread); - if (!get_inet_addr (to, tolen, &sin, &tolen)) + if (to && !get_inet_addr (to, tolen, &sin, &tolen)) return -1; if (is_nonblocking () || !(ovr = wsock_evt.prepare ())) { debug_printf ("Fallback to winsock 1 sendto call"); if ((res = ::sendto (get_socket (), (const char *) ptr, len, flags, - (sockaddr *) &sin, tolen)) == SOCKET_ERROR) + (to ? (sockaddr *) &sin : NULL), + tolen)) == SOCKET_ERROR) { set_winsock_errno (); res = -1; @@ -865,7 +792,9 @@ fhandler_socket::sendto (const void *ptr, size_t len, unsigned int flags, WSABUF wsabuf = { len, (char *) ptr }; DWORD ret = 0; if (WSASendTo (get_socket (), &wsabuf, 1, &ret, (DWORD)flags, - (sockaddr *) &sin, tolen, ovr, NULL) != SOCKET_ERROR) + (to ? (sockaddr *) &sin : NULL), + tolen, + ovr, NULL) != SOCKET_ERROR) res = ret; else if ((res = WSAGetLastError ()) != WSA_IO_PENDING) { diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 56e7fc22b..00fea193c 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -574,7 +574,7 @@ cygwin_sendto (int fd, const void *buf, int len, unsigned int flags, || (to &&__check_invalid_read_ptr_errno (to, tolen)) || !fh) res = -1; - else + else if ((res = len) != 0) res = fh->sendto (buf, len, flags, to, tolen); syscall_printf ("%d = sendto (%d, %x, %x, %x)", res, fd, buf, len, flags); @@ -584,19 +584,19 @@ cygwin_sendto (int fd, const void *buf, int len, unsigned int flags, /* exported as recvfrom: standards? */ extern "C" int -cygwin_recvfrom (int fd, char *buf, int len, int flags, struct sockaddr *from, +cygwin_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from, int *fromlen) { int res; fhandler_socket *fh = get (fd); - if (__check_null_invalid_struct_errno (buf, (unsigned) len) + if ((len && __check_null_invalid_struct_errno (buf, (unsigned) len)) || (from && (check_null_invalid_struct_errno (fromlen) ||__check_null_invalid_struct_errno (from, (unsigned) *fromlen))) || !fh) res = -1; - else + else if ((res = len) != 0) res = fh->recvfrom (buf, len, flags, from, fromlen); syscall_printf ("%d = recvfrom (%d, %x, %x, %x)", res, fd, buf, len, flags); @@ -1148,32 +1148,14 @@ cygwin_getpeername (int fd, struct sockaddr *name, int *len) extern "C" int cygwin_recv (int fd, void *buf, int len, unsigned int flags) { - int res; - fhandler_socket *fh = get (fd); - - if (__check_null_invalid_struct_errno (buf, len) || !fh) - res = -1; - else - res = fh->recv (buf, len, flags); - - syscall_printf ("%d = recv (%d, %x, %x, %x)", res, fd, buf, len, flags); - return res; + return cygwin_recvfrom (fd, buf, len, flags, NULL, NULL); } /* exported as send: standards? */ extern "C" int cygwin_send (int fd, const void *buf, int len, unsigned int flags) { - int res; - fhandler_socket *fh = get (fd); - - if ((len &&__check_invalid_read_ptr_errno (buf, len)) || !fh) - res = -1; - else - res = fh->send (buf, len, flags); - - syscall_printf ("%d = send (%d, %x, %d, %x)", res, fd, buf, len, flags); - return res; + return cygwin_sendto (fd, buf, len, flags, NULL, 0); } /* getdomainname: standards? */ -- cgit v1.2.3