Add close_pipe() wrapper for close()/closesocket().

This commit is contained in:
John Maguire 2013-01-28 17:22:12 +01:00
parent 90bf5816cf
commit 4bed5363e7

23
mdnsd.c
View File

@ -399,6 +399,14 @@ int write_pipe(int s, char* buf, int len) {
#endif #endif
} }
int close_pipe(int s) {
#ifdef _WIN32
return closesocket(s);
#else
return close(s);
#endif
}
// main loop to receive, process and send out MDNS replies // main loop to receive, process and send out MDNS replies
// also handles MDNS service announces // also handles MDNS service announces
static void main_loop(struct mdnsd *svr) { static void main_loop(struct mdnsd *svr) {
@ -497,11 +505,7 @@ static void main_loop(struct mdnsd *svr) {
free(pkt_buffer); free(pkt_buffer);
#ifdef _WIN32 close_pipe(svr->sockfd);
closesocket(svr->sockfd);
#else
close(svr->sockfd);
#endif
svr->stop_flag = 2; svr->stop_flag = 2;
} }
@ -657,13 +661,8 @@ void mdnsd_stop(struct mdnsd *s) {
while (s->stop_flag != 2) while (s->stop_flag != 2)
select(0, NULL, NULL, NULL, &tv); select(0, NULL, NULL, NULL, &tv);
#ifdef _WIN32 close_pipe(s->notify_pipe[0]);
closesocket(s->notify_pipe[0]); close_pipe(s->notify_pipe[1]);
closesocket(s->notify_pipe[1]);
#else
close(s->notify_pipe[0]);
close(s->notify_pipe[1]);
#endif
pthread_mutex_destroy(&s->data_lock); pthread_mutex_destroy(&s->data_lock);
rr_group_destroy(s->group); rr_group_destroy(s->group);