Index: fhandler.h =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler.h,v retrieving revision 1.135 diff -u -p -r1.135 fhandler.h --- fhandler.h 19 Aug 2002 04:43:58 -0000 1.135 +++ fhandler.h 21 Aug 2002 19:13:51 -0000 @@ -398,11 +398,13 @@ class fhandler_socket: public fhandler_b int getpeername (struct sockaddr *name, int *namelen); int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3))); + int recv (void *ptr, size_t len, unsigned int flags); int recvfrom (void *ptr, size_t len, unsigned int flags, struct sockaddr *from, int *fromlen); int recvmsg (struct msghdr *msg, int flags); int write (const void *ptr, size_t len); + int send (const void *ptr, size_t len, unsigned int flags); 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); Index: fhandler_socket.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler_socket.cc,v retrieving revision 1.58 diff -u -p -r1.58 fhandler_socket.cc --- fhandler_socket.cc 12 Aug 2002 13:54:12 -0000 1.58 +++ fhandler_socket.cc 21 Aug 2002 19:13:51 -0000 @@ -671,7 +671,44 @@ fhandler_socket::getpeername (struct soc int __stdcall fhandler_socket::read (void *ptr, size_t len) { - return recvfrom (ptr, len, 0, NULL, NULL); + return recv (ptr, len, 0); +} + +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 @@ -759,7 +796,44 @@ fhandler_socket::recvmsg (struct msghdr int fhandler_socket::write (const void *ptr, size_t len) { - return sendto (ptr, len, 0, NULL, 0); + return send (ptr, len, 0); +} + + 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 Index: net.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/net.cc,v retrieving revision 1.121 diff -u -p -r1.121 net.cc --- net.cc 12 Aug 2002 13:54:12 -0000 1.121 +++ net.cc 21 Aug 2002 19:13:52 -0000 @@ -1148,14 +1148,36 @@ cygwin_getpeername (int fd, struct socka extern "C" int cygwin_recv (int fd, void *buf, int len, unsigned int flags) { - return cygwin_recvfrom (fd, buf, len, flags, NULL, NULL); + int res; + fhandler_socket *fh = get (fd); + + if ((len && __check_null_invalid_struct_errno (buf, (unsigned) len)) + || !fh) + res = -1; + else if ((res = len) != 0) + res = fh->recv (buf, len, flags); + + syscall_printf ("%d = recv (%d, %x, %x, %x)", res, fd, buf, len, flags); + + return res; } /* exported as send: standards? */ extern "C" int cygwin_send (int fd, const void *buf, int len, unsigned int flags) { - return cygwin_sendto (fd, buf, len, flags, NULL, 0); + int res; + fhandler_socket *fh = get (fd); + + if ((len && __check_invalid_read_ptr_errno (buf, (unsigned) len)) + || !fh) + res = -1; + else if ((res = len) != 0) + res = fh->send (buf, len, flags); + + syscall_printf ("%d = send (%d, %x, %x, %x)", res, fd, buf, len, flags); + + return res; } /* getdomainname: standards? */