1 /*****************************************************************************
2 * linux/getaddrinfo.c: interruptible DNS resolution for Linux
3 *****************************************************************************
4 * Copyright (C) 2016 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_interrupt.h>
32 #include <vlc_network.h>
34 static void vlc_getaddrinfo_notify(union sigval val
)
36 vlc_sem_post(val
.sival_ptr
);
39 int vlc_getaddrinfo_i11e(const char *name
, unsigned port
,
40 const struct addrinfo
*hints
,
41 struct addrinfo
**res
)
54 if ((size_t)snprintf(portbuf
, sizeof (portbuf
), "%u",
55 port
) >= sizeof (portbuf
))
58 req
.ar_service
= portbuf
;
63 .sigev_notify
= SIGEV_THREAD
,
64 .sigev_value
= { .sival_ptr
= &done
, },
65 .sigev_notify_function
= vlc_getaddrinfo_notify
,
68 vlc_sem_init(&done
, 0);
70 int val
= getaddrinfo_a(GAI_NOWAIT
, &(struct gaicb
*){ &req
}, 1, &sev
);
74 vlc_sem_wait_i11e(&done
);
76 if (gai_cancel(&req
) == EAI_CANCELED
)
79 while (gai_suspend(&(const struct gaicb
*){ &req
}, 1, NULL
) == EAI_INTR
);
81 val
= gai_error(&req
);
82 assert(val
!= EAI_INPROGRESS
);