internal TcpTransceiver(Communicator communicator, Socket fd) { _communicator = communicator; Socket = fd; try { Network.SetBufSize(Socket, _communicator, Transport.TCP); _desc = Network.SocketToString(Socket); } catch (Exception) { Socket.CloseNoThrow(); throw; } }
internal TcpTransceiver(Communicator communicator, EndPoint addr, INetworkProxy?proxy, IPAddress?sourceAddr) { _communicator = communicator; _proxy = proxy; _addr = addr; _desc = ""; _sourceAddr = sourceAddr; Socket = Network.CreateSocket(false, (_proxy != null ? _proxy.Address : _addr).AddressFamily); try { Network.SetBufSize(Socket, _communicator, Transport.TCP); } catch (Exception) { Socket.CloseNoThrow(); throw; } }
// Only for use by UdpConnector. internal UdpSocket( Communicator communicator, IConnector connector, EndPoint addr, IPAddress?sourceAddr, string?multicastInterface, int multicastTtl) { _communicator = communicator; _connector = connector; _addr = (IPEndPoint)addr; _multicastInterface = multicastInterface; _incoming = false; if (sourceAddr != null) { _sourceAddr = new IPEndPoint(sourceAddr, 0); } Socket = Network.CreateSocket(true, _addr.AddressFamily, _connector); try { Network.SetBufSize(Socket, _communicator, Transport.UDP); _rcvSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer) !; _sndSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer) !; if (Network.IsMulticast(_addr)) { if (_multicastInterface != null) { Debug.Assert(_multicastInterface.Length > 0); Network.SetMulticastInterface(Socket, _multicastInterface, _addr.AddressFamily); } if (multicastTtl != -1) { Network.SetMulticastTtl(Socket, multicastTtl, _addr.AddressFamily); } } } catch (SocketException ex) { Socket.CloseNoThrow(); throw new TransportException(ex, RetryPolicy.NoRetry, _connector); } }
// Only for use by UdpEndpoint. internal UdpTransceiver(UdpEndpoint endpoint, Communicator communicator) { _communicator = communicator; _addr = Network.GetAddressForServerEndpoint(endpoint.Host, endpoint.Port, Network.EnableBoth); _multicastInterface = endpoint.MulticastInterface; _incoming = true; Socket = Network.CreateServerSocket(endpoint, _addr.AddressFamily); try { Network.SetBufSize(Socket, _communicator, Transport.UDP); _rcvSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer) !; _sndSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer) !; } catch (SocketException ex) { Socket.CloseNoThrow(); throw new TransportException(ex); } }
// Only for use by UdpEndpoint. internal UdpSocket(UdpEndpoint endpoint, Communicator communicator) { Debug.Assert(endpoint.Address != IPAddress.None); // not a DNS name _communicator = communicator; _addr = new IPEndPoint(endpoint.Address, endpoint.Port); _multicastInterface = endpoint.MulticastInterface; _incoming = true; Socket = Network.CreateServerSocket(endpoint, _addr.AddressFamily); try { Network.SetBufSize(Socket, _communicator, Transport.UDP); _rcvSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer) !; _sndSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer) !; } catch (SocketException ex) { Socket.CloseNoThrow(); throw new TransportException(ex, RetryPolicy.NoRetry); } }
// Only for use by UdpEndpoint. internal UdpTransceiver( Communicator communicator, string host, ushort port, string multicastInterface) { _communicator = communicator; _addr = Network.GetAddressForServerEndpoint(host, port, communicator.IPVersion, communicator.PreferIPv6); _multicastInterface = multicastInterface; _incoming = true; Socket = Network.CreateServerSocket(true, _addr.AddressFamily, communicator.IPVersion); try { Network.SetBufSize(Socket, _communicator, Transport.UDP); _rcvSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer) !; _sndSize = (int)Socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer) !; } catch (SocketException ex) { Socket.CloseNoThrow(); throw new TransportException(ex); } }