public RioTcpClientPool(RioFixedBufferPool sendPool, RioFixedBufferPool revicePool, uint socketCount, uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024) : base(sendPool, revicePool, socketCount, maxOutstandingReceive, maxOutstandingSend, (maxOutstandingReceive + maxOutstandingSend) * socketCount) { foreach (var s in allSockets) { _freeSockets.Enqueue(s); in_addr inAddress = new in_addr(); inAddress.s_b1 = 0; inAddress.s_b2 = 0; inAddress.s_b3 = 0; inAddress.s_b4 = 0; sockaddr_in sa = new sockaddr_in(); sa.sin_family = ADDRESS_FAMILIES.AF_INET; sa.sin_port = 0; //Imports.ThrowLastWSAError(); sa.sin_addr = inAddress; unsafe { if (WinSock.bind(s.Socket, ref sa, sizeof(sockaddr_in)) == WinSock.SOCKET_ERROR) { WinSock.ThrowLastWSAError(); } } } }
public void Listen(IPEndPoint localEP, int backlog) { in_addr inAddress = new in_addr(); inAddress.s_b1 = localEP.Address.GetAddressBytes()[0]; inAddress.s_b2 = localEP.Address.GetAddressBytes()[1]; inAddress.s_b3 = localEP.Address.GetAddressBytes()[2]; inAddress.s_b4 = localEP.Address.GetAddressBytes()[3]; sockaddr_in sa = new sockaddr_in(); sa.sin_family = ADDRESS_FAMILIES.AF_INET; sa.sin_port = WinSock.htons((ushort)localEP.Port); //Imports.ThrowLastWSAError(); sa.sin_addr = inAddress; unsafe { if (WinSock.bind(_listenerSocket, ref sa, sizeof(sockaddr_in)) == WinSock.SOCKET_ERROR) { WinSock.ThrowLastWSAError(); } } if (WinSock.listen(_listenerSocket, backlog) == WinSock.SOCKET_ERROR) { WinSock.ThrowLastWSAError(); } foreach (var s in allSockets) { BeginAccept(s); } }