Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RemoveSocket(s) method to Poller. #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/ZeroMQ/Poller.cs
Expand Up @@ -123,6 +123,47 @@ public void ClearSockets()
CreatePollItems();
}

/// <summary>
/// Remove a socket that is polled for input/output events, depending on its capabilities.
/// </summary>
/// <param name="socket">The <see cref="ZmqSocket"/> to remove.</param>
/// <exception cref="ArgumentNullException"><paramref name="socket"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="socket"/> has no event handlers.</exception>
public void RemoveSocket(ZmqSocket socket)
{
if (socket == null)
{
throw new ArgumentNullException("socket");
}

var pollEvents = socket.GetPollEvents();

if (pollEvents == PollEvents.None)
{
throw new ArgumentOutOfRangeException("socket", "Unable to remove socket without at least one handler.");
}

_pollableSockets.Remove(new PollItem(socket.SocketHandle, pollEvents));
CreatePollItems();
}

/// <summary>
/// Remove a collection of sockets that is polled for input/output events, depending on their capabilities.
/// </summary>
/// <param name="sockets">The collection of <see cref="ZmqSocket"/>s to poll.</param>
public void RemoveSockets(IEnumerable<ZmqSocket> sockets)
{
if (sockets == null)
{
throw new ArgumentNullException("sockets");
}

foreach (var socket in sockets)
{
RemoveSocket(socket);
}
}

/// <summary>
/// Multiplex input/output events over the contained set of sockets in blocking mode, firing
/// <see cref="ZmqSocket.ReceiveReady" /> or <see cref="ZmqSocket.SendReady" /> as appropriate.
Expand Down