Files
Np_Term/impl/session/session.cpp
2025-06-15 23:21:54 +09:00

42 lines
1.0 KiB
C++

#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<Network::IOCP*> 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();
sock_ = sock;
sock->init(addr.family);
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