private void ListenThread() { while (true) { Socket newSocket; try { newSocket = Base.Accept(); } catch (SocketException) { return; } catch (ObjectDisposedException) { return; } TcpSocket socket = new TcpSocket(newSocket, this); } }
public IOThread EnqueueNew(TcpSocket socket) { if (socket.Ended) { gotFirstSocket = true; return(this); } socket.IOHandler = this; socket.Base.NoDelay = true; socket.Base.Blocking = false; QueuedNew.Enqueue(socket); return(this); }
public IOThread EnqueueClose(TcpSocket socket) { lock (closeLock) { if (socket.IsClosing) { return(this); } socket.IsClosing = true; QueuedClose.Enqueue(socket); } return(this); }
public IOThread EnqueueTerminate(TcpSocket socket) { lock (terminateLock) { if (socket.IsTerminating) { return(this); } socket.IsTerminating = true; QueuedTerminate.Enqueue(socket); } return(this); }
public static IOThread Enqueue(TcpSocket socket) { IOThread best = null; lock (_threadModifyLock) { for (int i = 0; i < _threads.Count; i++) { IOThread curr = _threads[i]; if (best == null || best.SocketCount > curr.SocketCount) { best = curr; } } if (best == null || best.SocketCount > THREAD_MAX_SOCKETS) { IOThread empty = new IOThread(); _threads.Add(empty); best = empty; } } return(best.EnqueueNew(socket)); }
internal void FireConnection(TcpSocket socket) => OnConnection?.Invoke(socket);