aboutsummaryrefslogtreecommitdiff
path: root/tests/nt.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-06-11 12:54:02 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-06-11 13:18:29 +0300
commitbf6506cdc46446eada5090a428c2407ebd17468a (patch)
tree2113b5c049283413fb4fe3981a837989d2969918 /tests/nt.c
parent186b9a1c99988844c5ea3fcce1fcc6cadb491206 (diff)
downloadpies-bf6506cdc46446eada5090a428c2407ebd17468a.tar.gz
pies-bf6506cdc46446eada5090a428c2407ebd17468a.tar.bz2
Improve the nt tool. Test inet running instance limit.
* tests/Makefile.am: Add new test. * tests/aux/in.test (PIESCTL): Provide the necessary options. Discontinue the use of STOPCMD environment variable. New commands: enable, sleep, touch. * tests/testsuite.at (PIES_CONTROL_INIT): Rename pidfile to PIES_PIDFILE and ctlsock to PIES_CTLSOCK. Export both. Include maxinst.at * tests/control.at: Use new variables. * tests/inet.at: Remove the env block. * tests/iobuf.h (iobuf_copy): Return number of bytes copied. * tests/maxinst.at: New file. * tests/nt.c (netcat_stream_disconnect): New function. (netcat_stream_read): Disconnect the peer stream if no more input is available and the peer is not available for output (i.e. its output buffer is empty). (netcat_stream_write): Stop polling if output buffer is empty. (netcat): Fix event mask
Diffstat (limited to 'tests/nt.c')
-rw-r--r--tests/nt.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/tests/nt.c b/tests/nt.c
index 7501586..d30e447 100644
--- a/tests/nt.c
+++ b/tests/nt.c
@@ -109,2 +109,18 @@ net_writer (peer -> stdin_reader) same as stdout_writer
+static inline int
+peer_is_state (netcat_server_t *srv, int state)
+{
+ return srv->peer && (srv->peer->state & state);
+}
+
+static void
+netcat_stream_disconnect (netcat_server_t *srv, int mask)
+{
+ srv->disconnect (srv);
+ srv->state &= ~mask;
+ srv->pollfd->events &= ~mask;
+ if (srv->pollfd->events == 0)
+ srv->pollfd->fd = -1;
+}
+
ssize_t
@@ -113,3 +129,3 @@ netcat_stream_read (netcat_server_t *srv)
ssize_t n;
-
+
if (iobuf_avail_size (&srv->buf[IN]))
@@ -119,2 +135,4 @@ netcat_stream_read (netcat_server_t *srv)
{
+ if (errno == EINTR)
+ return 0;
grecs_error (NULL, errno, "%s: read", srv->id);
@@ -123,11 +141,13 @@ netcat_stream_read (netcat_server_t *srv)
}
- if (n == 0)
+ if (n == 0 || !peer_is_state (srv, POLLOUT))
{
- /* No more input is expected */
- srv->disconnect (srv);
- srv->state &= ~POLLIN;
- srv->pollfd->events &= ~POLLIN;
- if (srv->pollfd->events == 0)
- srv->pollfd->fd = -1;
+ /* No more input is expected || needed */
+ netcat_stream_disconnect (srv, POLLIN);
+
+ if (srv->peer)
+ netcat_stream_disconnect (srv->peer, POLLOUT);
+ return 0;
}
+ else
+ srv->peer->pollfd->events |= POLLOUT;
}
@@ -141,8 +161,2 @@ netcat_stream_read (netcat_server_t *srv)
-static inline int
-peer_is_state (netcat_server_t *srv, int state)
-{
- return srv->peer && (srv->peer->state & state);
-}
-
ssize_t
@@ -157,7 +171,3 @@ netcat_stream_write (netcat_server_t *srv)
// shutdown write end
- srv->disconnect (srv);
- srv->state &= ~POLLOUT;
- srv->pollfd->events &= ~POLLOUT;
- if (srv->pollfd->events == 0)
- srv->pollfd->fd = -1;
+ netcat_stream_disconnect (srv, POLLOUT);
return -1;
@@ -167,2 +177,3 @@ netcat_stream_write (netcat_server_t *srv)
srv->peer->pollfd->events |= POLLIN;
+ srv->pollfd->events &= ~POLLOUT;
return 0;
@@ -173,2 +184,4 @@ netcat_stream_write (netcat_server_t *srv)
{
+ if (errno == EINTR)
+ return 0;
grecs_error (NULL, errno, "%s: write", srv->id);
@@ -255,5 +268,6 @@ netcat (char const *urlstr)
int events;
-
+
events = (srv->pollfd->events|POLLHUP)
- & (srv->pollfd->revents & (srv->state|POLLHUP));
+ & (srv->pollfd->revents
+ & (srv->state | ((srv->state & POLLOUT) ? POLLHUP : 0)));
if (events)
@@ -263,7 +277,3 @@ netcat (char const *urlstr)
//grecs_error (NULL, 0, "HUP on %s", srv->id);
- srv->disconnect (srv);
- srv->pollfd->events &= ~srv->state;
- if (srv->pollfd->events == 0)
- srv->pollfd->fd = -1;
- srv->state = 0;
+ netcat_stream_disconnect (srv, srv->state);
}

Return to:

Send suggestions and report system problems to the System administrator.