/// <summary> /// Polls the supplied items for events. Static method. /// </summary> /// <param name="items">Items to Poll</param> /// <param name="timeout">Timeout(micro seconds)</param> /// <returns>Number of Poll items with events</returns> public static int Poller(PollItem[] items, long timeout) { Stopwatch spentTimeout = new Stopwatch(); int rc = -1; if (timeout >= 0) { spentTimeout.Start(); } while (rc != 0) { ZMQPollItem[] zitems = new ZMQPollItem[items.Length]; int index = 0; foreach (PollItem item in items) { item.ZMQPollItem.ResetRevents(); zitems[index] = item.ZMQPollItem; index++; } rc = C.zmq_poll(zitems, items.Length, timeout); if (rc > 0) { for (index = 0; index < items.Length; index++) { items[index].ZMQPollItem = zitems[index]; items[index].FireEvents(); } break; } else if (rc < 0) { if (ZMQ.C.zmq_errno() == 4) { if (spentTimeout.IsRunning) { long elapsed = spentTimeout.ElapsedMilliseconds * 1000; if (timeout < elapsed) { break; } else { timeout -= elapsed; continue; } } else { continue; } } throw new Exception(); } } return(rc); }
/// <summary> /// Polls the supplied items for events. Static method. /// </summary> /// <param name="items">Items to Poll</param> /// <param name="timeout">Timeout(micro seconds)</param> /// <returns>Number of Poll items with events</returns> public static int Poller(PollItem[] items, long timeout) { var spentTimeout = new Stopwatch(); int rc = -1; if (timeout >= 0) { spentTimeout.Start(); } while (rc != 0) { var zitems = new ZMQPollItem[items.Length]; int index = 0; foreach (PollItem item in items) { item.ZMQPollItem.ResetRevents(); zitems[index] = item.ZMQPollItem; index++; } rc = C.zmq_poll(zitems, items.Length, timeout); if (rc > 0) { for (index = 0; index < items.Length; index++) { items[index].ZMQPollItem = zitems[index]; items[index].FireEvents(); } break; } if (rc < 0) { if (C.zmq_errno() == 4) { if (spentTimeout.IsRunning) { long elapsed = spentTimeout.ElapsedMilliseconds * 1000; if (timeout < elapsed) { break; } timeout -= elapsed; continue; } continue; } throw new Exception(); } } return rc; }
/// <summary> /// Should not be created directly, use Socket.CreatePollItem /// </summary> /// <param name="zmqPollItem"></param> /// <param name="socket"></param> internal PollItem(ZMQPollItem zmqPollItem, Socket socket) { this._socket = socket; this._zmqPollItem = zmqPollItem; }
/// <summary> /// Should not be created directly, use Socket.CreatePollItem /// </summary> /// <param name="zmqPollItem">Native poll item</param> /// <param name="socket">Socket to poll</param> internal PollItem(ZMQPollItem zmqPollItem, Socket socket) { _socket = socket; _zmqPollItem = zmqPollItem; }
/// <summary> /// Should not be created directly, use Socket.CreatePollItem /// </summary> /// <param name="zmqPollItem">Native poll item</param> /// <param name="socket">Socket to poll</param> internal PollItem(ZMQPollItem zmqPollItem, Socket socket) { if (socket == null) { throw new ArgumentNullException("socket"); } _socket = socket; _zmqPollItem = zmqPollItem; }