コード例 #1
0
ファイル: ServerSocket.cpp プロジェクト: deniskin82/x0
bool ServerSocket::open(const SocketSpec& spec, int flags)
{
	if (spec.backlog() > 0)
		setBacklog(spec.backlog());

	if (spec.isLocal())
		return open(spec.local(), flags);
	else
		return open(spec.ipaddr().str(), spec.port(), flags);
}
コード例 #2
0
	void ListenSock::init( const Address& addr )
	{
		// Create socket
		createSocket(SOCK_STREAM, IPPROTO_TCP);
		setBacklog(-1);

		// Bind socket to port
		if ( ::bind( _socket, (const sockaddr *)addr.sockAddr(), sizeof(sockaddr_in) ) != 0 )
		{
			throw ESocket( "Unable to bind listen socket to port" );
		}
		_LocalAddr = addr;
		_Bound = true;

		// Listen
		if ( ::listen( _socket, _BackLog ) != 0 ) // SOMAXCONN = maximum length of the queue of pending connections
		{
			throw ESocket( "Unable to listen on specified port" );
		}
	}