public static void Return(AsyncAcceptArgs args) { if (args != null) { AsyncAcceptArgsPool.Push(args); } }
public Listener(Socket s, int maxAcceptOps = 10) { AcceptArgs = new BlockingCollection <AsyncAcceptArgs>(maxAcceptOps); Sock = s; MaxAcceptOps = maxAcceptOps; for (int i = 0; i < maxAcceptOps; i++) { AsyncAcceptArgs args = AsyncAcceptArgs.Get(this); AcceptArgs.Add(args); } }
public void StartAccepting(string address, int port) { Sock.Bind(new IPEndPoint(IPAddress.Parse(address), port)); Sock.Listen(MaxAcceptOps); while (true) { AsyncAcceptArgs args = AcceptArgs.Take(); args.AcceptSocket = null; accept(args); } }
public static AsyncAcceptArgs Get(Listener l) { AsyncAcceptArgs args = null; AsyncAcceptArgsPool.TryPop(out args); if (args == null) { args = new AsyncAcceptArgs(); } args.listener = l; return(args); }