internal void Connect(NetworkServerConnection connection) { lock (this.serverConnections) { if (this.pendingConnections.Remove(connection)) { this.serverConnections.Add(connection); this.pingTimer.TimesUp += connection.PingTimerCallback; } } if (!connection.IsConnected) { return; } var made = new ConnectionMadeEventArgs(connection, connection.LocalKey); OnConnectionMade(made); if (made.Rejected) { Trace.WriteLineIf(NetworkConnection.NTrace.TraceVerbose, "Connection rejected", "NetworkConnectionProvider ConnectAsync"); connection.Dispose(); } }
private void Accept(object sender, SocketAsyncEventArgs e) { Trace.WriteLineIf(NetworkConnection.NTrace.TraceVerbose, "Entering", String.Format("NetworkConnectionProvider Accept({0},{1})", e.BytesTransferred, e.SocketError)); if (!this.running || e.SocketError != SocketError.Success) { if (!this.running) { e.Dispose(); } else { #if !SILVERLIGHT e.AcceptSocket.Shutdown(SocketShutdown.Both); e.AcceptSocket.Disconnect(true); // ReliableSockets.Push (this.reliableSocket); #else e.ConnectSocket.Dispose(); #endif BeginAccepting(e); } Trace.WriteLineIf(NetworkConnection.NTrace.TraceVerbose, "Exiting", String.Format("NetworkConnectionProvider Accept({0},{1})", e.BytesTransferred, e.SocketError)); return; } var connection = new NetworkServerConnection(this.enabledHashAlgorithms, this.protocols, e.AcceptSocket, this); lock (this.serverConnections) { if (!connection.IsConnected) { return; } if (this.pendingConnections.Count + this.serverConnections.Count == MaxConnections) { Trace.WriteLineIf(NetworkConnection.NTrace.TraceVerbose, String.Format("At MaxConnections ({0}), disconnecting", MaxConnections), String.Format("NetworkConnectionProvider Accept({0},{1})", e.BytesTransferred, e.SocketError)); connection.DisconnectAsync(); return; } BeginAccepting(e); this.pendingConnections.Add(connection); if (NetworkConnection.AutoSizeSendBufferLimit) { Interlocked.Add(ref NetworkConnection.sendBufferLimit, NetworkConnection.AutoSizeFactor); } } }
internal void Disconnect(NetworkServerConnection connection) { lock (this.serverConnections) { bool atMax = (this.pendingConnections.Count + this.serverConnections.Count == MaxConnections); bool connected = this.serverConnections.Remove(connection); if (connected) { this.pingTimer.TimesUp -= connection.PingTimerCallback; if (NetworkConnection.AutoSizeSendBufferLimit) { Interlocked.Add(ref NetworkConnection.sendBufferLimit, NetworkConnection.AutoSizeFactor * -1); } } if ((connected || this.pendingConnections.Remove(connection)) && atMax) { BeginAccepting(null); } } }
private void Accept(object sender, SocketAsyncEventArgs e) { Trace.WriteLineIf (NetworkConnection.NTrace.TraceVerbose, "Entering", String.Format ("NetworkConnectionProvider Accept({0},{1})", e.BytesTransferred, e.SocketError)); if (!this.running || e.SocketError != SocketError.Success) { if (!this.running) e.Dispose(); else { #if !SILVERLIGHT e.AcceptSocket.Shutdown (SocketShutdown.Both); e.AcceptSocket.Disconnect (true); // ReliableSockets.Push (this.reliableSocket); #else e.ConnectSocket.Dispose(); #endif BeginAccepting (e); } Trace.WriteLineIf (NetworkConnection.NTrace.TraceVerbose, "Exiting", String.Format ("NetworkConnectionProvider Accept({0},{1})", e.BytesTransferred, e.SocketError)); return; } var connection = new NetworkServerConnection (this.enabledHashAlgorithms, this.protocols, e.AcceptSocket, this); lock (this.serverConnections) { if (!connection.IsConnected) return; if (this.pendingConnections.Count + this.serverConnections.Count == MaxConnections) { Trace.WriteLineIf (NetworkConnection.NTrace.TraceVerbose, String.Format ("At MaxConnections ({0}), disconnecting", MaxConnections), String.Format ("NetworkConnectionProvider Accept({0},{1})", e.BytesTransferred, e.SocketError)); connection.DisconnectAsync(); return; } BeginAccepting (e); this.pendingConnections.Add (connection); if (NetworkConnection.AutoSizeSendBufferLimit) Interlocked.Add (ref NetworkConnection.sendBufferLimit, NetworkConnection.AutoSizeFactor); } }
internal void Disconnect(NetworkServerConnection connection) { lock (this.serverConnections) { bool atMax = (this.pendingConnections.Count + this.serverConnections.Count == MaxConnections); bool connected = this.serverConnections.Remove (connection); if (connected) { this.pingTimer.TimesUp -= connection.PingTimerCallback; if (NetworkConnection.AutoSizeSendBufferLimit) Interlocked.Add (ref NetworkConnection.sendBufferLimit, NetworkConnection.AutoSizeFactor * -1); } if ((connected || this.pendingConnections.Remove (connection)) && atMax) { BeginAccepting (null); } } }
internal void Connect(NetworkServerConnection connection) { lock (this.serverConnections) { if (this.pendingConnections.Remove (connection)) { this.serverConnections.Add (connection); this.pingTimer.TimesUp += connection.PingTimerCallback; } } if (!connection.IsConnected) return; var made = new ConnectionMadeEventArgs (connection, connection.LocalKey); OnConnectionMade (made); if (made.Rejected) { Trace.WriteLineIf (NetworkConnection.NTrace.TraceVerbose, "Connection rejected", "NetworkConnectionProvider ConnectAsync"); connection.Dispose(); } }