private void disposeTimer()
        {
            if (_timer == null)
            {
                return;
            }

            try
            {
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
            }
            catch
            {
            }

            _timer.Dispose();
            _timer = null;
        }
Пример #2
0
        protected static T Read <T> (Stream stream, Func <string[], T> parser, int millisecondsTimeout)
            where T : HttpBase
        {
            var timeout = false;
            var timer   = new Timer(
                state =>
            {
                timeout = true;
                stream.Close();
            },
                null,
                millisecondsTimeout,
                -1);

            T         http      = null;
            Exception exception = null;

            try
            {
                http = parser(readHeaders(stream, _headersMaxLength));
                var contentLen = http.Headers["Content-Length"];
                if (contentLen != null && contentLen.Length > 0)
                {
                    http.EntityBodyData = readEntityBody(stream, contentLen);
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                timer.Change(-1, -1);
                timer.Dispose();
            }

            var msg = timeout
                                          ? "A timeout has occurred while reading an HTTP request/response."
                                          : exception != null
                                                ? "An exception has occurred while reading an HTTP request/response."
#if SSHARP
                      + String.Format(" [{0}]", exception.Message)
#endif
                                                : null;

            if (msg != null)
            {
                throw new WebSocketException(msg, exception);
            }

            return(http);
        }
 public void BeginReadRequest()
 {
     if (buffer == null)
     {
         buffer = new byte[BufferSize];
     }
     try
     {
         if (reuses == 1)
         {
             s_timeout = 15000;
         }
         timer.Change(s_timeout, Timeout.Infinite);
         stream.BeginRead(buffer, 0, BufferSize, onread_cb, this);
     }
     catch
     {
         timer.Change(Timeout.Infinite, Timeout.Infinite);
         CloseSocket();
         Unbind();
     }
 }
Пример #4
0
        internal void Start()
        {
            lock (_sync)
            {
#if NETCF
                if (_clean)
                {
                    _sweepTimer.Change(_sweepInterval, _sweepInterval);
                }
                else
                {
                    _sweepTimer.Stop();
                }
#else
                _sweepTimer.Enabled = _clean;
#endif
                _state = ServerState.Start;
            }
        }