/// <summary> /// Sets the listener in listening state on a particular end-point. /// </summary> /// <param name="address">End-point to listen to.</param> /// <param name="thread">The thread to use for listening.</param> public Task ListenAsync(ServiceAddress address, EventThread thread) { ServerAddress = address; Thread = thread; ConnectionManager = new ConnectionManager(thread); var tcs = new TaskCompletionSource <int>(this); Thread.Post(state => { var tcs2 = (TaskCompletionSource <int>)state; try { var listener = ((Listener)tcs2.Task.AsyncState); listener.ListenSocket = listener.CreateListenSocket(); tcs2.SetResult(0); } catch (Exception ex) { tcs2.SetException(ex); } }, tcs); return(tcs.Task); }
public void Add(int count) { Debug.Assert(count >= 0); if (count == 0) { // No-op and avoid taking lock to reduce contention return; } lock (_lock) { Size += count; if (!_connectionPaused && Size >= _maxSize) { _connectionPaused = true; _connectionThread.Post( (connectionControl) => ((Connection)connectionControl).Pause(), _connectionControl); } } }
public Task StartAsync( string pipeName, ServiceAddress address, EventThread thread) { _pipeName = pipeName; _buf = thread.Loop.Libuv.buf_init(_ptr, 4); ServerAddress = address; Thread = thread; ConnectionManager = new ConnectionManager(thread); DispatchPipe = new UvPipeHandle(); var tcs = new TaskCompletionSource <int>(this); Thread.Post(state => StartCallback((TaskCompletionSource <int>)state), tcs); return(tcs.Task); }