X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=acceptor.h;h=969ea65889419a38efd6683072be36bf60e9dc35;hp=97672338a133b0006b9203a8e33903057dd0aa33;hb=f2e7dbf218365e3f47b942ea999796b2724ccc24;hpb=e1722a5c0341fd541ce57f1eed4dc76cbd3efe07 diff --git a/acceptor.h b/acceptor.h index 9767233..969ea65 100644 --- a/acceptor.h +++ b/acceptor.h @@ -1,20 +1,54 @@ #ifndef _ACCEPTOR_H #define _ACCEPTOR_H +#include + +#include + #include "thread.h" -int create_server_socket(int port); +enum SocketType { + TCP_SOCKET, + UDP_SOCKET, +}; +int create_server_socket(const sockaddr_in6 &addr, SocketType socket_type); + +class AcceptorProto; + +sockaddr_in6 create_any_address(int port); +sockaddr_in6 extract_address_from_acceptor_proto(const AcceptorProto &proto); // A thread that accepts new connections on a given socket, // and hands them off to the server pool. -class AcceptorThread : public Thread { +class Acceptor : public Thread { public: - AcceptorThread(int server_sock); + Acceptor(int server_sock, const sockaddr_in6 &addr, + const std::string &certificate_chain, const std::string &private_key); + + // Serialization/deserialization. + Acceptor(const AcceptorProto &serialized); + AcceptorProto serialize() const; + + bool is_tls() const { return !certificate_chain.empty(); } + + std::string get_certificate_chain() const { + assert(is_tls()); + return certificate_chain; + } + + std::string get_private_key() const { + assert(is_tls()); + return private_key; + } + + void close_socket(); private: virtual void do_work(); int server_sock; + sockaddr_in6 addr; + std::string certificate_chain, private_key; // Both empty for no TLS. }; #endif // !defined(_ACCEPTOR_H)