void *pv_messclient_receive(){ NET_CHANNEL *chan = NULL; message_buf rbuf; struct str_user_data * p_user_data; chan = net_openchannel (DRIVER,user_data.local_IP_udp_port); if (!chan) { fprintf (stderr,"Error opening channel.\n"); exit(ERROR); } while(1){ while (net_query (chan)){ /* If so, receive them and print them out. */ if (net_receive (chan,&rbuf,sizeof(rbuf), NULL) > 0){ p_user_data = (struct str_user_data *)( rbuf.mtext + 1 ); /* Print the message */ printf("\n# Received from IP : %s PID : %d : %s\n", p_user_data->local_IP,p_user_data->pid,rbuf.mtext+1+sizeof(struct str_user_data)); /*Write the init massage again */ printf("# IP : %s PID :%d :", user_data.local_IP, user_data.pid ); fflush(stdout); }/*if*/ }/*while*/ }/*while (1)*/ net_closechannel (chan); return OK; }
static int destroy_conn (NET_CONN *conn) { struct conn_data_t *data = conn->data; if (data->referer) { /* remove us from refering list in listener connection */ struct conns_list *prev = NULL, *list = data->referer->conns; while (list) { if (list->chan == data->chan) { struct conns_list *old = list; if (prev) prev->next = list->next; else data->referer->conns = list->next; list = list->next; free(old->addr); free(old); } else { prev = list; list = list->next; } } } net_closechannel (data->chan); destroy_queues (conn); destroy_conns_list (data->conns); free (data); return 0; }