summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2015-06-23 15:42:33 +0100
committerOlivier Crête <olivier.crete@collabora.com>2016-06-03 18:35:36 -0400
commit11d4bb9783a69363de80ff49638030ba892a93fe (patch)
treeafa5bfb9c793e3a4d67740729716c20908996ace
parenta9a149f529b3165543b52260d40a7855401841da (diff)
downloadlibnice-11d4bb9783a69363de80ff49638030ba892a93fe.tar.gz
pseudotcp: Correct behaviour of buffer size methods when part-closed
Correct the behaviour of pseudo_tcp_socket_get_available_bytes() and pseudo_tcp_get_available_send_space() when the socket is not in TCP_ESTABLISHED state. It’s still permissible to send and receive up until the local side calls pseudo_tcp_socket_close(), which means we may be in state TCP_ESTABLISHED *or TCP_CLOSE_WAIT*.
-rw-r--r--agent/pseudotcp.c5
-rw-r--r--tests/test-pseudotcp-fin.c22
2 files changed, 25 insertions, 2 deletions
diff --git a/agent/pseudotcp.c b/agent/pseudotcp.c
index 6a8d499..e40bbd6 100644
--- a/agent/pseudotcp.c
+++ b/agent/pseudotcp.c
@@ -2465,10 +2465,11 @@ pseudo_tcp_socket_get_available_send_space (PseudoTcpSocket *self)
PseudoTcpSocketPrivate *priv = self->priv;
gsize ret;
- if (!pseudo_tcp_state_has_sent_fin (priv->state))
+ if (!pseudo_tcp_state_has_sent_fin (priv->state)) {
ret = pseudo_tcp_fifo_get_write_remaining (&priv->sbuf);
- else
+ } else {
ret = 0;
+ }
if (ret == 0)
priv->bWriteEnable = TRUE;
diff --git a/tests/test-pseudotcp-fin.c b/tests/test-pseudotcp-fin.c
index 4cc88aa..de5a910 100644
--- a/tests/test-pseudotcp-fin.c
+++ b/tests/test-pseudotcp-fin.c
@@ -1152,6 +1152,13 @@ pseudotcp_close_recv_queued (void)
/* Establish a connection. */
establish_connection (&data);
+ g_assert_cmpint (pseudo_tcp_socket_get_available_bytes (data.left), ==, 0);
+ g_assert_cmpint (pseudo_tcp_socket_get_available_bytes (data.right), ==, 0);
+ g_assert_cmpint (pseudo_tcp_socket_get_available_send_space (data.right), >,
+ 0);
+ g_assert_cmpint (pseudo_tcp_socket_get_available_send_space (data.left), >,
+ 0);
+
g_assert_cmpint (pseudo_tcp_socket_send (data.left, "foo", 3), ==, 3);
expect_data (data.left, data.left_sent, 7, 7, 3);
forward_segment_ltr (&data);
@@ -1164,9 +1171,24 @@ pseudotcp_close_recv_queued (void)
expect_fin (data.left, data.left_sent, 10, 7);
forward_segment_ltr (&data);
+ expect_socket_state (data.left, TCP_FIN_WAIT_1);
+ expect_socket_state (data.right, TCP_CLOSE_WAIT);
+
+ g_assert_cmpint (pseudo_tcp_socket_get_available_bytes (data.left), ==, 0);
+ g_assert_cmpint (pseudo_tcp_socket_get_available_send_space (data.left), ==,
+ 0);
+
expect_ack (data.right, data.right_sent, 7, 11);
forward_segment_rtl (&data);
+ expect_socket_state (data.left, TCP_FIN_WAIT_2);
+
+
+ g_assert_cmpint (pseudo_tcp_socket_get_available_bytes (data.right), ==, 3);
+
+ g_assert_cmpint (pseudo_tcp_socket_get_available_send_space (data.right), >,
+ 0);
+
/* Check that the data can be read */
g_assert_cmpint (pseudo_tcp_socket_recv (data.right, (char *) buf, sizeof (buf)), ==, 3);