diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2018-03-07 16:00:36 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2018-03-07 16:04:26 +0100 |
commit | d69bcdd671539caea906f18e327dfd2eb9f1da85 (patch) | |
tree | f903a577778f95a6816f33eee5fa74d612d49e2e | |
parent | e94fa4ebf39384446f89a44b3769756fb51cb4f9 (diff) | |
download | cygnal-d69bcdd671539caea906f18e327dfd2eb9f1da85.tar.gz cygnal-d69bcdd671539caea906f18e327dfd2eb9f1da85.tar.bz2 cygnal-d69bcdd671539caea906f18e327dfd2eb9f1da85.zip |
Cygwin: AF_UNIX: Add create_event helper and use throughout
Minimize overhead in creating a nameless event object.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r-- | winsup/cygwin/fhandler_socket_unix.cc | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc index d5f617d92..ea8aeced2 100644 --- a/winsup/cygwin/fhandler_socket_unix.cc +++ b/winsup/cygwin/fhandler_socket_unix.cc @@ -148,6 +148,24 @@ sun_name_t::sun_name_t (const struct sockaddr *name, socklen_t namelen) _nul[sizeof (struct sockaddr_un)] = '\0'; } +static HANDLE +create_event () +{ + NTSTATUS status; + OBJECT_ATTRIBUTES attr; + HANDLE evt = NULL; + + InitializeObjectAttributes (&attr, NULL, 0, NULL, NULL); + status = NtCreateEvent (&evt, EVENT_ALL_ACCESS, &attr, + NotificationEvent, FALSE); + if (!NT_SUCCESS (status)) + __seterrno_from_nt_status (status); + return evt; +} + +/* Character length of pipe name, excluding trailing NUL. */ +#define CYGWIN_PIPE_SOCKET_NAME_LEN 47 + /* Character position encoding the socket type in a pipe name. */ #define CYGWIN_PIPE_SOCKET_TYPE_POS 29 @@ -555,6 +573,7 @@ fhandler_socket_unix::send_my_name () int fhandler_socket_unix::recv_peer_name () { + HANDLE evt; NTSTATUS status; IO_STATUS_BLOCK io; af_unix_pkt_hdr_t *packet; @@ -562,10 +581,12 @@ fhandler_socket_unix::recv_peer_name () ULONG len; int ret = 0; + if (!(evt = create_event ())) + return ENOBUFS; len = sizeof *packet + sizeof *un; packet = (af_unix_pkt_hdr_t *) alloca (len); set_pipe_non_blocking (false); - status = NtReadFile (get_handle (), NULL, NULL, NULL, &io, packet, len, + status = NtReadFile (get_handle (), evt, NULL, NULL, &io, packet, len, NULL, NULL); if (status == STATUS_PENDING) { @@ -573,7 +594,7 @@ fhandler_socket_unix::recv_peer_name () LARGE_INTEGER timeout; timeout.QuadPart = -20 * NS100PERSEC; /* 20 secs */ - ret = cygwait (connect_wait_thr, &timeout, cw_sig_eintr); + ret = cygwait (evt, &timeout, cw_sig_eintr); switch (ret) { case WAIT_OBJECT_0: @@ -835,22 +856,11 @@ fhandler_socket_unix::listen_pipe () { NTSTATUS status; IO_STATUS_BLOCK io; - OBJECT_ATTRIBUTES attr; HANDLE evt = NULL; io.Status = STATUS_PENDING; - if (!is_nonblocking ()) - { - /* Create event object and set APC context pointer. */ - InitializeObjectAttributes (&attr, NULL, 0, NULL, NULL); - status = NtCreateEvent (&evt, EVENT_ALL_ACCESS, &attr, - NotificationEvent, FALSE); - if (!NT_SUCCESS (status)) - { - __seterrno_from_nt_status (status); - return -1; - } - } + if (!is_nonblocking () && !(evt = create_event ())) + return -1; status = NtFsControlFile (get_handle (), evt, NULL, NULL, &io, FSCTL_PIPE_LISTEN, NULL, 0, NULL, 0); if (status == STATUS_PENDING) |