Example #1
0
 public void Start()
 {
     _layerFactory = new OwinHandlerFactory(_parameters.OwinApp, _parameters.OwinCapabilities);
     _ipIsLocalChecker = new IpIsLocalChecker();
     _connectionAllocationStrategy = _parameters.ConnectionAllocationStrategy;
     var isSsl = _parameters.Certificate != null;
     _layerFactory = new Transport2HttpFactory(_parameters.BufferSize, isSsl, _parameters.ServerHeader, _ipIsLocalChecker, _layerFactory);
     if (isSsl)
     {
         _layerFactory = new SslTransportFactory(_parameters, _layerFactory);
     }
     ListenSocket = new Socket(_parameters.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     var start = DateTime.UtcNow;
     while (true)
     {
         try
         {
             ListenSocket.Bind(_parameters.EndPoint);
             break;
         }
         catch when(start + _parameters.RetrySocketBindingTime > DateTime.UtcNow)
         {
         }
         Thread.Sleep(50);
     }
     ListenSocket.Listen(100);
     var initialConnectionCount = _connectionAllocationStrategy.CalculateNewConnectionCount(0, 0);
     AllocatedConnections = initialConnectionCount;
     _blocks.Add(new ConnectionBlock(this, _layerFactory, initialConnectionCount));
 }
Example #2
0
        public void Start()
        {
            _layerFactory                 = new OwinHandlerFactory(_parameters.OwinApp, _parameters.OwinCapabilities);
            _ipIsLocalChecker             = new IpIsLocalChecker();
            _connectionAllocationStrategy = _parameters.ConnectionAllocationStrategy;
            var isSsl = _parameters.Certificate != null;

            _layerFactory = new Transport2HttpFactory(_parameters.BufferSize, isSsl, _parameters.ServerHeader, _ipIsLocalChecker, _layerFactory);
            if (isSsl)
            {
                _layerFactory = new SslTransportFactory(_parameters, _layerFactory);
            }
            ListenSocket = new Socket(_parameters.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            var start = DateTime.UtcNow;

            while (true)
            {
                try
                {
                    ListenSocket.Bind(_parameters.EndPoint);
                    break;
                }
                catch when(start + _parameters.RetrySocketBindingTime > DateTime.UtcNow)
                {
                }
                Thread.Sleep(50);
            }
            ListenSocket.Listen(100);
            var initialConnectionCount = _connectionAllocationStrategy.CalculateNewConnectionCount(0, 0);

            AllocatedConnections = initialConnectionCount;
            _blocks.Add(new ConnectionBlock(this, _layerFactory, initialConnectionCount));
        }
 public Transport2HttpFactory(int receiveBufferSize, bool isSsl, IIpIsLocalChecker ipIsLocalChecker, ILayerFactory next)
 {
     _receiveBufferSize = receiveBufferSize;
     _isSsl = isSsl;
     _ipIsLocalChecker = ipIsLocalChecker;
     _next = next;
     _charBuffer = new ThreadLocal<char[]>(()=>new char[receiveBufferSize]);
     PerConnectionBufferSize = MyPerConnectionBufferSize() + _next.PerConnectionBufferSize;
 }
Example #4
0
 public Transport2HttpFactory(int receiveBufferSize, bool isSsl, string serverName, IIpIsLocalChecker ipIsLocalChecker, ILayerFactory next)
 {
     _receiveBufferSize = receiveBufferSize;
     _isSsl             = isSsl;
     _serverName        = serverName;
     _ipIsLocalChecker  = ipIsLocalChecker;
     _next                   = next;
     _charBuffer             = new ThreadLocal <char[]>(() => new char[receiveBufferSize]);
     PerConnectionBufferSize = MyPerConnectionBufferSize() + _next.PerConnectionBufferSize;
 }
 public Transport2HttpHandler(IHttpLayerHandler next, bool isSsl, IIpIsLocalChecker ipIsLocalChecker, byte[] buffer, int startBufferOffset, int receiveBufferSize, int constantsOffset, ThreadLocal<char[]> charBuffer, int handlerId)
 {
     _next = next;
     StartBufferOffset = startBufferOffset;
     ReceiveBufferSize = receiveBufferSize;
     ResponseBodyBufferOffset = StartBufferOffset + ReceiveBufferSize * 2 + 8;
     _constantsOffset = constantsOffset;
     _charBuffer = charBuffer;
     _handlerId = handlerId;
     _buffer = buffer;
     _isSsl = isSsl;
     _ipIsLocalChecker = ipIsLocalChecker;
     _cancellation = new CancellationTokenSource();
     _reqRespStream = new ReqRespStream(this);
     _next.Callback = this;
 }
Example #6
0
 public Transport2HttpHandler(IHttpLayerHandler next, bool isSsl, string serverName, IDateHeaderValueProvider dateProvider, IIpIsLocalChecker ipIsLocalChecker, byte[] buffer, int startBufferOffset, int receiveBufferSize, int constantsOffset, ThreadLocal <char[]> charBuffer, int handlerId)
 {
     _next                    = next;
     StartBufferOffset        = startBufferOffset;
     ReceiveBufferSize        = receiveBufferSize;
     ResponseBodyBufferOffset = StartBufferOffset + ReceiveBufferSize * 2 + 8;
     _constantsOffset         = constantsOffset;
     _charBuffer              = charBuffer;
     _handlerId               = handlerId;
     _buffer                  = buffer;
     _isSsl                   = isSsl;
     _serverName              = serverName;
     _dateProvider            = dateProvider;
     _ipIsLocalChecker        = ipIsLocalChecker;
     _cancellation            = new CancellationTokenSource();
     _reqRespStream           = new ReqRespStream(this);
     _next.Callback           = this;
 }
Example #7
0
 public void Start()
 {
     _layerFactory = new OwinHandlerFactory(_parameters.OwinApp, _parameters.OwinCapabilities);
     _ipIsLocalChecker = new IpIsLocalChecker();
     _connectionAllocationStrategy = _parameters.ConnectionAllocationStrategy;
     var isSsl = _parameters.Certificate != null;
     _layerFactory = new Transport2HttpFactory(_parameters.BufferSize, isSsl, _ipIsLocalChecker, _layerFactory);
     if (isSsl)
     {
         _layerFactory = new SslTransportFactory(_parameters.Certificate, _layerFactory);
     }
     ListenSocket = new Socket(_parameters.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     ListenSocket.Bind(_parameters.EndPoint);
     ListenSocket.Listen(100);
     var initialConnectionCount = _connectionAllocationStrategy.CalculateNewConnectionCount(0, 0);
     AllocatedConnections = initialConnectionCount;
     _blocks.Add(new ConnectionBlock(this, _layerFactory, initialConnectionCount));
 }