mirror of https://github.com/schoebel/mars
add automatic socket shutdown on errors
This commit is contained in:
parent
2440176bda
commit
e7f3ee69ba
|
@ -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))) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue