* 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.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user