From e7f3ee69ba629b608233d3a80abd3e5c84dcd7cc Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Wed, 18 Jan 2012 15:31:39 +0100 Subject: [PATCH] add automatic socket shutdown on errors --- mars_client.c | 1 + mars_net.c | 4 ++++ mars_net.h | 1 + mars_server.c | 1 + sy_old/mars_light.c | 1 + 5 files changed, 8 insertions(+) diff --git a/mars_client.c b/mars_client.c index b0b5c685..05f7ff19 100644 --- a/mars_client.c +++ b/mars_client.c @@ -93,6 +93,7 @@ static int _connect(struct client_output *output, const char *str) MARS_DBG("no socket, status = %d\n", status); goto really_done; } + output->socket.s_shutdown_on_err = true; output->receiver.thread = kthread_create(receiver_thread, output, "mars_receiver%d", thread_count++); if (unlikely(IS_ERR(output->receiver.thread))) { diff --git a/mars_net.c b/mars_net.c index 6af7e6cf..8e6b7c29 100644 --- a/mars_net.c +++ b/mars_net.c @@ -345,6 +345,8 @@ int mars_send_raw(struct mars_socket *msock, void *buf, int len, bool cork) MARS_IO("#%d sent %d\n", msock->s_debug_nr, sent); done: + if (status < 0 && msock->s_shutdown_on_err) + mars_shutdown_socket(msock); mars_put_socket(msock); final: return status; @@ -410,6 +412,8 @@ int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen) status = done; err: + if (status < 0 && msock->s_shutdown_on_err) + mars_shutdown_socket(msock); mars_put_socket(msock); final: return status; diff --git a/mars_net.h b/mars_net.h index 9d787f1b..c987713b 100644 --- a/mars_net.h +++ b/mars_net.h @@ -19,6 +19,7 @@ struct mars_socket { atomic_t s_count; int s_debug_nr; bool s_dead; + bool s_shutdown_on_err; }; struct mars_tcp_params { diff --git a/mars_server.c b/mars_server.c index 577e20d9..f633ef5c 100644 --- a/mars_server.c +++ b/mars_server.c @@ -596,6 +596,7 @@ static int _server_thread(void *data) msleep(2000); continue; } + brick->handler_socket.s_shutdown_on_err = true; MARS_DBG("got new connection #%d\n", brick->handler_socket.s_debug_nr); diff --git a/sy_old/mars_light.c b/sy_old/mars_light.c index 2844ba6d..45f9d6cd 100644 --- a/sy_old/mars_light.c +++ b/sy_old/mars_light.c @@ -1053,6 +1053,7 @@ int peer_thread(void *data) msleep(5000); continue; } + peer->socket.s_shutdown_on_err = true; MARS_DBG("successfully opened socket to '%s'\n", real_peer); msleep(100); continue;