コード例 #1
0
        void IConnectionControl.End(ProduceEndType endType)
        {
            lock (_stateLock)
            {
                switch (endType)
                {
                case ProduceEndType.ConnectionKeepAlive:
                    if (_connectionState != ConnectionState.Open)
                    {
                        return;
                    }

                    Log.ConnectionKeepAlive(ConnectionId);
                    break;

                case ProduceEndType.SocketShutdown:
                case ProduceEndType.SocketDisconnect:
                    if (_connectionState == ConnectionState.Disconnecting ||
                        _connectionState == ConnectionState.SocketClosed)
                    {
                        return;
                    }
                    _connectionState = ConnectionState.Disconnecting;

                    Log.ConnectionDisconnect(ConnectionId);
                    _rawSocketOutput.End(endType);
                    break;
                }
            }
        }
コード例 #2
0
        void IConnectionControl.End(ProduceEndType endType)
        {
            lock (_stateLock)
            {
                switch (endType)
                {
                    case ProduceEndType.SocketShutdownSend:
                        if (_connectionState != ConnectionState.Open)
                        {
                            return;
                        }
                        _connectionState = ConnectionState.Shutdown;

                        KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0);
                        Thread.Post(
                            x =>
                            {
                                KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1);
                                var self = (Connection)x;
                                var shutdown = new UvShutdownReq();
                                shutdown.Init(self.Thread.Loop);
                                shutdown.Shutdown(self._socket, (req, status, state) =>
                                {
                                    KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1);
                                    req.Dispose();
                                }, null);
                            },
                            this);
                        break;
                    case ProduceEndType.ConnectionKeepAlive:
                        if (_connectionState != ConnectionState.Open)
                        {
                            return;
                        }

                        KestrelTrace.Log.ConnectionKeepAlive(_connectionId);
                        _frame = new Frame(this);
                        Thread.Post(
                            x => ((Frame)x).Consume(),
                            _frame);
                        break;
                    case ProduceEndType.SocketDisconnect:
                        if (_connectionState == ConnectionState.Disconnected)
                        {
                            return;
                        }
                        _connectionState = ConnectionState.Disconnected;

                        KestrelTrace.Log.ConnectionDisconnect(_connectionId);
                        Thread.Post(
                            x =>
                            {
                                KestrelTrace.Log.ConnectionStop(_connectionId);
                                ((UvHandle)x).Dispose();
                            },
                            _socket);
                        break;
                }
            }
        }
コード例 #3
0
        private void ProduceEnd(ProduceEndType endType)
        {
            Action drained = () =>
            {
                switch (endType)
                {
                case ProduceEndType.SocketShutdownSend:
                    _socket.Shutdown(SocketShutdown.Send);
                    break;

                case ProduceEndType.ConnectionKeepAlive:
                    ThreadPool.QueueUserWorkItem(_ => Go(true, null));
                    break;

                case ProduceEndType.SocketDisconnect:
                    _services.Trace.Event(TraceEventType.Stop, TraceMessage.Connection);

                    _baton.Free();

                    var receiveSocketEvent = Interlocked.Exchange(ref _receiveSocketEvent, null);

                    // this has a race condition
                    if (receiveSocketEvent.Completed == null)
                    {
                        _services.Memory.FreeSocketEvent(receiveSocketEvent);
                    }
                    else
                    {
                        receiveSocketEvent.Completed = () => _services.Memory.FreeSocketEvent(receiveSocketEvent);
                    }

                    _socket.Shutdown(SocketShutdown.Receive);

                    var    e       = new SocketAsyncEventArgs();
                    Action cleanup = () =>
                    {
                        e.Dispose();
                        _disconnected(_socket);
                    };

                    e.Completed += (_, __) => cleanup();
                    if (!_socket.DisconnectAsync(e))
                    {
                        cleanup();
                    }
                    break;
                }
            };

            if (!_socketSender.Flush(drained))
            {
                drained.Invoke();
            }
        }
コード例 #4
0
        void IConnectionControl.End(ProduceEndType endType)
        {
            switch (endType)
            {
            case ProduceEndType.ConnectionKeepAlive:
                Log.ConnectionKeepAlive(ConnectionId);
                break;

            case ProduceEndType.SocketShutdown:
            case ProduceEndType.SocketDisconnect:
                Log.ConnectionDisconnect(ConnectionId);
                ((SocketOutput)SocketOutput).End(endType);
                break;
            }
        }
コード例 #5
0
 void ISocketOutput.End(ProduceEndType endType)
 {
     switch (endType)
     {
         case ProduceEndType.SocketShutdownSend:
             Write(default(ArraySegment<byte>), (error, state, calledInline) => { }, null,
                 immediate: true,
                 socketShutdownSend: true,
                 socketDisconnect: false);
             break;
         case ProduceEndType.SocketDisconnect:
             Write(default(ArraySegment<byte>), (error, state, calledInline) => { }, null,
                 immediate: true,
                 socketShutdownSend: false,
                 socketDisconnect: true);
             break;
     }
 }
コード例 #6
0
        void ISocketOutput.End(ProduceEndType endType)
        {
            switch (endType)
            {
            case ProduceEndType.SocketShutdownSend:
                Write(default(ArraySegment <byte>), (error, state, calledInline) => { }, null,
                      immediate: true,
                      socketShutdownSend: true,
                      socketDisconnect: false);
                break;

            case ProduceEndType.SocketDisconnect:
                Write(default(ArraySegment <byte>), (error, state, calledInline) => { }, null,
                      immediate: true,
                      socketShutdownSend: false,
                      socketDisconnect: true);
                break;
            }
        }
コード例 #7
0
        public void End(ProduceEndType endType)
        {
            switch (endType)
            {
            case ProduceEndType.SocketShutdownSend:
                WriteAsync(default(ArraySegment <byte>),
                           immediate: true,
                           socketShutdownSend: true,
                           socketDisconnect: false);
                break;

            case ProduceEndType.SocketDisconnect:
                WriteAsync(default(ArraySegment <byte>),
                           immediate: true,
                           socketShutdownSend: false,
                           socketDisconnect: true);
                break;
            }
        }
コード例 #8
0
        void IConnectionControl.End(ProduceEndType endType)
        {
            switch (endType)
            {
            case ProduceEndType.SocketShutdownSend:
                KestrelTrace.Log.ConnectionWriteFin(_connectionId, 0);
                Thread.Post(
                    x =>
                {
                    KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1);
                    var self     = (Connection)x;
                    var shutdown = new UvShutdownReq();
                    shutdown.Init(self.Thread.Loop);
                    shutdown.Shutdown(self._socket, (req, status, state) =>
                    {
                        KestrelTrace.Log.ConnectionWriteFin(_connectionId, 1);
                        req.Dispose();
                    }, null);
                },
                    this);
                break;

            case ProduceEndType.ConnectionKeepAlive:
                KestrelTrace.Log.ConnectionKeepAlive(_connectionId);
                _frame = new Frame(this);
                Thread.Post(
                    x => ((Frame)x).Consume(),
                    _frame);
                break;

            case ProduceEndType.SocketDisconnect:
                KestrelTrace.Log.ConnectionDisconnect(_connectionId);
                Thread.Post(
                    x =>
                {
                    KestrelTrace.Log.ConnectionStop(_connectionId);
                    ((UvHandle)x).Dispose();
                },
                    _socket);
                break;
            }
        }
コード例 #9
0
        public void End(ProduceEndType produceEndType)
        {
            if (produceEndType == ProduceEndType.SocketShutdownSend)
            {
                ShutdownSend = true;
            }
            else
            {
                Ended = true;
            }

            if (produceEndType == ProduceEndType.ConnectionKeepAlive)
            {
                KeepAlive = true;
            }
            else if (produceEndType == ProduceEndType.SocketDisconnect)
            {
                KeepAlive = false;
            }
        }
コード例 #10
0
ファイル: FakeOutput.cs プロジェクト: virajs/firefly
        public void End(ProduceEndType produceEndType)
        {
            if (produceEndType == ProduceEndType.SocketShutdownSend)
            {
                ShutdownSend = true;
            }
            else
            {
                Ended = true;
            }

            if (produceEndType == ProduceEndType.ConnectionKeepAlive)
            {
                KeepAlive = true;
            }
            else if (produceEndType == ProduceEndType.SocketDisconnect)
            {
                KeepAlive = false;
            }
        }
コード例 #11
0
        public void End(ProduceEndType endType)
        {
            switch (endType)
            {
            case ProduceEndType.SocketShutdown:
                WriteAsync(default(ArraySegment <byte>),
                           default(CancellationToken),
                           socketShutdownSend: true,
                           socketDisconnect: true,
                           isSync: true);
                break;

            case ProduceEndType.SocketDisconnect:
                WriteAsync(default(ArraySegment <byte>),
                           default(CancellationToken),
                           socketShutdownSend: false,
                           socketDisconnect: true,
                           isSync: true);
                break;
            }
        }
コード例 #12
0
        void IConnectionControl.End(ProduceEndType endType)
        {
            lock (_stateLock)
            {
                switch (endType)
                {
                case ProduceEndType.SocketShutdownSend:
                    if (_connectionState != ConnectionState.Open)
                    {
                        return;
                    }
                    _connectionState = ConnectionState.Shutdown;

                    Log.ConnectionWriteFin(_connectionId);
                    SocketOutput.End(endType);
                    break;

                case ProduceEndType.ConnectionKeepAlive:
                    if (_connectionState != ConnectionState.Open)
                    {
                        return;
                    }

                    Log.ConnectionKeepAlive(_connectionId);
                    break;

                case ProduceEndType.SocketDisconnect:
                    if (_connectionState == ConnectionState.Disconnected)
                    {
                        return;
                    }
                    _connectionState = ConnectionState.Disconnected;

                    Log.ConnectionDisconnect(_connectionId);
                    SocketOutput.End(endType);
                    break;
                }
            }
        }
コード例 #13
0
        void IConnectionControl.End(ProduceEndType endType)
        {
            lock (_stateLock)
            {
                switch (endType)
                {
                    case ProduceEndType.SocketShutdownSend:
                        if (_connectionState != ConnectionState.Open)
                        {
                            return;
                        }
                        _connectionState = ConnectionState.Shutdown;

                        Log.ConnectionWriteFin(_connectionId);
                        SocketOutput.End(endType);
                        break;
                    case ProduceEndType.ConnectionKeepAlive:
                        if (_connectionState != ConnectionState.Open)
                        {
                            return;
                        }

                        Log.ConnectionKeepAlive(_connectionId);
                        break;
                    case ProduceEndType.SocketDisconnect:
                        if (_connectionState == ConnectionState.Disconnected)
                        {
                            return;
                        }
                        _connectionState = ConnectionState.Disconnected;

                        Log.ConnectionDisconnect(_connectionId);
                        SocketOutput.End(endType);
                        break;
                }
            }
        }
コード例 #14
0
ファイル: Connection.cs プロジェクト: ktairov/firefly
        private void ProduceEnd(ProduceEndType endType)
        {
            Action drained = () =>
            {
                switch (endType)
                {
                case ProduceEndType.SocketShutdownSend:
                    _socket.Shutdown(SocketShutdown.Send);
                    break;
                case ProduceEndType.ConnectionKeepAlive:
                    ThreadPool.QueueUserWorkItem(_ => Go(true, null));
                    break;
                case ProduceEndType.SocketDisconnect:
                    _services.Trace.Event(TraceEventType.Stop, TraceMessage.Connection);

                    _baton.Free();

                    var receiveSocketEvent = Interlocked.Exchange(ref _receiveSocketEvent, null);

                    // this has a race condition
                    if (receiveSocketEvent.Completed == null)
                    {
                        _services.Memory.FreeSocketEvent(receiveSocketEvent);
                    }
                    else
                    {
                        receiveSocketEvent.Completed = () => _services.Memory.FreeSocketEvent(receiveSocketEvent);
                    }

                    _socket.Shutdown(SocketShutdown.Receive);

                    var e = new SocketAsyncEventArgs();
                    Action cleanup = () =>
                    {
                        e.Dispose();
                        _disconnected(_socket);
                    };

                    e.Completed += (_, __) => cleanup();
                    if (!_socket.DisconnectAsync(e))
                    {
                        cleanup();
                    }
                    break;
                }
            };

            if (!_socketSender.Flush(drained))
            {
                drained.Invoke();
            }
        }
コード例 #15
0
 public void End(ProduceEndType endType)
 {
 }
コード例 #16
0
 public void End(ProduceEndType endType)
 {
 }
コード例 #17
0
 public void End(ProduceEndType endType)
 {
     switch (endType)
     {
         case ProduceEndType.SocketShutdownSend:
             WriteAsync(default(ArraySegment<byte>),
                 immediate: true,
                 socketShutdownSend: true,
                 socketDisconnect: false);
             break;
         case ProduceEndType.SocketDisconnect:
             WriteAsync(default(ArraySegment<byte>),
                 immediate: true,
                 socketShutdownSend: false,
                 socketDisconnect: true);
             break;
     }
 }