void ProcessAccept() { int oldState, newState; do { oldState = _state; newState = oldState & ~(int)State.Receive; } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState); var bytesTransfered = _receiveEvent.BytesTransferred; var socketError = _receiveEvent.SocketError; if (bytesTransfered >= 0 && socketError == SocketError.Success) { _socket = _receiveEvent.AcceptSocket; _server.ReportNewConnectedClient(); _handler.FinishAccept(_receiveEvent.Buffer, _receiveEvent.Offset, bytesTransfered, _socket.RemoteEndPoint as IPEndPoint, _socket.LocalEndPoint as IPEndPoint); } else { // Current socket could be corrupted Windows returns InvalidArguments nonsense. RecreateSaeas(); _handler.PrepareAccept(); } }
void ProcessDisconnect() { int oldState, newState; do { oldState = _state; newState = (oldState & ~(int)(State.Disconnect | State.Aborting)); } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState); _socket = null; _server.ReportDisconnectedClient(); _handler.PrepareAccept(); }
void ProcessAccept() { int oldState, newState; do { oldState = _state; newState = oldState & ~(int)State.Receive; } while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState); var bytesTransfered = _acceptEvent.BytesTransferred; var socketError = _acceptEvent.SocketError; if (bytesTransfered >= 0 && socketError == SocketError.Success) { _socket = _acceptEvent.AcceptSocket; IPEndPoint remoteEndpoint = null; IPEndPoint localEndpoint = null; try { remoteEndpoint = _socket.RemoteEndPoint as IPEndPoint; localEndpoint = _socket.LocalEndPoint as IPEndPoint; } catch (SocketException) //"The socket is not connected" is intentionally ignored { } if (remoteEndpoint != null && localEndpoint != null) { _server.ReportNewConnectedClient(); _handler.FinishAccept(_acceptEvent.Buffer, _acceptEvent.Offset, bytesTransfered, remoteEndpoint, localEndpoint); return; } } // Current socket could be corrupted Windows returns InvalidArguments nonsense. RecreateSaeas(); _handler.PrepareAccept(); }
public void PrepareAccept() { _ssl = null; var t = _authenticateTask; _authenticateTask = null; if (t != null && !t.IsCompleted) { t.ContinueWith((t2, next) => { ((ITransportLayerHandler)next).PrepareAccept(); }, _next); return; } _next.PrepareAccept(); }
public void PrepareAccept() { _ssl = null; _next.PrepareAccept(); }