-char *mesh_event_sock_create(const char *if_name) {
- struct sockaddr_in server;
- char *ip;
- struct ifreq req_if;
- struct sockaddr_in *resp_if_addr;
+static void set_cond_flag(struct cond_flag *s, bool flag) {
+ pthread_mutex_lock(&s->mutex);
+ s->flag = flag;
+ pthread_cond_broadcast(&s->cond);
+ pthread_mutex_unlock(&s->mutex);
+}
+
+static bool wait_cond_flag(struct cond_flag *s, int seconds) {
+ struct timespec timeout;
+ clock_gettime(CLOCK_REALTIME, &timeout);
+ timeout.tv_sec += seconds;
+
+ pthread_mutex_lock(&s->mutex);
+
+ while(!s->flag)
+ if(!pthread_cond_timedwait(&s->cond, &s->mutex, &timeout) || errno != EINTR) {
+ break;
+ }
+
+ pthread_mutex_unlock(&s->mutex);
+
+ return s->flag;
+}
+
+// event_receive_handler running in a separate thread queues all the events received from the UDP port
+static void *event_receive_handler(void *arg) {
+ (void)arg;
+ size_t recv_ret;
+ char udp_buff[UDP_BUFF_MAX];
+ struct sockaddr client;
+ socklen_t soc_len;
+
+ while(event_receive_thread_running) {
+ recv_ret = recvfrom(server_fd, udp_buff, sizeof(udp_buff), 0, &client, &soc_len);
+ assert(recv_ret >= sizeof(mesh_event_payload_t));