* 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.
This commit is contained in:
@ -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,36 +252,88 @@ 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
|
||||
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)
|
||||
{
|
||||
sigframe thisframe (mainthread);
|
||||
int res = cygwin_recv (get_fd (), (char *) ptr, len, 0);
|
||||
#if 0
|
||||
if (res == SOCKET_ERROR)
|
||||
set_winsock_errno ();
|
||||
#endif
|
||||
return res;
|
||||
return recv (ptr, len, 0);
|
||||
}
|
||||
|
||||
extern "C" int cygwin_send (int, const void *, int, unsigned int);
|
||||
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)
|
||||
{
|
||||
sigframe thisframe (mainthread);
|
||||
int res = cygwin_send (get_fd (), (const char *) ptr, len, 0);
|
||||
#if 0
|
||||
if (res == SOCKET_ERROR)
|
||||
{
|
||||
set_winsock_errno ();
|
||||
if (get_errno () == ECONNABORTED || get_errno () == ECONNRESET)
|
||||
_raise (SIGPIPE);
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
return send (ptr, len, 0);
|
||||
}
|
||||
|
||||
/* Cygwin internal */
|
||||
|
Reference in New Issue
Block a user