#include "session/session.h" #include "socket/tcp_socket.h" #include "socket/udp_socket.h" #include "utils/thread_pool.h" namespace Network { Session::Session(gsl::not_null iocp, utils::ThreadPool* tp, SessionType type, SessionProtocol proto, Network::Address addr) : iocp_(iocp), tp_(tp), proto_(proto) { switch (proto) { case SessionProtocol::UDP: case SessionProtocol::QUIC: case SessionProtocol::TCP: case SessionProtocol::TLS: { Network::TCPSocket* sock = new Network::TCPSocket(addr.family); sock_ = sock; switch (type) { case SessionType::CONNECT: sock->connect(addr); break; case SessionType::LISTEN: sock->bind(addr); sock->listen(SOMAXCONN); break; default: std::exit(EXIT_FAILURE); } } break; default: std::exit(EXIT_FAILURE); } } Session::~Session() { if (sock_ != nullptr) delete sock_; } } // namespace Network