private void ProcessRecieve(SocketAsyncEventArgs args) { try { int bytesTransferred = args.BytesTransferred; if (bytesTransferred == 0) { _server.DisconnectClient(this, true, false); } else { _bytesReceived += (uint)bytesTransferred; Interlocked.Add(ref _totalBytesReceived, bytesTransferred); _remainingLength += bytesTransferred; if (_remainingLength > 6) { OnReceive(); } ResumeReceive(); } } catch (ObjectDisposedException ex) { _server.DisconnectClient(this, true, false); } catch (Exception ex) { _server.Warning(this, ex); _server.DisconnectClient(this, true, false); } finally { args.Completed -= ReceiveAsyncComplete; SocketHelpers.ReleaseSocketArg(args); } }
private void ProcessRecieve(SocketAsyncEventArgs args) { try { int bytesTransferred = args.BytesTransferred; if (bytesTransferred == 0) { this._server.DisconnectClient((IClient)this, true, false); } else { this._bytesReceived += (uint)bytesTransferred; Interlocked.Add(ref ClientBase._totalBytesReceived, (long)bytesTransferred); this._remainingLength += bytesTransferred; if (this._remainingLength > 6) { this.OnReceive(); } this.ResumeReceive(); } } catch (ObjectDisposedException ex) { this._server.DisconnectClient((IClient)this, true, false); } catch (Exception ex) { this._server.Warning((IClient)this, ex); this._server.DisconnectClient((IClient)this, true, false); } finally { args.Completed -= new EventHandler <SocketAsyncEventArgs>(this.ReceiveAsyncComplete); SocketHelpers.ReleaseSocketArg(args); } }
/// <summary> /// Begin listening for TCP connections. Should not be called directly - instead use <see cref="M:Cell.Core.ServerBase.Start(System.Boolean,System.Boolean)" /> /// <seealso cref="P:Cell.Core.ServerBase.TCPEnabled" /> /// </summary> protected void StartTCP() { if (this.TcpEnabledEnabled || !this._running) { return; } ServerBase.VerifyEndpointAddress(this.TcpEndPoint); this._tcpListen = new Socket(this.TcpEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { this._tcpListen.Bind((EndPoint)this.TcpEndPoint); } catch (Exception ex) { ServerBase.log.Error("Could not bind to Address {0}: {1}", (object)this.TcpEndPoint, (object)ex); return; } this._tcpListen.Listen(this.MaximumPendingConnections); SocketHelpers.SetListenSocketOptions(this._tcpListen); this.StartAccept((SocketAsyncEventArgs)null); this.TcpEnabledEnabled = true; this.Info((IClient)null, Cell_Core.ListeningTCPSocket, (object)this.TcpEndPoint); }
/// <summary> /// Begin listening for TCP connections. Should not be called directly - instead use <see cref="M:Cell.Core.ServerBase.Start(System.Boolean,System.Boolean)" /> /// <seealso cref="P:Cell.Core.ServerBase.TCPEnabled" /> /// </summary> protected void StartTCP() { if (TcpEnabledEnabled || !_running) { return; } VerifyEndpointAddress(TcpEndPoint); _tcpListen = new Socket(TcpEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { _tcpListen.Bind(TcpEndPoint); } catch (Exception ex) { log.Error("Could not bind to Address {0}: {1}", TcpEndPoint, ex); return; } _tcpListen.Listen(MaximumPendingConnections); SocketHelpers.SetListenSocketOptions(_tcpListen); StartAccept(null); TcpEnabledEnabled = true; Info(null, Cell_Core.ListeningTCPSocket, (object)TcpEndPoint); }
private static void SendAsyncComplete(object sender, SocketAsyncEventArgs args) { args.Completed -= SendAsyncComplete; SocketHelpers.ReleaseSocketArg(args); }
private static void SendAsyncComplete(object sender, SocketAsyncEventArgs args) { args.Completed -= new EventHandler <SocketAsyncEventArgs>(ClientBase.SendAsyncComplete); SocketHelpers.ReleaseSocketArg(args); }