* 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:
Conrad Scott 2002-08-12 13:54:12 +00:00
parent a814828d06
commit e120995086
4 changed files with 28 additions and 106 deletions

View File

@ -1,3 +1,17 @@
2002-08-11 Conrad Scott <conrad.scott@dsl.pipex.com>
* 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 <cgf@redhat.com>
* cygthread.cc (cygthread::cygthread): Close another race.

View File

@ -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);

View File

@ -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)
{

View File

@ -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? */