void zbeacon (zsock_t *pipe, void *args) { self_t *self = s_self_new (pipe); assert (self); // Signal successful initialization zsock_signal (pipe, 0); while (!self->terminated) { // Poll on API pipe and on UDP socket zmq_pollitem_t pollitems [] = { { zsock_resolve (self->pipe), 0, ZMQ_POLLIN, 0 }, { NULL, self->udpsock, ZMQ_POLLIN, 0 } }; long timeout = -1; if (self->transmit) { timeout = (long) (self->ping_at - zclock_mono ()); if (timeout < 0) timeout = 0; } int pollset_size = self->udpsock? 2: 1; if (zmq_poll (pollitems, pollset_size, timeout * ZMQ_POLL_MSEC) == -1) break; // Interrupted if (pollitems [0].revents & ZMQ_POLLIN) s_self_handle_pipe (self); if (pollitems [1].revents & ZMQ_POLLIN) s_self_handle_udp (self); if (self->transmit && zclock_mono () >= self->ping_at) { // Send beacon to any listening peers if (zsys_udp_send (self->udpsock, self->transmit, &self->broadcast, sizeof (inaddr_t))) // Try to recreate UDP socket on interface s_self_prepare_udp (self); self->ping_at = zclock_mono () + self->interval; } } s_self_destroy (&self); }
/// // Send zframe to UDP socket, return -1 if sending failed due to // interface having disappeared (happens easily with WiFi) // *** This is for CZMQ internal use only and may change arbitrarily *** int QmlZsysAttached::udpSend (SOCKET udpsock, QmlZframe *frame, inaddr_t *address, int addrlen) { return zsys_udp_send (udpsock, frame->self, address, addrlen); };
/// // Send zframe to UDP socket, return -1 if sending failed due to // interface having disappeared (happens easily with WiFi) // *** This is for CZMQ internal use only and may change arbitrarily *** int QZsys::udpSend (SOCKET udpsock, QZframe *frame, inaddr_t *address, int addrlen) { int rv = zsys_udp_send (udpsock, frame->self, address, addrlen); return rv; }