Cygwin: FIFO: rename client[] to fc_handler[]

The word "client" suggests something that holds a handle to the client
side of the pipe (in Windows terminology).  But our
fifo_client_handlers hold a handle the server side of the pipe, and
they *connect* to clients.
This commit is contained in:
Ken Brown 2019-04-14 19:15:56 +00:00 committed by Corinna Vinschen
parent 1e6c561d48
commit b63843ed56
3 changed files with 59 additions and 59 deletions

View File

@ -1269,8 +1269,8 @@ class fhandler_fifo: public fhandler_base
HANDLE lct_termination_evt; HANDLE lct_termination_evt;
UNICODE_STRING pipe_name; UNICODE_STRING pipe_name;
WCHAR pipe_name_buf[CYGWIN_FIFO_PIPE_NAME_LEN + 1]; WCHAR pipe_name_buf[CYGWIN_FIFO_PIPE_NAME_LEN + 1];
fifo_client_handler client[MAX_CLIENTS]; fifo_client_handler fc_handler[MAX_CLIENTS];
int nclients, nconnected; int nhandlers, nconnected;
af_unix_spinlock_t _fifo_client_lock; af_unix_spinlock_t _fifo_client_lock;
bool _duplexer; bool _duplexer;
bool __reg2 wait (HANDLE); bool __reg2 wait (HANDLE);
@ -1278,15 +1278,15 @@ class fhandler_fifo: public fhandler_base
HANDLE create_pipe_instance (bool); HANDLE create_pipe_instance (bool);
NTSTATUS open_pipe (); NTSTATUS open_pipe ();
int disconnect_and_reconnect (int); int disconnect_and_reconnect (int);
int add_client (); int add_client_handler ();
bool listen_client (); bool listen_client ();
public: public:
fhandler_fifo (); fhandler_fifo ();
bool hit_eof (); bool hit_eof ();
int get_nclients () const { return nclients; } int get_nhandlers () const { return nhandlers; }
HANDLE& get_handle () { return fhandler_base::get_handle (); } HANDLE& get_handle () { return fhandler_base::get_handle (); }
HANDLE get_handle (int i) const { return client[i].fh->get_handle (); } HANDLE get_handle (int i) const { return fc_handler[i].fh->get_handle (); }
bool is_connected (int i) const { return client[i].state == fc_connected; } bool is_connected (int i) const { return fc_handler[i].state == fc_connected; }
PUNICODE_STRING get_pipe_name (); PUNICODE_STRING get_pipe_name ();
DWORD listen_client_thread (); DWORD listen_client_thread ();
void fifo_client_lock () { _fifo_client_lock.lock (); } void fifo_client_lock () { _fifo_client_lock.lock (); }
@ -1305,8 +1305,8 @@ public:
void clear_readahead () void clear_readahead ()
{ {
fhandler_base::clear_readahead (); fhandler_base::clear_readahead ();
for (int i = 0; i < nclients; i++) for (int i = 0; i < nhandlers; i++)
client[i].fh->clear_readahead (); fc_handler[i].fh->clear_readahead ();
} }
select_record *select_read (select_stuff *); select_record *select_read (select_stuff *);
select_record *select_write (select_stuff *); select_record *select_write (select_stuff *);
@ -1326,8 +1326,8 @@ public:
void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_fifo)); void *ptr = (void *) ccalloc (malloc_type, 1, sizeof (fhandler_fifo));
fhandler_fifo *fhf = new (ptr) fhandler_fifo (ptr); fhandler_fifo *fhf = new (ptr) fhandler_fifo (ptr);
copyto (fhf); copyto (fhf);
for (int i = 0; i < nclients; i++) for (int i = 0; i < nhandlers; i++)
fhf->client[i].fh = client[i].fh->clone (); fhf->fc_handler[i].fh = fc_handler[i].fh->clone ();
return fhf; return fhf;
} }
}; };

View File

@ -32,7 +32,7 @@ STATUS_PIPE_EMPTY simply means there's no data to be read. */
fhandler_fifo::fhandler_fifo (): fhandler_fifo::fhandler_fifo ():
fhandler_base (), read_ready (NULL), write_ready (NULL), fhandler_base (), read_ready (NULL), write_ready (NULL),
listen_client_thr (NULL), lct_termination_evt (NULL), nclients (0), listen_client_thr (NULL), lct_termination_evt (NULL), nhandlers (0),
nconnected (0), _duplexer (false) nconnected (0), _duplexer (false)
{ {
pipe_name_buf[0] = L'\0'; pipe_name_buf[0] = L'\0';
@ -146,7 +146,7 @@ fhandler_fifo::disconnect_and_reconnect (int i)
{ {
NTSTATUS status; NTSTATUS status;
IO_STATUS_BLOCK io; IO_STATUS_BLOCK io;
HANDLE ph = client[i].fh->get_handle (); HANDLE ph = fc_handler[i].fh->get_handle ();
status = NtFsControlFile (ph, NULL, NULL, NULL, &io, FSCTL_PIPE_DISCONNECT, status = NtFsControlFile (ph, NULL, NULL, NULL, &io, FSCTL_PIPE_DISCONNECT,
NULL, 0, NULL, 0); NULL, 0, NULL, 0);
@ -159,10 +159,10 @@ fhandler_fifo::disconnect_and_reconnect (int i)
__seterrno_from_nt_status (status); __seterrno_from_nt_status (status);
return -1; return -1;
} }
set_pipe_non_blocking (client[i].fh->get_handle (), false); set_pipe_non_blocking (fc_handler[i].fh->get_handle (), false);
if (client[i].connect () < 0) if (fc_handler[i].connect () < 0)
return -1; return -1;
if (client[i].state == fc_connected) if (fc_handler[i].state == fc_connected)
nconnected++; nconnected++;
return 0; return 0;
} }
@ -198,9 +198,9 @@ fhandler_fifo::npfs_handle (HANDLE &nph)
} }
/* Called when a FIFO is first opened for reading and again each time /* Called when a FIFO is first opened for reading and again each time
a new client is needed. Each pipe instance is created in blocking a new client handler is needed. Each pipe instance is created in
mode so that we can easily wait for a connection. After it is blocking mode so that we can easily wait for a connection. After
connected, it is put in nonblocking mode. */ it is connected, it is put in nonblocking mode. */
HANDLE HANDLE
fhandler_fifo::create_pipe_instance (bool first) fhandler_fifo::create_pipe_instance (bool first)
{ {
@ -271,13 +271,13 @@ fhandler_fifo::open_pipe ()
} }
int int
fhandler_fifo::add_client () fhandler_fifo::add_client_handler ()
{ {
fifo_client_handler fc; fifo_client_handler fc;
fhandler_base *fh; fhandler_base *fh;
bool first = (nclients == 0); bool first = (nhandlers == 0);
if (nclients == MAX_CLIENTS) if (nhandlers == MAX_CLIENTS)
{ {
set_errno (EMFILE); set_errno (EMFILE);
return -1; return -1;
@ -302,7 +302,7 @@ fhandler_fifo::add_client ()
} }
if (fc.state == fc_connected) if (fc.state == fc_connected)
nconnected++; nconnected++;
client[nclients++] = fc; fc_handler[nhandlers++] = fc;
return 0; return 0;
errout: errout:
delete fh; delete fh;
@ -353,8 +353,8 @@ fhandler_fifo::listen_client_thread ()
fifo_client_lock (); fifo_client_lock ();
found = false; found = false;
for (i = 0; i < nclients; i++) for (i = 0; i < nhandlers; i++)
switch (client[i].state) switch (fc_handler[i].state)
{ {
case fc_invalid: case fc_invalid:
if (disconnect_and_reconnect (i) < 0) if (disconnect_and_reconnect (i) < 0)
@ -364,20 +364,20 @@ fhandler_fifo::listen_client_thread ()
} }
/* Fall through. */ /* Fall through. */
case fc_connected: case fc_connected:
w[i] = client[i].dummy_evt; w[i] = fc_handler[i].dummy_evt;
break; break;
case fc_connecting: case fc_connecting:
found = true; found = true;
w[i] = client[i].connect_evt; w[i] = fc_handler[i].connect_evt;
break; break;
case fc_unknown: /* Shouldn't happen. */ case fc_unknown: /* Shouldn't happen. */
default: default:
break; break;
} }
w[nclients] = lct_termination_evt; w[nhandlers] = lct_termination_evt;
int res = 0; int res = 0;
if (!found) if (!found)
res = add_client (); res = add_client_handler ();
fifo_client_unlock (); fifo_client_unlock ();
if (res < 0) if (res < 0)
goto errout; goto errout;
@ -391,18 +391,18 @@ fhandler_fifo::listen_client_thread ()
} }
/* Wait for a client to connect. */ /* Wait for a client to connect. */
wait_ret = WaitForMultipleObjects (nclients + 1, w, false, INFINITE); wait_ret = WaitForMultipleObjects (nhandlers + 1, w, false, INFINITE);
i = wait_ret - WAIT_OBJECT_0; i = wait_ret - WAIT_OBJECT_0;
if (i < 0 || i > nclients) if (i < 0 || i > nhandlers)
goto errout; goto errout;
else if (i == nclients) /* Reader is closing. */ else if (i == nhandlers) /* Reader is closing. */
return 0; return 0;
else else
{ {
fifo_client_lock (); fifo_client_lock ();
client[i].state = fc_connected; fc_handler[i].state = fc_connected;
nconnected++; nconnected++;
set_pipe_non_blocking (client[i].fh->get_handle (), true); set_pipe_non_blocking (fc_handler[i].fh->get_handle (), true);
fifo_client_unlock (); fifo_client_unlock ();
yield (); yield ();
} }
@ -474,7 +474,7 @@ fhandler_fifo::open (int flags, mode_t)
goto out; goto out;
} }
/* If we're a duplexer, create the pipe and the first client. */ /* If we're a duplexer, create the pipe and the first client handler. */
if (duplexer) if (duplexer)
{ {
HANDLE ph, connect_evt, dummy_evt; HANDLE ph, connect_evt, dummy_evt;
@ -511,9 +511,9 @@ fhandler_fifo::open (int flags, mode_t)
CloseHandle (connect_evt); CloseHandle (connect_evt);
goto out; goto out;
} }
client[0] = fifo_client_handler (fh, fc_connected, connect_evt, fc_handler[0] = fifo_client_handler (fh, fc_connected, connect_evt,
dummy_evt); dummy_evt);
nconnected = nclients = 1; nconnected = nhandlers = 1;
} }
/* If we're reading, start the listen_client thread (which should /* If we're reading, start the listen_client thread (which should
@ -736,11 +736,11 @@ fhandler_fifo::raw_read (void *in_ptr, size_t& len)
/* Poll the connected clients for input. */ /* Poll the connected clients for input. */
fifo_client_lock (); fifo_client_lock ();
for (int i = 0; i < nclients; i++) for (int i = 0; i < nhandlers; i++)
if (client[i].state == fc_connected) if (fc_handler[i].state == fc_connected)
{ {
len = orig_len; len = orig_len;
client[i].fh->fhandler_base::raw_read (in_ptr, len); fc_handler[i].fh->fhandler_base::raw_read (in_ptr, len);
ssize_t nread = (ssize_t) len; ssize_t nread = (ssize_t) len;
if (nread > 0) if (nread > 0)
{ {
@ -749,7 +749,7 @@ fhandler_fifo::raw_read (void *in_ptr, size_t& len)
} }
/* In the duplex case with no data, we seem to get nread /* In the duplex case with no data, we seem to get nread
== -1 with ERROR_PIPE_LISTENING on the first attempt to == -1 with ERROR_PIPE_LISTENING on the first attempt to
read from the duplex pipe (client[0]), and nread == 0 read from the duplex pipe (fc_handler[0]), and nread == 0
on subsequent attempts. */ on subsequent attempts. */
else if (nread < 0) else if (nread < 0)
switch (GetLastError ()) switch (GetLastError ())
@ -767,7 +767,7 @@ fhandler_fifo::raw_read (void *in_ptr, size_t& len)
else if (nread == 0 && (!_duplexer || i > 0)) else if (nread == 0 && (!_duplexer || i > 0))
/* Client has disconnected. */ /* Client has disconnected. */
{ {
client[i].state = fc_invalid; fc_handler[i].state = fc_invalid;
nconnected--; nconnected--;
} }
} }
@ -841,8 +841,8 @@ fhandler_fifo::close ()
CloseHandle (read_ready); CloseHandle (read_ready);
if (write_ready) if (write_ready)
CloseHandle (write_ready); CloseHandle (write_ready);
for (int i = 0; i < nclients; i++) for (int i = 0; i < nhandlers; i++)
if (client[i].close () < 0) if (fc_handler[i].close () < 0)
res = -1; res = -1;
return fhandler_base::close () || res; return fhandler_base::close () || res;
} }
@ -873,19 +873,19 @@ fhandler_fifo::dup (fhandler_base *child, int flags)
__seterrno (); __seterrno ();
return -1; return -1;
} }
for (int i = 0; i < nclients; i++) for (int i = 0; i < nhandlers; i++)
{ {
if (!DuplicateHandle (GetCurrentProcess (), client[i].fh->get_handle (), if (!DuplicateHandle (GetCurrentProcess (), fc_handler[i].fh->get_handle (),
GetCurrentProcess (), GetCurrentProcess (),
&fhf->client[i].fh->get_handle (), &fhf->fc_handler[i].fh->get_handle (),
0, true, DUPLICATE_SAME_ACCESS) 0, true, DUPLICATE_SAME_ACCESS)
|| !DuplicateHandle (GetCurrentProcess (), client[i].connect_evt, || !DuplicateHandle (GetCurrentProcess (), fc_handler[i].connect_evt,
GetCurrentProcess (), GetCurrentProcess (),
&fhf->client[i].connect_evt, &fhf->fc_handler[i].connect_evt,
0, true, DUPLICATE_SAME_ACCESS) 0, true, DUPLICATE_SAME_ACCESS)
|| !DuplicateHandle (GetCurrentProcess (), client[i].dummy_evt, || !DuplicateHandle (GetCurrentProcess (), fc_handler[i].dummy_evt,
GetCurrentProcess (), GetCurrentProcess (),
&fhf->client[i].dummy_evt, &fhf->fc_handler[i].dummy_evt,
0, true, DUPLICATE_SAME_ACCESS)) 0, true, DUPLICATE_SAME_ACCESS))
{ {
CloseHandle (fhf->read_ready); CloseHandle (fhf->read_ready);
@ -907,11 +907,11 @@ fhandler_fifo::fixup_after_fork (HANDLE parent)
fhandler_base::fixup_after_fork (parent); fhandler_base::fixup_after_fork (parent);
fork_fixup (parent, read_ready, "read_ready"); fork_fixup (parent, read_ready, "read_ready");
fork_fixup (parent, write_ready, "write_ready"); fork_fixup (parent, write_ready, "write_ready");
for (int i = 0; i < nclients; i++) for (int i = 0; i < nhandlers; i++)
{ {
client[i].fh->fhandler_base::fixup_after_fork (parent); fc_handler[i].fh->fhandler_base::fixup_after_fork (parent);
fork_fixup (parent, client[i].connect_evt, "connect_evt"); fork_fixup (parent, fc_handler[i].connect_evt, "connect_evt");
fork_fixup (parent, client[i].dummy_evt, "dummy_evt"); fork_fixup (parent, fc_handler[i].dummy_evt, "dummy_evt");
} }
listen_client_thr = NULL; listen_client_thr = NULL;
lct_termination_evt = NULL; lct_termination_evt = NULL;
@ -924,10 +924,10 @@ fhandler_fifo::set_close_on_exec (bool val)
fhandler_base::set_close_on_exec (val); fhandler_base::set_close_on_exec (val);
set_no_inheritance (read_ready, val); set_no_inheritance (read_ready, val);
set_no_inheritance (write_ready, val); set_no_inheritance (write_ready, val);
for (int i = 0; i < nclients; i++) for (int i = 0; i < nhandlers; i++)
{ {
client[i].fh->fhandler_base::set_close_on_exec (val); fc_handler[i].fh->fhandler_base::set_close_on_exec (val);
set_no_inheritance (client[i].connect_evt, val); set_no_inheritance (fc_handler[i].connect_evt, val);
set_no_inheritance (client[i].dummy_evt, val); set_no_inheritance (fc_handler[i].dummy_evt, val);
} }
} }

View File

@ -872,7 +872,7 @@ peek_fifo (select_record *s, bool from_select)
} }
fh->fifo_client_lock (); fh->fifo_client_lock ();
for (int i = 0; i < fh->get_nclients (); i++) for (int i = 0; i < fh->get_nhandlers (); i++)
if (fh->is_connected (i)) if (fh->is_connected (i))
{ {
int n = pipe_data_available (s->fd, fh, fh->get_handle (i), int n = pipe_data_available (s->fd, fh, fh->get_handle (i),