* 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-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.
if (!not_open (newfd))
_close (newfd);
fds[newfd] = newfh;
- newfh->set_fd (newfd);
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
MALLOC_CHECK;
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
HANDLE secret_event;
struct _WSAPROTOCOL_INFOA *prot_info_ptr;
char *sun_path;
- int fd;
public:
fhandler_socket ();
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; }
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);
#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"
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 ()
#include "sigproc.h"
#include "pinfo.h"
#include "registry.h"
+#include "wsock_event.h"
#include <sys/uio.h>
extern "C" {
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 ()
{
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);
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);
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);
--- /dev/null
+/* 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__ */