socket: set fd field to -1 after closing socket

This ensures that g_socket_get_fd() will return -1 after the socket has
been closed.

https://bugzilla.gnome.org/show_bug.cgi?id=765959
This commit is contained in:
Christian Hergert 2016-05-04 10:40:50 +03:00
parent 0cd3d5741b
commit c16a0b53fe
2 changed files with 5 additions and 0 deletions

View File

@ -3285,6 +3285,7 @@ g_socket_close (GSocket *socket,
break; break;
} }
socket->priv->fd = -1;
socket->priv->connected_read = FALSE; socket->priv->connected_read = FALSE;
socket->priv->connected_write = FALSE; socket->priv->connected_write = FALSE;
socket->priv->closed = TRUE; socket->priv->closed = TRUE;

View File

@ -1197,6 +1197,10 @@ test_fd_reuse (void)
g_socket_close (data->server, &error); g_socket_close (data->server, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpint (g_socket_get_fd (client), ==, -1);
g_assert_cmpint (g_socket_get_fd (client2), ==, -1);
g_assert_cmpint (g_socket_get_fd (data->server), ==, -1);
g_object_unref (data->server); g_object_unref (data->server);
g_object_unref (client); g_object_unref (client);
g_object_unref (client2); g_object_unref (client2);