unsafe internal static bool PollSingle( ZSocket socket, ZPollItem item, ZPoll pollEvents, out ZError error, TimeSpan? timeout = null) { error = default(ZError); bool result = false; int timeoutMs = !timeout.HasValue ? -1 : (int)timeout.Value.TotalMilliseconds; zmq_pollitem_posix_t* native = stackalloc zmq_pollitem_posix_t[1]; // fixed (zmq_pollitem_posix_t* native = managedArray) { native->SocketPtr = socket.SocketPtr; native->Events = (short)(item.Events & pollEvents); native->ReadyEvents = (short)ZPoll.None; while (!(result = (-1 != zmq.poll(native, 1, timeoutMs)))) { error = ZError.GetLastErr(); if (error == ZError.EINTR) { error = default(ZError); continue; } break; } item.ReadyEvents = (ZPoll)native->ReadyEvents; //} return result; }
unsafe internal static bool PollSingle( ZSocket socket, ZPollItem item, ZPoll pollEvents, out ZError error, TimeSpan?timeout = null) { error = default(ZError); bool result = false; int timeoutMs = !timeout.HasValue ? -1 : (int)timeout.Value.TotalMilliseconds; zmq_pollitem_windows_t *native = stackalloc zmq_pollitem_windows_t[1]; // fixed (zmq_pollitem_windows_t* native = managedArray) { native->SocketPtr = socket.SocketPtr; native->Events = (short)(item.Events & pollEvents); native->ReadyEvents = (short)ZPoll.None; while (!(result = (-1 != zmq.poll(native, 1, timeoutMs)))) { error = ZError.GetLastErr(); /* if (error == ZmqError.EINTR) * { * error = default(ZmqError); * continue; * } */ break; } item.ReadyEvents = (ZPoll)native->ReadyEvents; // } return(result); }
public static bool Poll(this ZSocket socket, ZPollItem item, ZPoll pollEvents, ref ZMessage message, out ZError error, TimeSpan?timeout = null) { if (PollSingle(socket, item, pollEvents, out error, timeout)) { if (PollSingleResult(socket, item, pollEvents, ref message)) { return(true); } error = ZError.EAGAIN; } return(false); }
public zmq_pollitem_posix_t(IntPtr socket, ZPoll pollEvents) { if (socket == IntPtr.Zero) { throw new ArgumentException("Expected a valid socket handle.", "socket"); } socketPtr = socket; fileDescriptor = 0; events = (short)pollEvents; readyEvents = (short)ZPoll.None; }
public zmq_pollitem_windows_t(IntPtr socket, ZPoll pollEvents) { if (socket == IntPtr.Zero) { throw new ArgumentException("Expected a valid socket handle.", "socket"); } socketPtr = socket; fileDescriptor = IntPtr.Zero; events = (short)pollEvents; readyEvents = 0; }
internal static bool PollSingleResult(ZSocket socket, ZPollItem item, ZPoll pollEvents, ref ZMessage message) { bool shouldReceive = item.ReceiveMessage != null && ((pollEvents & ZPoll.In) == ZPoll.In); bool shouldSend = item.SendMessage != null && ((pollEvents & ZPoll.Out) == ZPoll.Out); if (pollEvents == ZPoll.In) { if (!shouldReceive) { throw new InvalidOperationException("No ReceiveMessage delegate set for Poll.In"); } if (OnReceiveMessage(socket, item, out message)) { if (!shouldSend) { return true; } if (OnSendMessage(socket, item, message)) { return true; } } } else if (pollEvents == ZPoll.Out) { if (!shouldSend) { throw new InvalidOperationException("No SendMessage delegate set for Poll.Out"); } if (OnSendMessage(socket, item, message)) { if (!shouldReceive) { return true; } if (OnReceiveMessage(socket, item, out message)) { return true; } } } return false; }
public static bool Poll(this ZSocket socket, ZPollItem item, ZPoll pollEvents, ref ZMessage message, out ZError error, TimeSpan? timeout = null) { if (PollSingle(socket, item, pollEvents, out error, timeout)) { if (PollSingleResult(socket, item, pollEvents, ref message)) { return true; } error = ZError.EAGAIN; } return false; }
unsafe internal static bool PollMany( IEnumerable <ZSocket> sockets, IEnumerable <ZPollItem> items, ZPoll pollEvents, out ZError error, TimeSpan?timeout = null) { error = default(ZError); bool result = false; int count = items.Count(); int timeoutMs = !timeout.HasValue ? -1 : (int)timeout.Value.TotalMilliseconds; zmq_pollitem_windows_t *natives = stackalloc zmq_pollitem_windows_t[count]; // fixed (zmq_pollitem_windows_t* natives = managedArray) { for (int i = 0; i < count; ++i) { ZSocket socket = sockets.ElementAt(i); ZPollItem item = items.ElementAt(i); zmq_pollitem_windows_t *native = natives + i; native->SocketPtr = socket.SocketPtr; native->Events = (short)(item.Events & pollEvents); native->ReadyEvents = (short)ZPoll.None; } while (!(result = (-1 != zmq.poll(natives, count, timeoutMs)))) { error = ZError.GetLastErr(); // No Signalling on Windows /* if (error == ZmqError.EINTR) { * error = ZmqError.DEFAULT; * continue; * } */ break; } for (int i = 0; i < count; ++i) { ZPollItem item = items.ElementAt(i); zmq_pollitem_windows_t *native = natives + i; item.ReadyEvents = (ZPoll)native->ReadyEvents; } // } return(result); }
public static bool Poll(this IEnumerable<ZSocket> sockets, IEnumerable<ZPollItem> items, ZPoll pollEvents, ref ZMessage[] messages, out ZError error, TimeSpan? timeout = null) { if (PollMany(sockets, items, pollEvents, out error, timeout)) { if (PollManyResult(sockets, items, pollEvents, ref messages)) { return true; } error = ZError.EAGAIN; } return false; }
unsafe internal static bool PollMany( IEnumerable<ZSocket> sockets, IEnumerable<ZPollItem> items, ZPoll pollEvents, out ZError error, TimeSpan? timeout = null) { error = default(ZError); bool result = false; int count = items.Count(); int timeoutMs = !timeout.HasValue ? -1 : (int)timeout.Value.TotalMilliseconds; zmq_pollitem_posix_t* natives = stackalloc zmq_pollitem_posix_t[count]; // fixed (zmq_pollitem_posix_t* natives = managedArray) { for (int i = 0; i < count; ++i) { ZSocket socket = sockets.ElementAt(i); ZPollItem item = items.ElementAt(i); zmq_pollitem_posix_t* native = natives + i; native->SocketPtr = socket.SocketPtr; native->Events = (short)(item.Events & pollEvents); native->ReadyEvents = (short)ZPoll.None; } while (!(result = (-1 != zmq.poll(natives, count, timeoutMs)))) { error = ZError.GetLastErr(); if (error == ZError.EINTR) { error = default(ZError); continue; } break; } for (int i = 0; i < count; ++i) { ZPollItem item = items.ElementAt(i); zmq_pollitem_posix_t* native = natives + i; item.ReadyEvents = (ZPoll)native->ReadyEvents; } // } return result; }
internal static bool PollSingleResult(ZSocket socket, ZPollItem item, ZPoll pollEvents, ref ZMessage message) { bool shouldReceive = item.ReceiveMessage != null && ((pollEvents & ZPoll.In) == ZPoll.In); bool shouldSend = item.SendMessage != null && ((pollEvents & ZPoll.Out) == ZPoll.Out); if (pollEvents == ZPoll.In) { if (!shouldReceive) { throw new InvalidOperationException("No ReceiveMessage delegate set for Poll.In"); } if (OnReceiveMessage(socket, item, out message)) { if (!shouldSend) { return(true); } if (OnSendMessage(socket, item, message)) { return(true); } } } else if (pollEvents == ZPoll.Out) { if (!shouldSend) { throw new InvalidOperationException("No SendMessage delegate set for Poll.Out"); } if (OnSendMessage(socket, item, message)) { if (!shouldReceive) { return(true); } if (OnReceiveMessage(socket, item, out message)) { return(true); } } } return(false); }
internal static bool PollManyResult(IEnumerable <ZSocket> sockets, IEnumerable <ZPollItem> items, ZPoll pollEvents, ref ZMessage[] messages) { int count = items.Count(); int readyCount = 0; bool send = messages != null && ((pollEvents & ZPoll.Out) == ZPoll.Out); bool receive = ((pollEvents & ZPoll.In) == ZPoll.In); ZMessage[] incoming = null; if (receive) { incoming = new ZMessage[count]; } for (int i = 0; i < count; ++i) { ZSocket socket = sockets.ElementAt(i); ZPollItem item = items.ElementAt(i); ZMessage message = send ? messages[i] : null; if (ZPollItems.PollSingleResult(socket, item, pollEvents, ref message)) { ++readyCount; } if (receive) { incoming[i] = message; } } if (receive) { messages = incoming; } return(readyCount > 0); }
public static bool Poll(this IEnumerable <ZSocket> sockets, IEnumerable <ZPollItem> items, ZPoll pollEvents, ref ZMessage[] messages, out ZError error, TimeSpan?timeout = null) { if (PollMany(sockets, items, pollEvents, out error, timeout)) { if (PollManyResult(sockets, items, pollEvents, ref messages)) { return(true); } error = ZError.EAGAIN; } return(false); }
protected ZPollItem(ZPoll events) { Events = events; }
protected ZPollItem(ZPoll events) { Events = events; }
internal static bool PollManyResult(IEnumerable<ZSocket> sockets, IEnumerable<ZPollItem> items, ZPoll pollEvents, ref ZMessage[] messages) { int count = items.Count(); int readyCount = 0; bool send = messages != null && ((pollEvents & ZPoll.Out) == ZPoll.Out); bool receive = ((pollEvents & ZPoll.In) == ZPoll.In); ZMessage[] incoming = null; if (receive) { incoming = new ZMessage[count]; } for (int i = 0; i < count; ++i) { ZSocket socket = sockets.ElementAt(i); ZPollItem item = items.ElementAt(i); ZMessage message = send ? messages[i] : null; if (ZPollItems.PollSingleResult(socket, item, pollEvents, ref message)) { ++readyCount; } if (receive) { incoming[i] = message; } } if (receive) { messages = incoming; } return readyCount > 0; }