diff options
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/ChangeLog | 46 | ||||
-rw-r--r-- | winsup/cygwin/cygtls.cc | 5 | ||||
-rw-r--r-- | winsup/cygwin/cygtls.h | 6 | ||||
-rw-r--r-- | winsup/cygwin/select.cc | 97 | ||||
-rw-r--r-- | winsup/cygwin/tlsoffsets.h | 110 |
5 files changed, 137 insertions, 127 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0533bf774..f468bff95 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,9 +1,23 @@ +2004-10-10 Christopher Faylor <cgf@timesys.com> + + * cygtls.h (exitsock): New element. + (exitsock_sin): Ditto. + * cygtls.cc (_cygtls::init_thread): Initialize exitsock to invalid handle. + (_cygtls::call2): Close exitsock if it is valid. + * select.cc (struct socketinf): Remove sin element. + (start_thread_socket): Initialize one SOCK_DGRAM socket per thread + instead of (apparently) expensive opening and closing of socket with + each select call. + (socket_cleanup): Send a byte to the exitsock socket as a way to + potentially signal a waiting-for-socket thread to exit. + * tlsoffsets.h: Regenerate. + 2004-10-07 Corinna Vinschen <corinna@vinschen.de> * cygheap.h (class cygheap_user): Add psystemroot member and env_systemroot method. * environ.cc (struct spenv): Add add_always member. - (spenvs): Accomodate new add_always member. Add + (spenvs): Accommodate new add_always member. Add cygheap_user::env_systemroot method to SYSTEMROOT entry. (build_env): Check add_always member when adding missing environment variables from spenvs. @@ -46,7 +60,7 @@ (path_conv::isdisk): Delete method. (path_conv::set_isdisk): Ditto. * path.cc (path_conv::check): Do not call set_isdisk. - * uinfo.cc(pwdgrp::load): Do not call pc.isdisk. + * uinfo.cc(pwdgrp::load): Do not call pc.isdisk. 2004-09-28 Christopher Faylor <cgf@timesys.com> @@ -1029,7 +1043,7 @@ * fhandler_tape.cc (mtinfo_drive::_set_pos): Take additional dont_wait parameter. Use in call to SetTapePosition. - (mtinfo_drive::set_pos): Accomodate _set_pos calls to above change. + (mtinfo_drive::set_pos): Accommodate _set_pos calls to above change. (mtinfo_drive::set_partition): Ditto. * mtinfo.h (mtinfo_drive::_set_pos): Change declaration accordingly. @@ -1119,7 +1133,7 @@ 2004-04-14 Corinna Vinschen <corinna@vinschen.de> - * fhandler.cc (fhandler_base::open): Accomodate query_write_control + * fhandler.cc (fhandler_base::open): Accommodate query_write_control query_state. (fhandler_base::fchown): New method. * fhandler.h: Declare fchown method in fhandler_base, @@ -1305,7 +1319,7 @@ (fhandler_disk_file::readdir): Use pc.isencoded() directly. * mtinfo.h (class mtinfo_drive): Const'ify all read accessor methods. * path.cc (fsinfo_cnt): Add. - (fs_info::update): Accomodate class changes. Evaluate file system + (fs_info::update): Accommodate class changes. Evaluate file system name specific flags right here. Add thread safety for reading and writing global fsinfo array. * path.h (enum path_types): Drop values for flags kept in fs already. @@ -1394,7 +1408,7 @@ (fhandler_base::open_status): Ditto. (class fhandler_socket): Move status bits into private bitfield struct type status_flags. Change accessor methods appropriately. - * fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate + * fhandler_socket.cc (fhandler_socket::fhandler_socket): Accommodate above status bit changes. * tty.h: Remove status bit enumerator. (TTYISSETF): Remove. @@ -1414,7 +1428,7 @@ * fhandler.cc (fhandler_base::write): Use bool parameter in calls to set_did_lseek. - (fhandler_base::fhandler_base): Accomodate new status and open_status + (fhandler_base::fhandler_base): Accommodate new status and open_status constructor. * fhandler.h: Remove status bit enumerator. (FHDEVN): Remove. @@ -1426,10 +1440,10 @@ (UNCONNECTED, CONNECT_PENDING, CONNECTED): Substitute by enum connect_state. (fhandler_base::status): Define as bitfield struct type status_flags. - Remove unused flags entirely. Accomodate all status access methods. + Remove unused flags entirely. Accommodate all status access methods. (open_status): Define as bitfield struct type status_flags. (fhandler_socket): Move socket related status bits to here. Redefine - had_connect_or_listen to be part of these status bits. Accomodate + had_connect_or_listen to be part of these status bits. Accommodate related access methods. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Use pc.issymlink instead of dropped method get_symlink_p. @@ -1476,7 +1490,7 @@ to allow calling get_nt_object_attribute in case a non-NULL handle is given. * security.h (get_file_attribute): Add handle to argument list. - * syscalls.cc (chown_worker): Accomodate new definition of + * syscalls.cc (chown_worker): Accommodate new definition of get_file_attribute. 2004-04-07 Pierre Humblet <pierre.humblet@ieee.org> @@ -1624,7 +1638,7 @@ * net.cc (wsock_event::prepare): Reimplement using asynchronous I/O. (wsock_event::wait): Ditto. (wsock_event::release): New method. - * wsock_event.h (class wsock_event): Remove ovr member. Accomodate + * wsock_event.h (class wsock_event): Remove ovr member. Accommodate new implementation of prepare and wait methods. Add release method. 2004-03-29 Thomas Pfaff <tpfaff@gmx.net> @@ -1926,7 +1940,7 @@ Handle ERROR_FILEMARK_DETECTED. * fhandler_tape.cc (TAPE_FUNC): Add comment that ERROR_BUS_RESET has still to be handled correctly. - (fhandler_dev_tape::open): Accomodate fact that get.mt_dsreg + (fhandler_dev_tape::open): Accommodate fact that get.mt_dsreg also contains density code. (fhandler_dev_tape::ioctl): Rearrange slightly. Reset devbuf also on MTNOP, MTWSM, MTSETBLK, MTSETDRVBUFFER, MTSETPART and MTMKPART. @@ -1975,12 +1989,12 @@ * fhandler_raw.cc (fhandler_dev_raw::write_file): New method, created from former static function. (fhandler_dev_raw::read_file): Ditto. - (fhandler_dev_raw::writebuf): Accomodate the fact that no devbuf + (fhandler_dev_raw::writebuf): Accommodate the fact that no devbuf exists under variable block size condition. (fhandler_dev_raw::raw_read): Ditto. Add local p pointer to simplify pointer arithmetic. (fhandler_dev_raw::raw_write): Always set devbufend to 0 when starting - with writing. Accomodate the fact that no devbuf exists under + with writing. Accommodate the fact that no devbuf exists under variable block size condition. * fhandler_tape.cc: Various formatting changes. (TAPE_FUNC): New macro. Use throughout as tape function loop. @@ -2014,7 +2028,7 @@ (fhandler_dev_tape::tape_set_blocksize): Don't call tape_get_blocksize. Error handling already done in fhandler_dev_tape::ioctl. (fhandler_dev_tape::tape_status): Remove local `dp' variable. - Accomodate logical tape reporting. Call tape_get_feature instead + Accommodate logical tape reporting. Call tape_get_feature instead of accessing feature words directly. (fhandler_dev_tape::tape_compression): Use dp instead of calling GetTapeParameters. Fix resetting datcompression. @@ -2244,7 +2258,7 @@ * thread.cc (pthread::cancelable_wait): Rearrange slightly. Add do_sig_wait parameter. Wait for signal_arrived if set to true. Return WAIT_SIGNALED if signal arrived. - (pthread_cond::wait): Accomodate change to pthread::cancelable_wait. + (pthread_cond::wait): Accommodate change to pthread::cancelable_wait. (pthread::join): Ditto. (semaphore::_timedwait): Ditto. (semaphore::_wait): Ditto. Change to return int to allow status diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index a409fda04..4dcd5df8f 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -92,6 +92,10 @@ _cygtls::call2 (DWORD (*func) (void *, void *), void *arg, void *buf) _my_tls.init_thread (buf, func); DWORD res = func (arg, buf); _my_tls.remove (INFINITE); + // FIXME: Need some sort of atthreadexit function to allow things like + // select to control this themselves + if (_my_tls.locals.exitsock != INVALID_SOCKET) + closesocket (_my_tls.locals.exitsock); ExitThread (res); } @@ -114,6 +118,7 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *)) } local_clib._current_locale = "C"; locals.process_logmask = LOG_UPTO (LOG_DEBUG); + locals.exitsock = INVALID_SOCKET; } set_state (false); diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index 2ce91dbc8..016bf8c9c 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -16,6 +16,8 @@ details. */ #define _NOMNTENT_FUNCS #include <mntent.h> #undef _NOMNTENT_FUNCS +#define USE_SYS_TYPES_FD_SET +#include <winsock.h> #define CYGTLS_INITIALIZED 0x43227 #define CYGTLS_EXCEPTION (0x43227 + true) @@ -61,6 +63,10 @@ struct _local_storage char mnt_fsname[CYG_MAX_PATH]; char mnt_dir[CYG_MAX_PATH]; + /* select.cc */ + SOCKET exitsock; + struct sockaddr_in exitsock_sin; + /* strerror */ char strerror_buf[20]; diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 95ee14161..ee4d30d32 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -11,11 +11,8 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ -/* - * The following line means that the BSD socket - * definitions for fd_set, FD_ISSET etc. are used in this - * file. - */ +/* The following line means that the BSD socket definitions for + fd_set, FD_ISSET etc. are used in this file. */ #define __INSIDE_CYGWIN_NET__ @@ -43,6 +40,8 @@ details. */ #include "tty.h" #include "cygthread.h" #include "ntdll.h" +#include "cygtls.h" +#include <asm/byteorder.h> /* * All these defines below should be in sys/types.h @@ -1211,7 +1210,6 @@ struct socketinf cygthread *thread; winsock_fd_set readfds, writefds, exceptfds; SOCKET exitsock; - struct sockaddr_in sin; select_record *start; }; @@ -1306,12 +1304,9 @@ thread_socket (void *arg) if (WINSOCK_FD_ISSET (si->exitsock, &si->readfds)) select_printf ("saw exitsock read"); - return 0; } -extern "C" unsigned long htonl (unsigned long); - static int start_thread_socket (select_record *me, select_stuff *stuff) { @@ -1350,36 +1345,43 @@ start_thread_socket (select_record *me, select_stuff *stuff) } } - if ((si->exitsock = socket (PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) + if (_my_tls.locals.exitsock != INVALID_SOCKET) { - set_winsock_errno (); - select_printf ("cannot create socket, %E"); - return -1; + char buf[1]; + si->exitsock = _my_tls.locals.exitsock; + select_printf ("read a byte from %p", si->exitsock); + recv (si->exitsock, buf, 1, 0); } - /* Allow rapid reuse of the port. */ - int tmp = 1; - (void) setsockopt (si->exitsock, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof (tmp)); - - int sin_len = sizeof (si->sin); - memset (&si->sin, 0, sizeof (si->sin)); - si->sin.sin_family = AF_INET; - si->sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK); - if (bind (si->exitsock, (struct sockaddr *) &si->sin, sizeof (si->sin)) < 0) + else { - select_printf ("cannot bind socket, %E"); - goto err; - } + si->exitsock = _my_tls.locals.exitsock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (_my_tls.locals.exitsock == INVALID_SOCKET) + { + set_winsock_errno (); + select_printf ("cannot create socket, %E"); + return -1; + } +#if 0 + /* Allow rapid reuse of the port. */ + int tmp = 1; + (void) setsockopt (si->exitsock, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof (tmp)); +#endif - if (getsockname (si->exitsock, (struct sockaddr *) &si->sin, &sin_len) < 0) - { - select_printf ("getsockname error"); - goto err; - } + int sin_len = sizeof (_my_tls.locals.exitsock_sin); + memset (&_my_tls.locals.exitsock_sin, 0, sin_len); + _my_tls.locals.exitsock_sin.sin_family = AF_INET; + _my_tls.locals.exitsock_sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK); + if (bind (si->exitsock, (struct sockaddr *) &_my_tls.locals.exitsock_sin, sin_len) < 0) + { + select_printf ("cannot bind socket %p, %E", si->exitsock); + goto err; + } - if (listen (si->exitsock, 1)) - { - select_printf ("listen failed, %E"); - goto err; + if (getsockname (si->exitsock, (struct sockaddr *) &_my_tls.locals.exitsock_sin, &sin_len) < 0) + { + select_printf ("getsockname error"); + goto err; + } } select_printf ("exitsock %p", si->exitsock); @@ -1405,30 +1407,13 @@ socket_cleanup (select_record *, select_stuff *stuff) select_printf ("si %p si->thread %p", si, si ? si->thread : NULL); if (si && si->thread) { - select_printf ("connection to si->exitsock %p", si->exitsock); - SOCKET s = socket (AF_INET, SOCK_STREAM, 0); - - /* Set LINGER with 0 timeout for hard close */ - struct linger tmp = {1, 0}; /* On, 0 delay */ - (void) setsockopt (s, SOL_SOCKET, SO_LINGER, (char *)&tmp, sizeof (tmp)); - (void) setsockopt (si->exitsock, SOL_SOCKET, SO_LINGER, (char *)&tmp, sizeof (tmp)); - - /* Connecting to si->exitsock will cause any executing select to wake - up. When this happens then the exitsock condition will cause the - thread to terminate. */ - if (connect (s, (struct sockaddr *) &si->sin, sizeof (si->sin)) < 0) - { - set_winsock_errno (); - select_printf ("connect failed"); - /* FIXME: now what? */ - } - shutdown (s, SD_BOTH); - closesocket (s); - + char buf[] = ""; + int res = sendto (_my_tls.locals.exitsock, buf, 1, 0, + (sockaddr *) &_my_tls.locals.exitsock_sin, + sizeof (_my_tls.locals.exitsock_sin)); + select_printf ("sent a byte to the exit sock %p, res %d", _my_tls.locals.exitsock, res); /* Wait for thread to go away */ si->thread->detach (); - shutdown (si->exitsock, SD_BOTH); - closesocket (si->exitsock); stuff->device_specific_socket = NULL; delete si; } diff --git a/winsup/cygwin/tlsoffsets.h b/winsup/cygwin/tlsoffsets.h index 271ed367e..e6b955c51 100644 --- a/winsup/cygwin/tlsoffsets.h +++ b/winsup/cygwin/tlsoffsets.h @@ -1,113 +1,113 @@ //;# autogenerated: Do not edit. -//; $tls::sizeof__cygtls = 3912; -//; $tls::func = -3912; +//; $tls::sizeof__cygtls = 3932; +//; $tls::func = -3932; //; $tls::pfunc = 0; -//; $tls::saved_errno = -3908; +//; $tls::saved_errno = -3928; //; $tls::psaved_errno = 4; -//; $tls::sa_flags = -3904; +//; $tls::sa_flags = -3924; //; $tls::psa_flags = 8; -//; $tls::oldmask = -3900; +//; $tls::oldmask = -3920; //; $tls::poldmask = 12; -//; $tls::deltamask = -3896; +//; $tls::deltamask = -3916; //; $tls::pdeltamask = 16; -//; $tls::event = -3892; +//; $tls::event = -3912; //; $tls::pevent = 20; -//; $tls::errno_addr = -3888; +//; $tls::errno_addr = -3908; //; $tls::perrno_addr = 24; -//; $tls::initialized = -3884; +//; $tls::initialized = -3904; //; $tls::pinitialized = 28; -//; $tls::sigmask = -3880; +//; $tls::sigmask = -3900; //; $tls::psigmask = 32; -//; $tls::sigwait_mask = -3876; +//; $tls::sigwait_mask = -3896; //; $tls::psigwait_mask = 36; -//; $tls::sigwait_info = -3872; +//; $tls::sigwait_info = -3892; //; $tls::psigwait_info = 40; -//; $tls::threadkill = -3868; +//; $tls::threadkill = -3888; //; $tls::pthreadkill = 44; -//; $tls::infodata = -3864; +//; $tls::infodata = -3884; //; $tls::pinfodata = 48; -//; $tls::tid = -3716; +//; $tls::tid = -3736; //; $tls::ptid = 196; -//; $tls::local_clib = -3712; +//; $tls::local_clib = -3732; //; $tls::plocal_clib = 200; -//; $tls::__dontuse = -3712; +//; $tls::__dontuse = -3732; //; $tls::p__dontuse = 200; -//; $tls::locals = -2648; +//; $tls::locals = -2668; //; $tls::plocals = 1264; //; $tls::wq = -1080; -//; $tls::pwq = 2832; +//; $tls::pwq = 2852; //; $tls::prev = -1052; -//; $tls::pprev = 2860; +//; $tls::pprev = 2880; //; $tls::next = -1048; -//; $tls::pnext = 2864; +//; $tls::pnext = 2884; //; $tls::stackptr = -1044; -//; $tls::pstackptr = 2868; +//; $tls::pstackptr = 2888; //; $tls::sig = -1040; -//; $tls::psig = 2872; +//; $tls::psig = 2892; //; $tls::incyg = -1036; -//; $tls::pincyg = 2876; +//; $tls::pincyg = 2896; //; $tls::spinning = -1032; -//; $tls::pspinning = 2880; +//; $tls::pspinning = 2900; //; $tls::stacklock = -1028; -//; $tls::pstacklock = 2884; +//; $tls::pstacklock = 2904; //; $tls::stack = -1024; -//; $tls::pstack = 2888; +//; $tls::pstack = 2908; //; $tls::padding = 0; -//; $tls::ppadding = 3912; +//; $tls::ppadding = 3932; //; __DATA__ -#define tls_func (-3912) +#define tls_func (-3932) #define tls_pfunc (0) -#define tls_saved_errno (-3908) +#define tls_saved_errno (-3928) #define tls_psaved_errno (4) -#define tls_sa_flags (-3904) +#define tls_sa_flags (-3924) #define tls_psa_flags (8) -#define tls_oldmask (-3900) +#define tls_oldmask (-3920) #define tls_poldmask (12) -#define tls_deltamask (-3896) +#define tls_deltamask (-3916) #define tls_pdeltamask (16) -#define tls_event (-3892) +#define tls_event (-3912) #define tls_pevent (20) -#define tls_errno_addr (-3888) +#define tls_errno_addr (-3908) #define tls_perrno_addr (24) -#define tls_initialized (-3884) +#define tls_initialized (-3904) #define tls_pinitialized (28) -#define tls_sigmask (-3880) +#define tls_sigmask (-3900) #define tls_psigmask (32) -#define tls_sigwait_mask (-3876) +#define tls_sigwait_mask (-3896) #define tls_psigwait_mask (36) -#define tls_sigwait_info (-3872) +#define tls_sigwait_info (-3892) #define tls_psigwait_info (40) -#define tls_threadkill (-3868) +#define tls_threadkill (-3888) #define tls_pthreadkill (44) -#define tls_infodata (-3864) +#define tls_infodata (-3884) #define tls_pinfodata (48) -#define tls_tid (-3716) +#define tls_tid (-3736) #define tls_ptid (196) -#define tls_local_clib (-3712) +#define tls_local_clib (-3732) #define tls_plocal_clib (200) -#define tls___dontuse (-3712) +#define tls___dontuse (-3732) #define tls_p__dontuse (200) -#define tls_locals (-2648) +#define tls_locals (-2668) #define tls_plocals (1264) #define tls_wq (-1080) -#define tls_pwq (2832) +#define tls_pwq (2852) #define tls_prev (-1052) -#define tls_pprev (2860) +#define tls_pprev (2880) #define tls_next (-1048) -#define tls_pnext (2864) +#define tls_pnext (2884) #define tls_stackptr (-1044) -#define tls_pstackptr (2868) +#define tls_pstackptr (2888) #define tls_sig (-1040) -#define tls_psig (2872) +#define tls_psig (2892) #define tls_incyg (-1036) -#define tls_pincyg (2876) +#define tls_pincyg (2896) #define tls_spinning (-1032) -#define tls_pspinning (2880) +#define tls_pspinning (2900) #define tls_stacklock (-1028) -#define tls_pstacklock (2884) +#define tls_pstacklock (2904) #define tls_stack (-1024) -#define tls_pstack (2888) +#define tls_pstack (2908) #define tls_padding (0) -#define tls_ppadding (3912) +#define tls_ppadding (3932) |