* 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:
Corinna Vinschen 2002-02-09 10:40:48 +00:00
parent d0672acc75
commit ff86860ba6
6 changed files with 133 additions and 112 deletions

View File

@ -1,3 +1,19 @@
2002-02-09 Corinna Vinschen <corinna@vinschen.de>
* 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.
2002-02-06 Alexander Gottwald <Alexander.Gottwald@s1999.tuchemnitz.de>
* net.cc (get_2k_ifconf): Create interface entries for tokenring cards.

View File

@ -411,7 +411,6 @@ dtable::dup2 (int oldfd, int newfd)
if (!not_open (newfd))
_close (newfd);
fds[newfd] = newfh;
newfh->set_fd (newfd);
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
MALLOC_CHECK;

View File

@ -351,9 +351,6 @@ class fhandler_base
virtual void seekdir (DIR *, off_t);
virtual void rewinddir (DIR *);
virtual int closedir (DIR *);
virtual void set_fd (int nfd) {}
virtual int get_fd () { return -1; }
};
class fhandler_socket: public fhandler_base
@ -364,7 +361,6 @@ class fhandler_socket: public fhandler_base
HANDLE secret_event;
struct _WSAPROTOCOL_INFOA *prot_info_ptr;
char *sun_path;
int fd;
public:
fhandler_socket ();
@ -378,8 +374,12 @@ class fhandler_socket: public fhandler_base
void set_shutdown_read () {FHSETF (SHUTRD);}
void set_shutdown_write () {FHSETF (SHUTWR);}
int write (const void *ptr, size_t len);
int recv (void *ptr, size_t len, unsigned int flags);
int __stdcall read (void *ptr, size_t len) __attribute__ ((regparm (3)));
int send (const void *ptr, size_t len, unsigned int flags);
int write (const void *ptr, size_t len);
int ioctl (unsigned int cmd, void *);
int fcntl (int cmd, void *);
off_t lseek (off_t, int) { return 0; }
@ -395,8 +395,6 @@ class fhandler_socket: public fhandler_base
select_record *select_read (select_record *s);
select_record *select_write (select_record *s);
select_record *select_except (select_record *s);
void set_fd (int nfd) { fd = nfd; }
int get_fd () { return fd; }
void set_addr_family (int af) {addr_family = af;}
int get_addr_family () {return addr_family;}
void set_sun_path (const char *path);

View File

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

View File

@ -34,6 +34,7 @@ details. */
#include "sigproc.h"
#include "pinfo.h"
#include "registry.h"
#include "wsock_event.h"
#include <sys/uio.h>
extern "C" {
@ -47,23 +48,6 @@ int __stdcall rresvport (int *);
int sscanf (const char *, const char *, ...);
} /* End of "C" section */
class wsock_event
{
WSAEVENT event;
WSAOVERLAPPED ovr;
public:
wsock_event () : event (NULL) {};
~wsock_event ()
{
if (event)
WSACloseEvent (event);
event = NULL;
};
LPWSAOVERLAPPED prepare ();
int wait (int socket, LPDWORD flags);
};
LPWSAOVERLAPPED
wsock_event::prepare ()
{
@ -522,7 +506,6 @@ fdsock (int& fd, const char *name, SOCKET soc)
else
debug_printf ("not setting socket inheritance since winsock2_active %d", winsock2_active);
fhandler_socket *fh = (fhandler_socket *) cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name);
fh->set_fd (fd);
fh->set_io_handle ((HANDLE) soc);
fh->set_flags (O_RDWR);
fh->set_name (name, name);
@ -1528,42 +1511,12 @@ extern "C" int
cygwin_recv (int fd, void *buf, int len, unsigned int flags)
{
int res;
wsock_event wsock_evt;
LPWSAOVERLAPPED ovr;
fhandler_socket *h = get (fd);
fhandler_socket *fh = get (fd);
if (__check_null_invalid_struct_errno (buf, len) || !h)
if (__check_null_invalid_struct_errno (buf, len) || !fh)
res = -1;
else
{
sigframe thisframe (mainthread);
if (h->is_nonblocking () || !(ovr = wsock_evt.prepare ()))
{
debug_printf ("Fallback to winsock 1 recv call");
if ((res = recv (h->get_socket (), (char *) buf, len, flags))
== SOCKET_ERROR)
{
set_winsock_errno ();
res = -1;
}
}
else
{
WSABUF wsabuf = { len, (char *) buf };
DWORD ret = 0;
if (WSARecv (h->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 (h->get_socket (), (DWORD *)&flags)) == -1)
set_winsock_errno ();
}
}
res = fh->recv (buf, len, flags);
syscall_printf ("%d = recv (%d, %x, %x, %x)", res, fd, buf, len, flags);
@ -1575,42 +1528,12 @@ extern "C" int
cygwin_send (int fd, const void *buf, int len, unsigned int flags)
{
int res;
wsock_event wsock_evt;
LPWSAOVERLAPPED ovr;
fhandler_socket *h = get (fd);
fhandler_socket *fh = get (fd);
if (__check_invalid_read_ptr_errno (buf, len) || !h)
if (__check_invalid_read_ptr_errno (buf, len) || !fh)
res = -1;
else
{
sigframe thisframe (mainthread);
if (h->is_nonblocking () || !(ovr = wsock_evt.prepare ()))
{
debug_printf ("Fallback to winsock 1 send call");
if ((res = send (h->get_socket (), (const char *) buf, len, flags))
== SOCKET_ERROR)
{
set_winsock_errno ();
res = -1;
}
}
else
{
WSABUF wsabuf = { len, (char *) buf };
DWORD ret = 0;
if (WSASend (h->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 (h->get_socket (), (DWORD *)&flags)) == -1)
set_winsock_errno ();
}
}
res = fh->send (buf, len, flags);
syscall_printf ("%d = send (%d, %x, %d, %x)", res, fd, buf, len, flags);

View File

@ -0,0 +1,32 @@
/* wsock_event.h: Defining the wsock_event class
Copyright 2002 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef __WSOCK_EVENT_H__
#define __WSOCK_EVENT_H__
class wsock_event
{
WSAEVENT event;
WSAOVERLAPPED ovr;
public:
wsock_event () : event (NULL) {};
~wsock_event ()
{
if (event)
WSACloseEvent (event);
event = NULL;
};
/* The methods are implemented in net.cc */
LPWSAOVERLAPPED prepare ();
int wait (int socket, LPDWORD flags);
};
#endif /* __WSOCK_EVENT_H__ */