#ifndef __JNET__JSERVERSOCKET__ #define __JNET__JSERVERSOCKET__ #include #include #include "JLang/JException.hh" #include "JNet/JTCPSocket.hh" /** * \author mdejong */ namespace JNET {} namespace JPP { using namespace JNET; } namespace JNET { using JLANG::JSocketException; using JLANG::JFileDescriptorMask; /** * TCP server socket. */ class JServerSocket : public JTCPSocket { public: /** * Constructor. * * \param port port number * \param backlog backlog */ JServerSocket(const int port, const int backlog) { setReuseAddress(true); setTcpNoDelay (true); setIPnumber(); setPort(port); if (::bind(getFileDescriptor(), getSockaddr(), sizeof(sockaddr)) < 0) { THROW(JSocketException, "Bind socket failed " << errno); } if (::listen(getFileDescriptor(), backlog) < 0) { THROW(JSocketException, "Listen socket failed " << errno); } } }; } #endif