void TCPSocket::listen(int backlog) { if (this->_state != CREATED) { throw SocketStateException("Wrong state for operation"); } if (::listen(this->_b->_sock, backlog) == -1) { throw ListenException(errno); } this->_state = LISTENING; }
Server::Server(uint32_t port) { _terminated = false; sockfd = socket(PF_INET, SOCK_STREAM, 0); if (sockfd == -1) throw SocketException(); server.sin_family = AF_INET; // host byte order server.sin_port = htons(port); // short, network byte order server.sin_addr.s_addr = htonl(INADDR_ANY); // fill in the IP address of the machine memset(&(server.sin_zero), '\0', 8); // zero the rest of the struct if (bind(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr)) < 0) throw BindException(); if (listen(sockfd, backlog) < 0) throw ListenException(); }
void StreamServerSocket::listen( int backlog ) { int rc = ::listen( m_fd, backlog ); if ( rc ) { throw ListenException("Error on listen", rc); } }