void AcceptNext() { try { Debug.WriteLine("KayakServer: accepting connection"); listener.BeginAccept(iasr => { Socket socket = null; Exception error = null; try { socket = listener.EndAccept(iasr); AcceptNext(); } catch (Exception e) { error = e; } if (error is ObjectDisposedException) return; scheduler.Post(() => { Debug.WriteLine("KayakServer: accepted connection"); if (error != null) HandleAcceptError(error); var s = new KayakSocket(socket, this.scheduler); state.IncrementConnections(); var socketDelegate = del.OnConnection(this, s); s.del = socketDelegate; s.DoRead(); }); }, null); } catch (ObjectDisposedException e) { return; } catch (Exception e) { HandleAcceptError(e); } }
internal void SocketClosed(KayakSocket socket) { //Debug.WriteLine("Connection " + socket.id + ": closed (" + connections + " active connections)"); if (state.DecrementConnections()) RaiseOnClose(); }