diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-03-14 19:25:35 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-03-15 11:47:05 -0700 |
commit | 3c4f4f003d9fdbf759e42ced4fece8dd6a506298 (patch) | |
tree | a7cc1d07995a6330c22345935968da40baae6ba9 /src/common/socket.cpp | |
parent | f2757bbfd049777f6fa9089bd33e38f80290c039 (diff) | |
download | tmwa-3c4f4f003d9fdbf759e42ced4fece8dd6a506298.tar.gz tmwa-3c4f4f003d9fdbf759e42ced4fece8dd6a506298.tar.bz2 tmwa-3c4f4f003d9fdbf759e42ced4fece8dd6a506298.tar.xz tmwa-3c4f4f003d9fdbf759e42ced4fece8dd6a506298.zip |
Fix session death and shutdown when bored
Diffstat (limited to 'src/common/socket.cpp')
-rw-r--r-- | src/common/socket.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/common/socket.cpp b/src/common/socket.cpp index b5f6379..73e32a4 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -13,7 +13,8 @@ #include <ctime> #include "../io/cxxstdio.hpp" -//#include "mmo.hpp" +#include "core.hpp" +#include "timer.hpp" #include "utils.hpp" #include "../poison.hpp" @@ -377,12 +378,26 @@ void WFIFOSET(Session *s, size_t len) void do_sendrecv(interval_t next_ms) { + bool any = false; io::FD_Set rfd = readfds, wfd; for (io::FD i : iter_fds()) { Session *s = get_session(i); - if (s && s->wdata_size) - wfd.set(i); + if (s) + { + any = true; + if (s->wdata_size) + wfd.set(i); + } + } + if (!any) + { + if (!has_timers()) + { + PRINTF("Shutting down - nothing to do\n"); + runflag = false; + } + return; } struct timeval timeout; { @@ -433,6 +448,12 @@ void do_parsepacket(void) { s->func_parse(s); /// some func_parse may call delete_session + s = get_session(i); + if (s && s->eof) + { + delete_session(s); + s = nullptr; + } if (!s) continue; } |