Example #1
0
        public StreamSocket(ProtocolInstance 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
            // receiging/sending large messages.
            //
            _maxSendPacketSize = Math.Max(512, Network.getSendBufferSize(_fd));
            _maxRecvPacketSize = Math.Max(512, Network.getRecvBufferSize(_fd));
        }
Example #2
0
 public virtual void close()
 {
     Debug.Assert(_acceptFd == null);
     if (_fd != null)
     {
         Network.closeSocketNoThrow(_fd);
         _fd = null;
     }
 }
Example #3
0
 public virtual void close()
 {
     if (_acceptFd != null)
     {
         Network.closeSocketNoThrow(_acceptFd);
         _acceptFd = null;
     }
     if (_fd != null)
     {
         Network.closeSocketNoThrow(_fd);
         _fd = null;
     }
 }
Example #4
0
 public StreamSocket(ProtocolInstance instance, Socket fd)
 {
     _instance = instance;
     _fd       = fd;
     _state    = StateConnected;
     try
     {
         _desc = Network.fdToString(_fd);
     }
     catch (Exception)
     {
         Network.closeSocketNoThrow(_fd);
         throw;
     }
     init();
 }