internal static void Poll(int[] s, int ct, int[] result, nn_pollfd[] info, TimeSpan?timeout) { int milliseconds = -1; if (timeout != null) { milliseconds = (int)timeout.Value.TotalMilliseconds; } else { milliseconds = int.MaxValue; } unsafe { for (int i = 0; i < ct; ++i) { info[i] = new nn_pollfd { fd = s[i], events = (short)Events.POLLIN, revents = 0 }; } fixed(nn_pollfd *pInfo = info) { Interop.nn_poll(pInfo, ct, milliseconds); } } for (int i = 0; i < ct; ++i) { result[i] = (info[i].revents & (short)Events.POLLIN) != 0 ? 1 : 0; } }
public static int[] Poll(int[] s, int ct, TimeSpan?timeout) { var result = new int[ct]; nn_pollfd[] pollfd = new nn_pollfd[ct]; Poll(s, ct, result, pollfd, timeout); return(result); }
public void AddSocket(int s) { var cap = _sockets.Length; if (_ct >= cap) { var new_cap = cap * 2; var new_sockets = new int[new_cap]; var new_results = new int[new_cap]; var new_pollfds = new nn_pollfd[new_cap]; Array.Copy(_sockets, new_sockets, _ct); Array.Copy(_results, new_results, _ct); Array.Copy(_pollfds, new_pollfds, _ct); _sockets = new_sockets; _results = new_results; _pollfds = new_pollfds; } _sockets[_ct] = s; ++_ct; }