Ejemplo n.º 1
0
        public ProtoConnection(ProtoConnectionContext context)
        {
            _context     = context;
            _systemClock = _context.ServiceContext.SystemClock;

            _timeoutControl = new TimeoutControl(this);
        }
Ejemplo n.º 2
0
        public Task OnConnectionAsync(ConnectionContext connectionContext)
        {
            // We need the transport feature so that we can cancel the output reader that the transport is using
            // This is a bit of a hack but it preserves the existing semantics
            var memoryPoolFeature = connectionContext.Features.Get <IMemoryPoolFeature>();

            var httpConnectionContext = new ProtoConnectionContext
            {
                ConnectionId       = connectionContext.ConnectionId,
                ConnectionContext  = connectionContext,
                Protocols          = _protocols,
                ServiceContext     = _serviceContext,
                ConnectionFeatures = connectionContext.Features,
                MemoryPool         = memoryPoolFeature.MemoryPool,
                ConnectionAdapters = _connectionAdapters,
                Transport          = connectionContext.Transport
            };

            var connectionFeature = connectionContext.Features.Get <IProtoConnectionFeature>();

            if (connectionFeature != null)
            {
                if (connectionFeature.LocalIpAddress != null)
                {
                    httpConnectionContext.LocalEndPoint = new IPEndPoint(connectionFeature.LocalIpAddress, connectionFeature.LocalPort);
                }

                if (connectionFeature.RemoteIpAddress != null)
                {
                    httpConnectionContext.RemoteEndPoint = new IPEndPoint(connectionFeature.RemoteIpAddress, connectionFeature.RemotePort);
                }
            }

            var connection = new ProtoConnection(httpConnectionContext);

            return(connection.ProcessRequestsAsync(_application));
        }