diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-02-04 23:18:54 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-02-06 11:18:37 -0800 |
commit | 9215c35975be745628e8188473154c7e476add55 (patch) | |
tree | 14d4f5d51381f8a59803233c24dfafc846ddf583 /src/common/socket.hpp | |
parent | 9544985ccbb20d7f8377c63a4e59d1ff97b844ac (diff) | |
download | tmwa-9215c35975be745628e8188473154c7e476add55.tar.gz tmwa-9215c35975be745628e8188473154c7e476add55.tar.bz2 tmwa-9215c35975be745628e8188473154c7e476add55.tar.xz tmwa-9215c35975be745628e8188473154c7e476add55.zip |
Wrap remaining FDs in a class
Diffstat (limited to 'src/common/socket.hpp')
-rw-r--r-- | src/common/socket.hpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/common/socket.hpp b/src/common/socket.hpp index 4d51604..6d0ca01 100644 --- a/src/common/socket.hpp +++ b/src/common/socket.hpp @@ -13,6 +13,8 @@ # include "../strings/vstring.hpp" # include "../strings/xstring.hpp" +# include "../io/fd.hpp" + # include "dumb_ptr.hpp" # include "ip.hpp" # include "utils.hpp" @@ -64,13 +66,13 @@ struct Session /// Server-specific data type std::unique_ptr<SessionData, SessionDeleter> session_data; - int fd; + io::FD fd; }; inline int convert_for_printf(Session *s) { - return s->fd; + return s->fd.uncast_dammit(); } // save file descriptors for important stuff @@ -79,12 +81,23 @@ constexpr int SOFT_LIMIT = FD_SETSIZE - 50; // socket timeout to establish a full connection in seconds constexpr int CONNECT_TIMEOUT = 15; -/// Everyone who has connected -// note: call delete_session(i) to null out an element -extern std::array<std::unique_ptr<Session>, FD_SETSIZE> session; -/// Maximum used FD, +1 -extern int fd_max; +void set_session(io::FD fd, std::unique_ptr<Session> sess); +Session *get_session(io::FD fd); +void reset_session(io::FD fd); +int get_fd_max(); + +class IncrFD +{ +public: + static + io::FD inced(io::FD v) + { + return io::FD::cast_dammit(v.uncast_dammit() + 1); + } +}; +IteratorPair<ValueIterator<io::FD, IncrFD>> iter_fds(); + /// open a socket, bind, and listen. Return an fd, or -1 if socket() fails, /// but exit if bind() or listen() fails @@ -101,9 +114,6 @@ void do_sendrecv(interval_t next); /// Call the parser function for every socket that has read data void do_parsepacket(void); -/// An init function -void do_socket(void); - /// Change the default parser for newly connected clients // typically called once per server, but individual clients may identify // themselves as servers |