/// <summary>Add a socket.</summary> /// <param name="sock"> /// The socket to add. It is an error to re-add a socket that /// we are already watching. /// </param> /// <param name="handler"> /// The handler to associate with this socket. This may be /// called any time after this function is called. /// </param> public void Add(DomainSocket sock, DomainSocketWatcher.Handler handler) { Lock.Lock(); try { if (closed) { handler.Handle(sock); IOUtils.Cleanup(Log, sock); return; } DomainSocketWatcher.Entry entry = new DomainSocketWatcher.Entry(sock, handler); try { sock.refCount.Reference(); } catch (ClosedChannelException) { // If the socket is already closed before we add it, invoke the // handler immediately. Then we're done. handler.Handle(sock); return; } toAdd.AddItem(entry); Kick(); while (true) { try { processedCond.Await(); } catch (Exception) { Thread.CurrentThread().Interrupt(); } if (!toAdd.Contains(entry)) { break; } } } finally { Lock.Unlock(); } }
internal Entry(DomainSocket socket, DomainSocketWatcher.Handler handler) { this.socket = socket; this.handler = handler; }