aboutsummaryrefslogtreecommitdiff
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
parentd0672acc75f1101ed426b4a33426391a8073d9d1 (diff)
downloadnewlib-ff86860ba629f504f059a1ec8b2c9945accaffc6.zip
newlib-ff86860ba629f504f059a1ec8b2c9945accaffc6.tar.gz
newlib-ff86860ba629f504f059a1ec8b2c9945accaffc6.tar.bz2
* 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.
-rw-r--r--winsup/cygwin/ChangeLog16
-rw-r--r--winsup/cygwin/dtable.cc1
-rw-r--r--winsup/cygwin/fhandler.h12
-rw-r--r--winsup/cygwin/fhandler_socket.cc89
-rw-r--r--winsup/cygwin/net.cc91
-rw-r--r--winsup/cygwin/wsock_event.h32
6 files changed, 131 insertions, 110 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 4529c68..213a664 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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.
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index ab6f3c2..f09ddec 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -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;
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index f2b3f13..1b81427 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -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);
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index 33e9b39..c2af990 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 ()
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 9f24d71..fd0274f 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -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);
diff --git a/winsup/cygwin/wsock_event.h b/winsup/cygwin/wsock_event.h
new file mode 100644
index 0000000..3f86381
--- /dev/null
+++ b/winsup/cygwin/wsock_event.h
@@ -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__ */