Failed attempt at fixing disable debugger when 1+ sessions are open

This commit is contained in:
TuxSH 2019-06-14 00:40:41 +02:00
parent 648541bb1f
commit 84c5cf0661
4 changed files with 31 additions and 11 deletions

View File

@ -73,4 +73,5 @@ typedef struct sock_server
Result server_init(struct sock_server *serv);
void server_bind(struct sock_server *serv, u16 port);
void server_run(struct sock_server *serv);
void server_kill_connections(struct sock_server *serv);
void server_finalize(struct sock_server *serv);

View File

@ -148,6 +148,7 @@ void DebuggerMenu_DisableDebugger(void)
if(initialized)
{
svcSignalEvent(gdbServer.super.shall_terminate_event);
server_kill_connections(&gdbServer.super);
res = MyThread_Join(&debuggerDebugThread, 5 * 1000 * 1000 * 1000LL);
if(res == 0)
res = MyThread_Join(&debuggerSocketThread, 5 * 1000 * 1000 * 1000LL);

View File

@ -396,11 +396,6 @@ int socPoll(struct pollfd *fds, nfds_t nfds, int timeout)
if(ret == 0)
ret = _net_convert_error(cmdbuf[2]);
if(ret < 0) {
//errno = -ret;
return -1;
}
return ret;
}

View File

@ -148,13 +148,14 @@ void server_run(struct sock_server *serv)
{
struct pollfd *fds = serv->poll_fds;
Handle handles[2] = { terminationRequestEvent, serv->shall_terminate_event };
s32 idx = -1;
serv->running = true;
svcSignalEvent(serv->started_event);
while(serv->running && !terminationRequest)
{
s32 idx = -1;
idx = -1;
if(svcWaitSynchronizationN(&idx, handles, 2, false, 0LL) == 0)
goto abort_connections;
@ -170,11 +171,15 @@ void server_run(struct sock_server *serv)
fds[i].revents = 0;
int pollres = socPoll(fds, serv->nfds, 50);
idx = -1;
if(svcWaitSynchronizationN(&idx, handles, 2, false, 0LL) == 0)
goto abort_connections;
for(nfds_t i = 0; pollres > 0 && i < serv->nfds; i++)
{
struct sock_ctx *curr_ctx = serv->ctx_ptrs[i];
if((fds[i].revents & POLLHUP) || curr_ctx->should_close)
if((fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) || curr_ctx->should_close)
server_close_ctx(serv, curr_ctx);
else if(fds[i].revents & POLLIN)
@ -228,6 +233,10 @@ void server_run(struct sock_server *serv)
}
}
idx = -1;
if(svcWaitSynchronizationN(&idx, handles, 2, false, 0LL) == 0)
goto abort_connections;
if(serv->compact_needed)
compact(serv);
}
@ -244,18 +253,32 @@ void server_run(struct sock_server *serv)
return;
abort_connections:
for(unsigned int i = 0; i < serv->nfds; i++)
server_kill_connections(serv);
serv->running = false;
svcClearEvent(serv->started_event);
}
void server_kill_connections(struct sock_server *serv)
{
struct pollfd *fds = serv->poll_fds;
nfds_t nfds = serv->nfds;
for(unsigned int i = 0; i < nfds; i++)
{
if(fds[i].fd == -1)
continue;
struct linger linger;
linger.l_onoff = 1;
linger.l_linger = 0;
socSetsockopt(fds[i].fd, SOL_SOCKET, SO_LINGER, &linger, sizeof(struct linger));
socClose(fds[i].fd);
}
fds[i].fd = -1;
serv->running = false;
svcClearEvent(serv->started_event);
serv->ctx_ptrs[i]->should_close = true;
}
}
void server_finalize(struct sock_server *serv)