Skip to content
Snippets Groups Projects
Commit ebc5a705 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

net server: catch more issues; set timeout on connection, not on socket

parent 70adf557
No related branches found
No related tags found
No related merge requests found
...@@ -164,23 +164,49 @@ static void do_send(gpointer data, gpointer user_data) ...@@ -164,23 +164,49 @@ static void do_send(gpointer data, gpointer user_data)
GIOStream *stream; GIOStream *stream;
GOutputStream *ostream; GOutputStream *ostream;
GSocket *socket;
GError *error = NULL; GError *error = NULL;
gboolean ret; gboolean ret;
g_mutex_lock(&c->lock); g_mutex_lock(&c->lock);
if (!G_IS_IO_STREAM(c->con)) if (!G_IS_IO_STREAM(c->con)) {
c->kick = TRUE;
goto bye;
}
socket = g_socket_connection_get_socket(c->con);
if (!G_IS_SOCKET(socket)) {
c->kick = TRUE;
goto bye; goto bye;
}
g_socket_set_timeout(g_socket_connection_get_socket(c->con), 10); g_socket_set_timeout(socket, 10);
stream = G_IO_STREAM(c->con); stream = G_IO_STREAM(c->con);
if (!G_IS_IO_STREAM(stream)) {
c->kick = TRUE;
goto bye;
}
ostream = g_io_stream_get_output_stream(stream); ostream = g_io_stream_get_output_stream(stream);
if (!G_IS_OUTPUT_STREAM(ostream)) {
c->kick = TRUE;
goto bye;
}
ret = g_output_stream_write_all(ostream, th->buf, th->bytes, NULL, NULL, &error); ret = g_output_stream_write_all(ostream, th->buf, th->bytes, NULL, NULL, &error);
g_socket_set_timeout(g_socket_connection_get_socket(c->con), 0); if (!G_IS_SOCKET(socket)) {
c->kick = TRUE;
goto bye;
}
if (!ret) { if (!ret) {
if (error) { if (error) {
...@@ -192,6 +218,7 @@ static void do_send(gpointer data, gpointer user_data) ...@@ -192,6 +218,7 @@ static void do_send(gpointer data, gpointer user_data)
} }
bye: bye:
g_socket_set_timeout(socket, 0);
g_mutex_unlock(&c->lock); g_mutex_unlock(&c->lock);
g_free(th->buf); g_free(th->buf);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment