void Accept() { if (SocketAsynPool.Count > 0) { SocketAsyncEventArgs sockasyn = SocketAsynPool.Pop(); sockasyn.Completed += new EventHandler <SocketAsyncEventArgs>(WorkaroundCallback); if (!Sock.AcceptAsync(sockasyn)) { WorkaroundCallback(null, sockasyn); } var client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); if (myEnd.Address == IPAddress.Any) { client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), myEnd.Port)); } else { client.Connect(myEnd); } client.Close(); } else { LogOutEvent(null, LogType.Error, "The MaxUserCout"); } }
private void Accept(SocketAsyncEventArgs args) { args.AcceptSocket = null; if (!Sock.AcceptAsync(args)) { Asyn_Completed(null, args); } }
private async Task Accept() { while (!Cts.IsCancellationRequested) { var ns = await Sock.AcceptAsync(); if (ns != null) { new BitcoinNodePeer(new BitcoinPeer(ns)); } } }
void Accept(ZYSocketAsyncEventArgs sockasyn) { sockasyn.Reset(); try { if (!Sock.AcceptAsync(sockasyn)) { BeginAccep(sockasyn); } } catch (ObjectDisposedException) { } }
void Accept() { if (SocketAsynPool.Count > 0) { SocketAsyncEventArgs sockasyn = SocketAsynPool.Pop(); if (!Sock.AcceptAsync(sockasyn)) { BeginAccep(sockasyn); } } else { LogOutEvent(null, LogType.Error, "The MaxUserCout"); } }
private async Task Accept() { #if NET461 var sem_net461 = new SemaphoreSlim(1); #endif while (!Cts.IsCancellationRequested) { #if NET461 Socket ns = null; var saa = new SocketAsyncEventArgs(); saa.Completed += (s, e) => { ns = e.AcceptSocket; sem_net461.Release(); }; if (!Sock.AcceptAsync(saa)) { ns = saa.AcceptSocket; } else { await sem_net461.WaitAsync(); } #else var ns = await Sock.AcceptAsync(); #endif if (ns != null) { var id = Guid.NewGuid(); var np = new T(); np.OnStop += Node_OnStop; np.Init(this, new BitcoinPeer(ChainParams, ns, true), id); if (Peers.TryAdd(id, np)) { OnLog?.Invoke($"New peer added: {np.RemoteEndpoint}!"); } } } }