Commit 11d4bb97 authored by Philip Withnall's avatar Philip Withnall Committed by Olivier Crête

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*.
parent a9a149f5
...@@ -2465,10 +2465,11 @@ pseudo_tcp_socket_get_available_send_space (PseudoTcpSocket *self) ...@@ -2465,10 +2465,11 @@ pseudo_tcp_socket_get_available_send_space (PseudoTcpSocket *self)
PseudoTcpSocketPrivate *priv = self->priv; PseudoTcpSocketPrivate *priv = self->priv;
gsize ret; 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); ret = pseudo_tcp_fifo_get_write_remaining (&priv->sbuf);
else } else {
ret = 0; ret = 0;
}
if (ret == 0) if (ret == 0)
priv->bWriteEnable = TRUE; priv->bWriteEnable = TRUE;
......
...@@ -1152,6 +1152,13 @@ pseudotcp_close_recv_queued (void) ...@@ -1152,6 +1152,13 @@ pseudotcp_close_recv_queued (void)
/* Establish a connection. */ /* Establish a connection. */
establish_connection (&data); 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); g_assert_cmpint (pseudo_tcp_socket_send (data.left, "foo", 3), ==, 3);
expect_data (data.left, data.left_sent, 7, 7, 3); expect_data (data.left, data.left_sent, 7, 7, 3);
forward_segment_ltr (&data); forward_segment_ltr (&data);
...@@ -1164,9 +1171,24 @@ pseudotcp_close_recv_queued (void) ...@@ -1164,9 +1171,24 @@ pseudotcp_close_recv_queued (void)
expect_fin (data.left, data.left_sent, 10, 7); expect_fin (data.left, data.left_sent, 10, 7);
forward_segment_ltr (&data); 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); expect_ack (data.right, data.right_sent, 7, 11);
forward_segment_rtl (&data); 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 */ /* Check that the data can be read */
g_assert_cmpint (pseudo_tcp_socket_recv (data.right, (char *) buf, sizeof (buf)), ==, 3); g_assert_cmpint (pseudo_tcp_socket_recv (data.right, (char *) buf, sizeof (buf)), ==, 3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment