summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler_socket.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2002-02-09 10:40:48 +0000
committerCorinna Vinschen <corinna@vinschen.de>2002-02-09 10:40:48 +0000
commitff86860ba629f504f059a1ec8b2c9945accaffc6 (patch)
tree97b365760405c2d544f72b0373badca0d6b53634 /winsup/cygwin/fhandler_socket.cc
parentd0672acc75f1101ed426b4a33426391a8073d9d1 (diff)
downloadcygnal-ff86860ba629f504f059a1ec8b2c9945accaffc6.tar.gz
cygnal-ff86860ba629f504f059a1ec8b2c9945accaffc6.tar.bz2
cygnal-ff86860ba629f504f059a1ec8b2c9945accaffc6.zip
* dtable.cc (dtable::dup2): Revert previous patch.
* fhandler.h: Ditto. (fhandler_socket::recv): Define new method. (fhandler_socket::send): Ditto. * fhandler_socket.cc (fhandler_socket::recv): New method. (fhandler_socket::send): Ditto. (fhandler_socket::read): Call fhandler_socket::recv() now. (fhandler_socket::write): Call fhandler_socket::send() now. * net.cc (class wsock_event): Move definition to wsock_event.h. (fdsock): Revert previous patch. (cygwin_recv): Move implementation to fhandler_socket::recv(). (cygwin_send): Move implementation to fhandler_socket::send(). * wsock_event.h: New file.
Diffstat (limited to 'winsup/cygwin/fhandler_socket.cc')
-rw-r--r--winsup/cygwin/fhandler_socket.cc89
1 files changed, 71 insertions, 18 deletions
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index 33e9b39f3..c2af990df 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -31,6 +31,7 @@
#include "dtable.h"
#include "cygheap.h"
#include "sigproc.h"
+#include "wsock_event.h"
#define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x"
#define ENTROPY_SOURCE_NAME "/dev/urandom"
@@ -251,38 +252,90 @@ fhandler_socket::fstat (struct stat *buf, path_conv *pc)
return fh.fstat (buf, pc);
}
-extern "C" int cygwin_recv (int, void *, int, unsigned int);
-
-int __stdcall
-fhandler_socket::read (void *ptr, size_t len)
+int
+fhandler_socket::recv (void *ptr, size_t len, unsigned int flags)
{
+ int res = -1;
+ wsock_event wsock_evt;
+ LPWSAOVERLAPPED ovr;
+
sigframe thisframe (mainthread);
- int res = cygwin_recv (get_fd (), (char *) ptr, len, 0);
-#if 0
- if (res == SOCKET_ERROR)
- set_winsock_errno ();
-#endif
+ 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;
}
-extern "C" int cygwin_send (int, const void *, int, unsigned int);
+int __stdcall
+fhandler_socket::read (void *ptr, size_t len)
+{
+ return recv (ptr, len, 0);
+}
int
-fhandler_socket::write (const void *ptr, size_t len)
+fhandler_socket::send (const void *ptr, size_t len, unsigned int flags)
{
+ int res = -1;
+ wsock_event wsock_evt;
+ LPWSAOVERLAPPED ovr;
+
sigframe thisframe (mainthread);
- int res = cygwin_send (get_fd (), (const char *) ptr, len, 0);
-#if 0
- if (res == SOCKET_ERROR)
+ if (is_nonblocking () || !(ovr = wsock_evt.prepare ()))
{
- set_winsock_errno ();
- if (get_errno () == ECONNABORTED || get_errno () == ECONNRESET)
- _raise (SIGPIPE);
+ 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 ();
}
-#endif
return res;
}
+int
+fhandler_socket::write (const void *ptr, size_t len)
+{
+ return send (ptr, len, 0);
+}
+
/* Cygwin internal */
int
fhandler_socket::close ()