Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2001-10-13 21:23:35 +0400
committerChristopher Faylor <me@cgf.cx>2001-10-13 21:23:35 +0400
commit0476bae576d4a21ed57cc55074509c07138d1fba (patch)
treedc30019ce3ba2d8eb84d34f3b650827bbf4fc999 /winsup/cygwin/fhandler_socket.cc
parent5dec13e1793901735554fd4dd60cad64c9394bb5 (diff)
* fhandler_dsp.cc (fhandler_dsp::ioctl): Return 0 for successful
SNDCTL_DSP_GETBLKSIZE operation. Remove obsolete 'name' arg from fhandler_* constructors throughout. * winsup.h (winsock_active): New macro. (winsock2_active): Ditto. * autoload.cc (wsock_init): Use new macros to decide if winsock or winsock2 is loaded. (nonexist_wsock32): Dummy function to force winsock load. (nonexist_ws2_32): Dummy function to force winsock2 load. * fhandler.h (fhandler_socket::fstat): Declare new method. Currently unused. * fhandler_socket.cc (fhandler_socket::fixup_before_fork_exec): Check that winsock2 is active before trying WSADuplicateSocketA. (fhandler_socket::fixup_after_fork): Add extra check for winsock2_active. Otherwise use iffy procedures for Windows 95. (fhandler_socket::fixup_after_exec): Add debugging. (fhandler_socket::dup): Add debugging. (fhandler_socket::fstat): New method. (fhandler_socket::set_close_on_exec): Attempt to perform iffy stuff on Windows 95. * errno.cc (_sys_nerr): Work around compiler strangeness. * pinfo.cc (winpids::add): Add extra element at end of allocated array for setting to NULL. (winpids::enumNT): Ditto. (winpids::init): Don't modify pidlist if it hasn't been allocated (possibly due to malloc problem).
Diffstat (limited to 'winsup/cygwin/fhandler_socket.cc')
-rw-r--r--winsup/cygwin/fhandler_socket.cc90
1 files changed, 47 insertions, 43 deletions
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index 4711189c0..6c92d1e02 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -41,8 +41,8 @@ fhandler_dev_random* entropy_source;
/**********************************************************************/
/* fhandler_socket */
-fhandler_socket::fhandler_socket (const char *name) :
- fhandler_base (FH_SOCKET, name)
+fhandler_socket::fhandler_socket () :
+ fhandler_base (FH_SOCKET)
{
set_cb (sizeof *this);
set_need_fork_fixup ();
@@ -62,8 +62,7 @@ fhandler_socket::set_connect_secret ()
if (!entropy_source)
{
void *buf = malloc (sizeof (fhandler_dev_random));
- entropy_source = new (buf) fhandler_dev_random (ENTROPY_SOURCE_NAME,
- ENTROPY_SOURCE_DEV_UNIT);
+ entropy_source = new (buf) fhandler_dev_random (ENTROPY_SOURCE_DEV_UNIT);
}
if (entropy_source &&
!entropy_source->open (NULL, O_RDONLY))
@@ -115,8 +114,13 @@ fhandler_socket::create_secret_event (int* secret)
void
fhandler_socket::signal_secret_event ()
{
- if (secret_event)
- SetEvent (secret_event);
+ if (!secret_event)
+ debug_printf ("no secret event?");
+ else
+ {
+ SetEvent (secret_event);
+ debug_printf ("signaled secret_event");
+ }
}
void
@@ -160,54 +164,48 @@ fhandler_socket::check_peer_secret_event (struct sockaddr_in* peer, int* secret)
void
fhandler_socket::fixup_before_fork_exec (DWORD win_proc_id)
{
- int ret = 1;
-
- if (prot_info_ptr &&
- (ret = WSADuplicateSocketA (get_socket (), win_proc_id, prot_info_ptr)))
+ if (!winsock2_active)
{
- debug_printf ("WSADuplicateSocket error");
- set_winsock_errno ();
- }
- if (!ret && ws2_32_handle)
- {
- debug_printf ("WSADuplicateSocket went fine, dwServiceFlags1=%d",
- prot_info_ptr->dwServiceFlags1);
+ fhandler_base::fixup_before_fork_exec (win_proc_id);
+ debug_printf ("Without Winsock 2.0");
}
+ else if (!WSADuplicateSocketA (get_socket (), win_proc_id, prot_info_ptr))
+ debug_printf ("WSADuplicateSocket went fine, dwServiceFlags1=%d",
+ prot_info_ptr->dwServiceFlags1);
else
{
- fhandler_base::fixup_before_fork_exec (win_proc_id);
- debug_printf ("Without Winsock 2.0");
+ debug_printf ("WSADuplicateSocket error");
+ set_winsock_errno ();
}
}
void
fhandler_socket::fixup_after_fork (HANDLE parent)
{
- SOCKET new_sock = INVALID_SOCKET;
+ SOCKET new_sock;
debug_printf ("WSASocket begin, dwServiceFlags1=%d",
prot_info_ptr->dwServiceFlags1);
- if (prot_info_ptr &&
- (new_sock = WSASocketA (FROM_PROTOCOL_INFO,
- FROM_PROTOCOL_INFO,
- FROM_PROTOCOL_INFO,
- prot_info_ptr, 0, 0)) == INVALID_SOCKET)
+
+ if ((new_sock = WSASocketA (FROM_PROTOCOL_INFO,
+ FROM_PROTOCOL_INFO,
+ FROM_PROTOCOL_INFO,
+ prot_info_ptr, 0, 0)) == INVALID_SOCKET)
{
debug_printf ("WSASocket error");
set_winsock_errno ();
}
- if (new_sock != INVALID_SOCKET && ws2_32_handle)
+ else if (!new_sock && !winsock2_active)
{
- debug_printf ("WSASocket went fine %p", new_sock);
- set_io_handle ((HANDLE) new_sock);
+ fhandler_base::fixup_after_fork (parent);
+ debug_printf ("Without Winsock 2.0");
}
else
{
-#if 0
- fhandler_base::fixup_after_fork (parent);
-#endif
- debug_printf ("Without Winsock 2.0");
+ debug_printf ("WSASocket went fine %p", new_sock);
+ set_io_handle ((HANDLE) new_sock);
}
+
if (secret_event)
fork_fixup (parent, secret_event, "secret_event");
}
@@ -215,21 +213,24 @@ fhandler_socket::fixup_after_fork (HANDLE parent)
void
fhandler_socket::fixup_after_exec (HANDLE parent)
{
- extern WSADATA wsadata;
+ debug_printf ("here");
if (!get_close_on_exec ())
fixup_after_fork (parent);
- else if (wsadata.wVersion < 512) /* < Winsock 2.0 */
+#if 0
+ else if (!winsock2_active)
closesocket (get_socket ());
+#endif
}
int
fhandler_socket::dup (fhandler_base *child)
{
+ debug_printf ("here");
fhandler_socket *fhs = (fhandler_socket *) child;
fhs->addr_family = addr_family;
fhs->set_io_handle (get_io_handle ());
fhs->fixup_before_fork_exec (GetCurrentProcessId ());
- if (ws2_32_handle)
+ if (winsock2_active)
{
fhs->fixup_after_fork (hMainProc);
return 0;
@@ -237,15 +238,21 @@ fhandler_socket::dup (fhandler_base *child)
return fhandler_base::dup (child);
}
+int __stdcall
+fhandler_socket::fstat (struct stat *buf, path_conv *pc)
+{
+ fhandler_disk_file fh;
+ fh.set_name (get_name (), get_win32_name ());
+ return fh.fstat (buf, pc);
+}
+
int
fhandler_socket::read (void *ptr, size_t len)
{
sigframe thisframe (mainthread);
int res = recv (get_socket (), (char *) ptr, len, 0);
if (res == SOCKET_ERROR)
- {
- set_winsock_errno ();
- }
+ set_winsock_errno ();
return res;
}
@@ -414,7 +421,7 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
if (cmd == FIONBIO)
{
syscall_printf ("socket is now %sblocking",
- *(int *) p ? "un" : "");
+ *(int *) p ? "non" : "");
/* Start AsyncSelect if async socket unblocked */
if (*(int *) p && get_async ())
WSAAsyncSelect (get_socket (), gethwnd (), WM_ASYNCIO, ASYNC_MASK);
@@ -460,11 +467,8 @@ fhandler_socket::fcntl (int cmd, void *arg)
void
fhandler_socket::set_close_on_exec (int val)
{
-#if 0
- extern WSADATA wsadata;
- if (wsadata.wVersion < 512) /* < Winsock 2.0 */
+ if (!winsock2_active) /* < Winsock 2.0 */
set_inheritance (get_handle (), val);
-#endif
set_close_on_exec_flag (val);
debug_printf ("set close_on_exec for %s to %d", get_name (), val);
}