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;
                }
            }
        }
Exemple #2
0
 public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb)
 {
     req.Validate();
     handle.Validate();
     Check(_uv_shutdown(req, handle, cb));
 }
            /// <summary>
            /// Second step: initiate async shutdown if needed, otherwise go to next step
            /// </summary>
            public void DoShutdownIfNeeded()
            {
                if (SocketShutdownSend == false || Self._socket.IsClosed)
                {
                    DoDisconnectIfNeeded();
                    return;
                }

                var shutdownReq = new UvShutdownReq(Self._log);
                shutdownReq.Init(Self._thread.Loop);
                shutdownReq.Shutdown(Self._socket, (_shutdownReq, status, state) =>
                {
                    _shutdownReq.Dispose();
                    var _this = (WriteContext)state;
                    _this.ShutdownSendStatus = status;

                    Self._log.ConnectionWroteFin(Self._connectionId, status);

                    DoDisconnectIfNeeded();
                }, this);
            }
Exemple #4
0
 public static extern int uv_shutdown(UvShutdownReq req,UvStreamHandle handle,uv_shutdown_cb cb);
Exemple #5
0
 public void shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb)
 {
     req.Validate();
     handle.Validate();
     Check(_uv_shutdown(req, handle, cb));
 }
 public static extern int uv_shutdown(UvShutdownReq req, UvStreamHandle handle, uv_shutdown_cb cb);