public StreamSocket(TransportInstance instance, Socket fd) { _instance = instance; _fd = fd; _state = StateConnected; try { _desc = Network.FdToString(_fd); } catch (Exception) { Network.CloseSocketNoThrow(_fd); throw; } Network.SetBlock(_fd, false); Network.SetTcpBufSize(_fd, _instance); _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); // // For timeouts to work properly, we need to receive/send // the data in several chunks. Otherwise, we would only be // notified when all the data is received/written. The // connection timeout could easily be triggered when // receiving/sending large messages. // _maxSendPacketSize = Math.Max(512, Network.GetSendBufferSize(_fd)); _maxRecvPacketSize = Math.Max(512, Network.GetRecvBufferSize(_fd)); }
public StreamSocket(TransportInstance instance, INetworkProxy?proxy, EndPoint addr, IPAddress?sourceAddr) { _instance = instance; _proxy = proxy; _addr = addr; _sourceAddr = sourceAddr; _fd = Network.CreateSocket(false, (_proxy != null ? _proxy.GetAddress() : _addr).AddressFamily); _state = StateNeedConnect; Network.SetBlock(_fd, false); Network.SetTcpBufSize(_fd, _instance); _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); // // For timeouts to work properly, we need to receive/send // the data in several chunks. Otherwise, we would only be // notified when all the data is received/written. The // connection timeout could easily be triggered when // receiving/sending large messages. // _maxSendPacketSize = Math.Max(512, Network.GetSendBufferSize(_fd)); _maxRecvPacketSize = Math.Max(512, Network.GetRecvBufferSize(_fd)); }
// // Only for use by UdpConnector. // internal UdpTransceiver(TransportInstance instance, EndPoint addr, IPAddress?sourceAddr, string mcastInterface, int mcastTtl) { _instance = instance; _addr = addr; if (sourceAddr != null) { _sourceAddr = new IPEndPoint(sourceAddr, 0); } _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.RemoteEndPoint = _addr; _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.RemoteEndPoint = _addr; _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); _mcastInterface = mcastInterface; _state = StateNeedConnect; _incoming = false; try { _fd = Network.CreateSocket(true, _addr.AddressFamily); SetBufSize(-1, -1); Network.SetBlock(_fd, false); if (Network.IsMulticast((IPEndPoint)_addr)) { if (_mcastInterface.Length > 0) { Network.SetMcastInterface(_fd, _mcastInterface, _addr.AddressFamily); } if (mcastTtl != -1) { Network.SetMcastTtl(_fd, mcastTtl, _addr.AddressFamily); } } } catch (System.Exception) { _fd = null; throw; } }
internal TcpAcceptor(TcpEndpoint endpoint, TransportInstance instance, string host, int port) { _endpoint = endpoint; _instance = instance; _backlog = instance.Communicator.GetPropertyAsInt("Ice.TCP.Backlog") ?? 511; try { int ipVersion = _instance.IPVersion; _addr = (IPEndPoint)Network.GetAddressForServer(host, port, ipVersion, _instance.PreferIPv6); _fd = Network.CreateServerSocket(false, _addr.AddressFamily, ipVersion); Network.SetBlock(_fd, false); Network.SetTcpBufSize(_fd, _instance); } catch (Exception) { _fd = null; throw; } }
// // Only for use by UdpEndpoint. // internal UdpTransceiver(UdpEndpoint endpoint, TransportInstance instance, string host, int port, string mcastInterface, bool connect) { _endpoint = endpoint; _instance = instance; _state = connect ? StateNeedConnect : StateNotConnected; _mcastInterface = mcastInterface; _incoming = true; _port = port; try { _addr = Network.GetAddressForServer(host, port, instance.IPVersion, instance.PreferIPv6); _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.RemoteEndPoint = _addr; _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.RemoteEndPoint = _addr; _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IoCompleted); _fd = Network.CreateServerSocket(true, _addr.AddressFamily, instance.IPVersion); SetBufSize(-1, -1); Network.SetBlock(_fd, false); } catch (Ice.LocalException) { if (_readEventArgs != null) { _readEventArgs.Dispose(); } if (_writeEventArgs != null) { _writeEventArgs.Dispose(); } _fd = null; throw; } }
public void SetBlock(bool block) { Debug.Assert(_fd != null); Network.SetBlock(_fd, block); }