From 2ce7b3c000d4927f48b545a7927e67d7d1c03607 Mon Sep 17 00:00:00 2001 From: Conrad Scott Date: Sat, 27 Jul 2002 13:36:14 +0000 Subject: * include/cygwin/cygserver_transport_pipes.h (cygserver_transport_pipes::_sd): Rename field. (cygserver_transport_pipes::_sec_none_nih): Ditto. (cygserver_transport_pipes::_sec_all_nih): Ditto. (cygserver_transport_pipes::_pipe_name): Ditto. (cygserver_transport_pipes::_hPipe): Ditto. (cygserver_transport_pipes::_is_accepted_endpoint): Ditto. * cygserver_transport_pipes.cc (transport_layer_pipes::transport_layer_pipes): Rename fields. (transport_layer_pipes::init_security): Ditto. (transport_layer_pipes::listen): Ditto. (transport_layer_pipes::accept): Ditto. (transport_layer_pipes::close): Ditto. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::connect): Ditto. (transport_layer_pipes::impersonate_client): Ditto. (transport_layer_pipes::revert_to_self): Ditto. * include/cygwin/cygserver_transport_sockets.h (cygserver_transport_sockets::_fd): Rename field. (cygserver_transport_sockets::_addr): Ditto. (cygserver_transport_sockets::_addr_len): Ditto. * cygserver_transport_sockets.cc (transport_layer_sockets::transport_layer_sockets): Rename fields. (transport_layer_sockets::listen): Ditto. (transport_layer_sockets::accept): Ditto. (transport_layer_sockets::close): Ditto. (transport_layer_sockets::read): Ditto. (transport_layer_sockets::write): Ditto. (transport_layer_sockets::connect): Ditto. --- winsup/cygwin/ChangeLog | 33 ++++++ winsup/cygwin/cygserver_transport_pipes.cc | 122 ++++++++++----------- winsup/cygwin/cygserver_transport_sockets.cc | 76 ++++++------- .../include/cygwin/cygserver_transport_pipes.h | 12 +- .../include/cygwin/cygserver_transport_sockets.h | 6 +- 5 files changed, 139 insertions(+), 110 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 91abe87be..88afcf968 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,36 @@ +2002-07-27 Conrad Scott + + * include/cygwin/cygserver_transport_pipes.h + (cygserver_transport_pipes::_sd): Rename field. + (cygserver_transport_pipes::_sec_none_nih): Ditto. + (cygserver_transport_pipes::_sec_all_nih): Ditto. + (cygserver_transport_pipes::_pipe_name): Ditto. + (cygserver_transport_pipes::_hPipe): Ditto. + (cygserver_transport_pipes::_is_accepted_endpoint): Ditto. + * cygserver_transport_pipes.cc + (transport_layer_pipes::transport_layer_pipes): Rename fields. + (transport_layer_pipes::init_security): Ditto. + (transport_layer_pipes::listen): Ditto. + (transport_layer_pipes::accept): Ditto. + (transport_layer_pipes::close): Ditto. + (transport_layer_pipes::read): Ditto. + (transport_layer_pipes::write): Ditto. + (transport_layer_pipes::connect): Ditto. + (transport_layer_pipes::impersonate_client): Ditto. + (transport_layer_pipes::revert_to_self): Ditto. + * include/cygwin/cygserver_transport_sockets.h + (cygserver_transport_sockets::_fd): Rename field. + (cygserver_transport_sockets::_addr): Ditto. + (cygserver_transport_sockets::_addr_len): Ditto. + * cygserver_transport_sockets.cc + (transport_layer_sockets::transport_layer_sockets): Rename fields. + (transport_layer_sockets::listen): Ditto. + (transport_layer_sockets::accept): Ditto. + (transport_layer_sockets::close): Ditto. + (transport_layer_sockets::read): Ditto. + (transport_layer_sockets::write): Ditto. + (transport_layer_sockets::connect): Ditto. + 2002-07-27 Conrad Scott * cygserver_shm.cc (with_strerr): Fix use of %p format. diff --git a/winsup/cygwin/cygserver_transport_pipes.cc b/winsup/cygwin/cygserver_transport_pipes.cc index 3a230cf11..7668d6cc9 100755 --- a/winsup/cygwin/cygserver_transport_pipes.cc +++ b/winsup/cygwin/cygserver_transport_pipes.cc @@ -56,12 +56,12 @@ initialise_pipe_instance_lock () #ifndef __INSIDE_CYGWIN__ -transport_layer_pipes::transport_layer_pipes (const HANDLE new_pipe) - : pipe_name (""), - pipe (new_pipe), - is_accepted_endpoint (true) +transport_layer_pipes::transport_layer_pipes (const HANDLE hPipe) + : _pipe_name (""), + _hPipe (hPipe), + _is_accepted_endpoint (true) { - assert (pipe && pipe != INVALID_HANDLE_VALUE); + assert (_hPipe && _hPipe != INVALID_HANDLE_VALUE); init_security (); } @@ -69,9 +69,9 @@ transport_layer_pipes::transport_layer_pipes (const HANDLE new_pipe) #endif /* !__INSIDE_CYGWIN__ */ transport_layer_pipes::transport_layer_pipes () - : pipe_name ("\\\\.\\pipe\\cygwin_lpc"), - pipe (NULL), - is_accepted_endpoint (false) + : _pipe_name ("\\\\.\\pipe\\cygwin_lpc"), + _hPipe (NULL), + _is_accepted_endpoint (false) { init_security (); } @@ -83,13 +83,13 @@ transport_layer_pipes::init_security () /* FIXME: pthread_once or equivalent needed */ - InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION); - SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE); + InitializeSecurityDescriptor (&_sd, SECURITY_DESCRIPTOR_REVISION); + SetSecurityDescriptorDacl (&_sd, TRUE, NULL, FALSE); - sec_none_nih.nLength = sec_all_nih.nLength = sizeof (SECURITY_ATTRIBUTES); - sec_none_nih.bInheritHandle = sec_all_nih.bInheritHandle = FALSE; - sec_none_nih.lpSecurityDescriptor = NULL; - sec_all_nih.lpSecurityDescriptor = &sd; + _sec_none_nih.nLength = _sec_all_nih.nLength = sizeof (SECURITY_ATTRIBUTES); + _sec_none_nih.bInheritHandle = _sec_all_nih.bInheritHandle = FALSE; + _sec_none_nih.lpSecurityDescriptor = NULL; + _sec_all_nih.lpSecurityDescriptor = &_sd; } transport_layer_pipes::~transport_layer_pipes () @@ -102,16 +102,16 @@ transport_layer_pipes::~transport_layer_pipes () void transport_layer_pipes::listen () { - assert (!is_accepted_endpoint); - assert (!pipe); + assert (!_is_accepted_endpoint); + assert (!_hPipe); /* no-op */ } class transport_layer_pipes * transport_layer_pipes::accept (bool *const recoverable) { - assert (!is_accepted_endpoint); - assert (!pipe); + assert (!_is_accepted_endpoint); + assert (!_hPipe); pthread_once (&pipe_instance_lock_once, &initialise_pipe_instance_lock); @@ -125,13 +125,13 @@ transport_layer_pipes::accept (bool *const recoverable) const bool first_instance = (pipe_instance == 0); const HANDLE accept_pipe = - CreateNamedPipe (pipe_name, + CreateNamedPipe (_pipe_name, (PIPE_ACCESS_DUPLEX | (first_instance ? FILE_FLAG_FIRST_PIPE_INSTANCE : 0)), (PIPE_TYPE_BYTE | PIPE_WAIT), PIPE_UNLIMITED_INSTANCES, 0, 0, 1000, - &sec_all_nih); + &_sec_all_nih); const bool duplicate = (accept_pipe == INVALID_HANDLE_VALUE && pipe_instance == 0 @@ -176,53 +176,53 @@ transport_layer_pipes::accept (bool *const recoverable) void transport_layer_pipes::close () { - // verbose: debug_printf ("closing pipe %p", pipe); + // verbose: debug_printf ("closing pipe %p", _hPipe); - if (pipe) + if (_hPipe) { - assert (pipe != INVALID_HANDLE_VALUE); + assert (_hPipe != INVALID_HANDLE_VALUE); #ifndef __INSIDE_CYGWIN__ - if (is_accepted_endpoint) + if (_is_accepted_endpoint) { - (void) FlushFileBuffers (pipe); // Blocks until client reads. - (void) DisconnectNamedPipe (pipe); + (void) FlushFileBuffers (_hPipe); // Blocks until client reads. + (void) DisconnectNamedPipe (_hPipe); EnterCriticalSection (&pipe_instance_lock); - (void) CloseHandle (pipe); + (void) CloseHandle (_hPipe); assert (pipe_instance > 0); InterlockedDecrement (&pipe_instance); LeaveCriticalSection (&pipe_instance_lock); } else - (void) CloseHandle (pipe); + (void) CloseHandle (_hPipe); #else /* __INSIDE_CYGWIN__ */ - assert (!is_accepted_endpoint); - (void) ForceCloseHandle (pipe); + assert (!_is_accepted_endpoint); + (void) ForceCloseHandle (_hPipe); #endif /* __INSIDE_CYGWIN__ */ - pipe = NULL; + _hPipe = NULL; } } ssize_t transport_layer_pipes::read (void *const buf, const size_t len) { - // verbose: debug_printf ("reading from pipe %p", pipe); + // verbose: debug_printf ("reading from pipe %p", _hPipe); - if (!pipe) + if (!_hPipe) { set_errno (EBADF); return -1; } - assert (pipe != INVALID_HANDLE_VALUE); + assert (_hPipe != INVALID_HANDLE_VALUE); DWORD count; - if (!ReadFile (pipe, buf, len, &count, NULL)) + if (!ReadFile (_hPipe, buf, len, &count, NULL)) { debug_printf ("error reading from pipe (%lu)", GetLastError ()); set_errno (EINVAL); // FIXME? @@ -235,18 +235,18 @@ transport_layer_pipes::read (void *const buf, const size_t len) ssize_t transport_layer_pipes::write (void *const buf, const size_t len) { - // verbose: debug_printf ("writing to pipe %p", pipe); + // verbose: debug_printf ("writing to pipe %p", _hPipe); - if (!pipe) + if (!_hPipe) { set_errno (EBADF); return -1; } - assert (pipe != INVALID_HANDLE_VALUE); + assert (_hPipe != INVALID_HANDLE_VALUE); DWORD count; - if (!WriteFile (pipe, buf, len, &count, NULL)) + if (!WriteFile (_hPipe, buf, len, &count, NULL)) { debug_printf ("error writing to pipe, error = %lu", GetLastError ()); set_errno (EINVAL); // FIXME? @@ -268,9 +268,9 @@ transport_layer_pipes::write (void *const buf, const size_t len) bool transport_layer_pipes::connect () { - if (pipe) + if (_hPipe) { - assert (pipe != INVALID_HANDLE_VALUE); + assert (_hPipe != INVALID_HANDLE_VALUE); debug_printf ("Already have a pipe in this %p",this); return false; @@ -283,19 +283,19 @@ transport_layer_pipes::connect () while (rc) { - pipe = CreateFile (pipe_name, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &sec_all_nih, - OPEN_EXISTING, - SECURITY_IMPERSONATION, - NULL); - - if (pipe != INVALID_HANDLE_VALUE) + _hPipe = CreateFile (_pipe_name, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &_sec_all_nih, + OPEN_EXISTING, + SECURITY_IMPERSONATION, + NULL); + + if (_hPipe != INVALID_HANDLE_VALUE) { - assert (pipe); + assert (_hPipe); #ifdef __INSIDE_CYGWIN__ - ProtectHandle (pipe); + ProtectHandle (_hPipe); #endif assume_cygserver = true; return true; @@ -304,11 +304,11 @@ transport_layer_pipes::connect () if (!assume_cygserver && GetLastError () != ERROR_PIPE_BUSY) { debug_printf ("Error opening the pipe (%lu)", GetLastError ()); - pipe = NULL; + _hPipe = NULL; return false; } - pipe = NULL; + _hPipe = NULL; /* Note: `If no instances of the specified named pipe exist, the * WaitNamedPipe function returns immediately, regardless of the @@ -316,7 +316,7 @@ transport_layer_pipes::connect () * with ERROR_FILE_NOT_FOUND. */ while (retries != MAX_WAIT_NAMED_PIPE_RETRY - && !(rc = WaitNamedPipe (pipe_name, WAIT_NAMED_PIPE_TIMEOUT))) + && !(rc = WaitNamedPipe (_pipe_name, WAIT_NAMED_PIPE_TIMEOUT))) { if (GetLastError () == ERROR_FILE_NOT_FOUND) Sleep (0); // Give the server a chance. @@ -340,14 +340,14 @@ transport_layer_pipes::connect () void transport_layer_pipes::impersonate_client () { - assert (is_accepted_endpoint); + assert (_is_accepted_endpoint); - // verbose: debug_printf ("impersonating pipe %p", pipe); - if (pipe) + // verbose: debug_printf ("impersonating pipe %p", _hPipe); + if (_hPipe) { - assert (pipe != INVALID_HANDLE_VALUE); + assert (_hPipe != INVALID_HANDLE_VALUE); - if (!ImpersonateNamedPipeClient (pipe)) + if (!ImpersonateNamedPipeClient (_hPipe)) debug_printf ("Failed to Impersonate the client, (%lu)", GetLastError ()); } @@ -357,7 +357,7 @@ transport_layer_pipes::impersonate_client () void transport_layer_pipes::revert_to_self () { - assert (is_accepted_endpoint); + assert (_is_accepted_endpoint); RevertToSelf (); // verbose: debug_printf ("I am who I yam"); diff --git a/winsup/cygwin/cygserver_transport_sockets.cc b/winsup/cygwin/cygserver_transport_sockets.cc index bf79dffae..a2f8131db 100755 --- a/winsup/cygwin/cygserver_transport_sockets.cc +++ b/winsup/cygwin/cygserver_transport_sockets.cc @@ -28,43 +28,39 @@ details. */ /* to allow this to link into cygwin and the .dll, a little magic is needed. */ #ifndef __OUTSIDE_CYGWIN__ -extern "C" int -cygwin_socket (int af, int type, int protocol); -extern "C" int -cygwin_connect (int fd, - const struct sockaddr *name, - int namelen); -extern "C" int -cygwin_accept (int fd, struct sockaddr *peer, int *len); -extern "C" int -cygwin_listen (int fd, int backlog); -extern "C" int -cygwin_bind (int fd, const struct sockaddr *my_addr, int addrlen); -#else -#define cygwin_accept(A,B,C) ::accept (A,B,C) -#define cygwin_socket(A,B,C) ::socket (A,B,C) -#define cygwin_listen(A,B) ::listen (A,B) -#define cygwin_bind(A,B,C) ::bind (A,B,C) -#define cygwin_connect(A,B,C) ::connect (A,B,C) -#endif +extern "C" int cygwin_accept (int fd, struct sockaddr *, int *len); +extern "C" int cygwin_bind (int fd, const struct sockaddr *, int len); +extern "C" int cygwin_connect (int fd, const struct sockaddr *, int len); +extern "C" int cygwin_listen (int fd, int backlog); +extern "C" int cygwin_socket (int af, int type, int protocol); + +#else /* __OUTSIDE_CYGWIN__ */ + +#define cygwin_accept(A,B,C) ::accept (A,B,C) +#define cygwin_bind(A,B,C) ::bind (A,B,C) +#define cygwin_connect(A,B,C) ::connect (A,B,C) +#define cygwin_listen(A,B) ::listen (A,B) +#define cygwin_socket(A,B,C) ::socket (A,B,C) + +#endif /* __OUTSIDE_CYGWIN__ */ transport_layer_sockets::transport_layer_sockets (int newfd) - : fd (newfd) + : _fd (newfd) { /* This may not be needed in this constructor - it's only used * when creating a connection via bind or connect */ - sockdetails.sa_family = AF_UNIX; - strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); - sdlen = strlen (sockdetails.sa_data) + sizeof (sockdetails.sa_family); + _addr.sa_family = AF_UNIX; + strcpy (_addr.sa_data, "/tmp/cygdaemo"); + _addr_len = strlen (_addr.sa_data) + sizeof (_addr.sa_family); }; -transport_layer_sockets::transport_layer_sockets (): fd (-1) +transport_layer_sockets::transport_layer_sockets (): _fd (-1) { - sockdetails.sa_family = AF_UNIX; - strcpy (sockdetails.sa_data, "/tmp/cygdaemo"); - sdlen = strlen (sockdetails.sa_data) + sizeof (sockdetails.sa_family); + _addr.sa_family = AF_UNIX; + strcpy (_addr.sa_data, "/tmp/cygdaemo"); + _addr_len = strlen (_addr.sa_data) + sizeof (_addr.sa_family); } transport_layer_sockets::~transport_layer_sockets () @@ -78,11 +74,11 @@ void transport_layer_sockets::listen () { /* we want a thread pool based approach. */ - if ((fd = cygwin_socket (AF_UNIX, SOCK_STREAM,0)) < 0) + if ((_fd = cygwin_socket (AF_UNIX, SOCK_STREAM,0)) < 0) system_printf ("Socket not created error %d", errno); - if (cygwin_bind (fd, &sockdetails, sdlen)) + if (cygwin_bind (_fd, &_addr, _addr_len)) system_printf ("Bind doesn't like you. Tsk Tsk. Bind said %d", errno); - if (cygwin_listen (fd, 5) < 0) + if (cygwin_listen (_fd, 5) < 0) system_printf ("And the OS just isn't listening, all it says is %d", errno); } @@ -91,7 +87,7 @@ class transport_layer_sockets * transport_layer_sockets::accept (bool *const recoverable) { /* FIXME: check we have listened */ - const int accept_fd = cygwin_accept (fd, &sockdetails, &sdlen); + const int accept_fd = cygwin_accept (_fd, &_addr, &_addr_len); if (accept_fd == -1) { @@ -123,10 +119,10 @@ void transport_layer_sockets::close () { /* FIXME - are we open? */ - if (fd != -1) + if (_fd != -1) { - ::close (fd); - fd = -1; + ::close (_fd); + _fd = -1; } } @@ -134,27 +130,27 @@ ssize_t transport_layer_sockets::read (void *buf, size_t len) { /* FIXME: are we open? */ - return ::read (fd, buf, len); + return ::read (_fd, buf, len); } ssize_t transport_layer_sockets::write (void *buf, size_t len) { /* FIXME: are we open? */ - return ::write (fd, buf, len); + return ::write (_fd, buf, len); } bool transport_layer_sockets::connect () { /* are we already connected? */ - if (fd != -1) + if (_fd != -1) return false; - fd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); - if (cygwin_connect (fd, &sockdetails, sdlen) < 0) + _fd = cygwin_socket (AF_UNIX, SOCK_STREAM, 0); + if (cygwin_connect (_fd, &_addr, _addr_len) < 0) { debug_printf ("client connect failure %d", errno); - ::close (fd); + ::close (_fd); return false; } return true; diff --git a/winsup/cygwin/include/cygwin/cygserver_transport_pipes.h b/winsup/cygwin/include/cygwin/cygserver_transport_pipes.h index 1f4a86ca7..fe571a770 100755 --- a/winsup/cygwin/include/cygwin/cygserver_transport_pipes.h +++ b/winsup/cygwin/include/cygwin/cygserver_transport_pipes.h @@ -39,13 +39,13 @@ private: /* for pipe based communications */ void init_security (); //FIXME: allow inited, sd, all_nih_.. to be static members - SECURITY_DESCRIPTOR sd; - SECURITY_ATTRIBUTES sec_none_nih, sec_all_nih; - const char *const pipe_name; - HANDLE pipe; - const bool is_accepted_endpoint; + SECURITY_DESCRIPTOR _sd; + SECURITY_ATTRIBUTES _sec_none_nih, _sec_all_nih; + const char *const _pipe_name; + HANDLE _hPipe; + const bool _is_accepted_endpoint; - transport_layer_pipes (HANDLE new_pipe); + transport_layer_pipes (HANDLE hPipe); }; #endif /* _CYGSERVER_TRANSPORT_PIPES_ */ diff --git a/winsup/cygwin/include/cygwin/cygserver_transport_sockets.h b/winsup/cygwin/include/cygwin/cygserver_transport_sockets.h index 0b646cdc6..97d3baa23 100755 --- a/winsup/cygwin/include/cygwin/cygserver_transport_sockets.h +++ b/winsup/cygwin/include/cygwin/cygserver_transport_sockets.h @@ -31,9 +31,9 @@ public: private: /* for socket based communications */ - int fd; - struct sockaddr sockdetails; - int sdlen; + int _fd; + struct sockaddr _addr; + int _addr_len; transport_layer_sockets (int newfd); }; -- cgit v1.2.3