Пример #1
0
        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));
        }
Пример #2
0
 public virtual void Close()
 {
     if (_acceptFd != null)
     {
         Network.CloseSocketNoThrow(_acceptFd);
     }
     if (_fd != null)
     {
         Network.CloseSocketNoThrow(_fd);
     }
 }