[vlc-devel] [PATCH 1/3] vlccore: export vlc_poll() and vlc_freeaddrinfo()
KO Myung-Hun
komh78 at gmail.com
Thu Nov 13 09:06:59 CET 2014
---
include/vlc_network.h | 1 +
include/vlc_threads.h | 25 ++------------------
modules/stream_out/standard.c | 4 ++--
src/Makefile.am | 1 +
src/extras/poll.c | 53 +++++++++++++++++++++++++++++++++++++++++++
src/libvlccore.sym | 2 ++
src/network/getaddrinfo.c | 7 +++++-
7 files changed, 67 insertions(+), 26 deletions(-)
create mode 100644 src/extras/poll.c
diff --git a/include/vlc_network.h b/include/vlc_network.h
index d1c63b1..bb11029 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -267,6 +267,7 @@ VLC_API int getnameinfo ( const struct sockaddr *, socklen_t,
VLC_API int vlc_getnameinfo( const struct sockaddr *, int, char *, int, int *, int );
VLC_API int vlc_getaddrinfo (const char *, unsigned,
const struct addrinfo *, struct addrinfo **);
+VLC_API void vlc_freeaddrinfo( struct addrinfo * );
#ifdef __OS2__
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 00435cb..94a768d 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -388,32 +388,11 @@ struct vlc_cleanup_t
#endif /* !LIBVLC_USE_PTHREAD_CLEANUP */
-#ifndef LIBVLC_USE_PTHREAD_CANCEL
/* poll() with cancellation */
-# ifdef __OS2__
-int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout);
-# else
-static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
-{
- int val;
-
- do
- {
- int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
- if (timeout >= 0)
- timeout -= ugly_timeout;
-
- vlc_testcancel ();
- val = poll (fds, nfds, ugly_timeout);
- }
- while (val == 0 && timeout != 0);
-
- return val;
-}
-# endif
+VLC_API int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout);
+#ifndef LIBVLC_USE_PTHREAD_CANCEL
# define poll(u,n,t) vlc_poll(u, n, t)
-
#endif /* LIBVLC_USE_PTHREAD_CANCEL */
static inline void vlc_cleanup_lock (void *lock)
diff --git a/modules/stream_out/standard.c b/modules/stream_out/standard.c
index a386801..da8fe3f 100644
--- a/modules/stream_out/standard.c
+++ b/modules/stream_out/standard.c
@@ -169,13 +169,13 @@ static void create_SDP(sout_stream_t *p_stream, sout_access_out_t *p_access)
if (!vlc_getaddrinfo (dhost, dport, &hints, &res))
{
memcpy (&dst, res->ai_addr, dstlen = res->ai_addrlen);
- freeaddrinfo (res);
+ vlc_freeaddrinfo (res);
}
if (!vlc_getaddrinfo (shost, sport, &hints, &res))
{
memcpy (&src, res->ai_addr, srclen = res->ai_addrlen);
- freeaddrinfo (res);
+ vlc_freeaddrinfo (res);
}
char *head = vlc_sdp_Start (VLC_OBJECT (p_stream), SOUT_CFG_PREFIX,
diff --git a/src/Makefile.am b/src/Makefile.am
index e200669..62fcd21 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -480,6 +480,7 @@ SOURCES_libvlc_common = \
misc/update_crypto.c \
misc/xml.c \
extras/libc.c \
+ extras/poll.c \
extras/tdestroy.c \
misc/addons.c \
misc/filter.c \
diff --git a/src/extras/poll.c b/src/extras/poll.c
new file mode 100644
index 0000000..9f62ca2
--- /dev/null
+++ b/src/extras/poll.c
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * poll.c: poll() replacement function for systems without cancelable poll()
+ *****************************************************************************
+ * Copyright (C) 2014 VLC authors and VideoLAN
+ *
+ * Authors: KO Myung-Hun <komh at chollian.net>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_threads.h>
+
+/* vlc_poll() for OS/2 is in src/os2/thread.c */
+#ifndef __OS2__
+int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
+{
+# ifndef LIBVLC_USE_PTHREAD_CANCEL
+ int val;
+
+ do
+ {
+ int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
+ if (timeout >= 0)
+ timeout -= ugly_timeout;
+
+ vlc_testcancel ();
+ val = (poll) (fds, nfds, ugly_timeout);
+ }
+ while (val == 0 && timeout != 0);
+
+ return val;
+# else
+ return (poll) (fds, nfds, timeout);
+# endif
+}
+#endif
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 10e036a..bf3f83a 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -650,3 +650,5 @@ addons_manager_Remove
addon_entry_New
addon_entry_Hold
addon_entry_Release
+vlc_poll
+vlc_freeaddrinfo
diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c
index 16dd68e..b996175 100644
--- a/src/network/getaddrinfo.c
+++ b/src/network/getaddrinfo.c
@@ -77,7 +77,7 @@ int vlc_getnameinfo( const struct sockaddr *sa, int salen,
* @param res pointer set to the resulting chained list.
* @return 0 on success, a getaddrinfo() error otherwise.
* On failure, *res is undefined. On success, it must be freed with
- * freeaddrinfo().
+ * vlc_freeaddrinfo().
*/
int vlc_getaddrinfo (const char *node, unsigned port,
const struct addrinfo *hints, struct addrinfo **res)
@@ -123,3 +123,8 @@ int vlc_getaddrinfo (const char *node, unsigned port,
return getaddrinfo (node, servname, hints, res);
}
+
+void vlc_freeaddrinfo (struct addrinfo *res)
+{
+ freeaddrinfo (res);
+}
--
1.8.5.2
More information about the vlc-devel
mailing list