diff --git a/mars_net.c b/mars_net.c index e06d44bd..c2d3ee93 100644 --- a/mars_net.c +++ b/mars_net.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "mars.h" #include "mars_net.h" @@ -205,7 +206,7 @@ int mars_accept_socket(struct mars_socket *new_msock, struct mars_socket *old_ms ok = mars_get_socket(old_msock); if (likely(ok)) { - status = kernel_accept(old_msock->s_socket, &new_socket, 0); + status = kernel_accept(old_msock->s_socket, &new_socket, O_NONBLOCK); if (unlikely(status < 0)) { goto err; } @@ -416,8 +417,14 @@ int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen) if (status == -EAGAIN) { msleep(sleeptime); // linearly increasing backoff - if (sleeptime < 100) + if (sleeptime < 100) { sleeptime += 1000 / HZ; + } else if (kthread_should_stop()) { + MARS_WRN("interrupting, done = %d\n", done); + if (done > 0) + status = -EIDRM; + goto err; + } continue; } if (!status) { // EOF diff --git a/mars_server.c b/mars_server.c index 97749a6a..f1cbe8f9 100644 --- a/mars_server.c +++ b/mars_server.c @@ -603,7 +603,7 @@ static int _server_thread(void *data) /* TODO: check authorization. */ - if (!mars_global || !mars_global->global_power.button) { + if (!mars_global || !mars_global->global_power.button || kthread_should_stop()) { MARS_WRN("system is not alive\n"); goto err; } @@ -626,12 +626,23 @@ static int _server_thread(void *data) if (status < 0) { BRICK_ERR("kill status = %d, giving up\n", status); } + brick = NULL; } msleep(3000); } MARS_INF("-------- cleaning up ----------\n"); + if (brick) { + //FIXME: this hangs up. Leaving a minor memleak for now. + //mars_put_socket(&brick->handler_socket); + //status = mars_kill_brick((void*)brick); + //if(status < 0) { + //BRICK_WRN("kill status = %d, giving up\n", status); + //} + brick = NULL; + } + spin_lock(&server_lock); while (!list_empty(&server_list)) { struct list_head *tmp = server_list.next;