qt: playlist: use item title if available
[vlc.git] / src / linux / getaddrinfo.c
blob7c082d4e97868c1dbb1622fb18011f8ff05028a5
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <assert.h>
26 #include <stdio.h>
27 #include <netdb.h>
28 #include <signal.h>
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)
43 struct gaicb req =
45 .ar_name = name,
46 .ar_service = NULL,
47 .ar_request = hints,
49 char portbuf[6];
50 vlc_sem_t done;
52 if (port != 0)
54 if ((size_t)snprintf(portbuf, sizeof (portbuf), "%u",
55 port) >= sizeof (portbuf))
56 return EAI_NONAME;
58 req.ar_service = portbuf;
61 struct sigevent sev =
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);
71 if (val)
72 return val;
74 vlc_sem_wait_i11e(&done);
76 if (gai_cancel(&req) == EAI_CANCELED)
77 vlc_sem_wait(&done);
79 while (gai_suspend(&(const struct gaicb *){ &req }, 1, NULL) == EAI_INTR);
81 val = gai_error(&req);
82 assert(val != EAI_INPROGRESS);
84 if (val == 0)
85 *res = req.ar_result;
87 return val;