add automatic socket shutdown on errors

This commit is contained in:
Thomas Schoebel-Theuer 2012-01-18 15:31:39 +01:00 committed by Thomas Schoebel-Theuer
parent 2440176bda
commit e7f3ee69ba
5 changed files with 8 additions and 0 deletions

View File

@ -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))) {

View File

@ -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;

View File

@ -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 {

View File

@ -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);

View File

@ -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;