/// <summary> /// Start listening for incoming connections. /// </summary> /// <param name="backlog">Indicates the number of connections the kernel might queue.</param> /// <param name="callback">Callback to be called when a new incoming connection is received.</param> /// <param name="state">State to be passed to the callback.</param> public void Listen(int backlog, ListenCallbackDelegate callback, object state = null) { this.EnsureCallingThread(); if (this._ListenVitality.IsAllocated) { throw new InvalidOperationException("Listen may not be called more than once."); } try { this._UserListenCallback = callback; this._UserListenState = state; this._ListenVitality = GCHandle.Alloc(this, GCHandleType.Normal); Libuv.EnsureSuccess(Libuv.uv_listen(this, backlog, _UvListenCallback)); } catch { this._UserListenCallback = null; this._UserListenState = null; if (this._ListenVitality.IsAllocated) { this._ListenVitality.Free(); } throw; } }