aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-19 20:40:33 +0200
committerMax Kellermann <max@duempel.org>2011-09-20 08:35:25 +0200
commitb03f9ece05c6f9a6410da48ec024f9d6bed0dc82 (patch)
tree93a4e566fd407330c039b958ab819d7a3916f6cc
parent1d8840412fc1dd76a73ee13413cd7fc9a6ff229a (diff)
glib_socket.h: wrap g_io_channel_*_new() calls portably
The server_socket library (used by the httpd output plugin) didn't check for WIN32, that's fixed now.
-rw-r--r--Makefile.am1
-rw-r--r--src/client_new.c7
-rw-r--r--src/event_pipe.c7
-rw-r--r--src/glib_socket.h40
-rw-r--r--src/output/httpd_client.c7
-rw-r--r--src/server_socket.c3
6 files changed, 49 insertions, 16 deletions
diff --git a/Makefile.am b/Makefile.am
index 5e6747e6..47861440 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -243,6 +243,7 @@ src_mpd_SOURCES = \
$(OUTPUT_API_SRC) $(OUTPUT_SRC) \
$(MIXER_API_SRC) $(MIXER_SRC) \
$(FILTER_SRC) \
+ src/glib_socket.h \
src/notify.c \
src/audio.c \
src/audio_check.c \
diff --git a/src/client_new.c b/src/client_new.c
index 781a3652..0ee21916 100644
--- a/src/client_new.c
+++ b/src/client_new.c
@@ -22,6 +22,7 @@
#include "fifo_buffer.h"
#include "socket_util.h"
#include "permission.h"
+#include "glib_socket.h"
#include <assert.h>
#include <sys/types.h>
@@ -82,11 +83,7 @@ void client_new(int fd, const struct sockaddr *sa, size_t sa_length, int uid)
client = g_new0(struct client, 1);
-#ifndef G_OS_WIN32
- client->channel = g_io_channel_unix_new(fd);
-#else
- client->channel = g_io_channel_win32_new_socket(fd);
-#endif
+ client->channel = g_io_channel_new_socket(fd);
/* GLib is responsible for closing the file descriptor */
g_io_channel_set_close_on_unref(client->channel, true);
/* NULL encoding means the stream is binary safe; the MPD
diff --git a/src/event_pipe.c b/src/event_pipe.c
index 5b519984..edfd40eb 100644
--- a/src/event_pipe.c
+++ b/src/event_pipe.c
@@ -21,6 +21,7 @@
#include "event_pipe.h"
#include "fd_util.h"
#include "mpd_error.h"
+#include "glib_socket.h"
#include <stdbool.h>
#include <assert.h>
@@ -94,11 +95,7 @@ void event_pipe_init(void)
if (ret < 0)
MPD_ERROR("Couldn't open pipe: %s", strerror(errno));
-#ifndef G_OS_WIN32
- channel = g_io_channel_unix_new(event_pipe[0]);
-#else
- channel = g_io_channel_win32_new_fd(event_pipe[0]);
-#endif
+ channel = g_io_channel_new_socket(event_pipe[0]);
g_io_channel_set_encoding(channel, NULL, NULL);
g_io_channel_set_buffered(channel, false);
diff --git a/src/glib_socket.h b/src/glib_socket.h
new file mode 100644
index 00000000..46fab37d
--- /dev/null
+++ b/src/glib_socket.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#ifndef MPD_GLIB_SOCKET_H
+#define MPD_GLIB_SOCKET_H
+
+#include <glib.h>
+
+/**
+ * Portable wrapper for g_io_channel_unix_new() or
+ * g_io_channel_win32_new_socket().
+ */
+G_GNUC_MALLOC
+static inline GIOChannel *
+g_io_channel_new_socket(int fd)
+{
+#ifdef G_OS_WIN32
+ return g_io_channel_win32_new_socket(fd);
+#else
+ return g_io_channel_unix_new(fd);
+#endif
+}
+
+#endif
diff --git a/src/output/httpd_client.c b/src/output/httpd_client.c
index 1119a783..995c1f65 100644
--- a/src/output/httpd_client.c
+++ b/src/output/httpd_client.c
@@ -24,6 +24,7 @@
#include "page.h"
#include "icy_server.h"
#include "glib_compat.h"
+#include "glib_socket.h"
#include <stdbool.h>
#include <assert.h>
@@ -459,11 +460,7 @@ httpd_client_new(struct httpd_output *httpd, int fd, bool metadata_supported)
client->httpd = httpd;
-#ifndef G_OS_WIN32
- client->channel = g_io_channel_unix_new(fd);
-#else
- client->channel = g_io_channel_win32_new_socket(fd);
-#endif
+ client->channel = g_io_channel_new_socket(fd);
/* GLib is responsible for closing the file descriptor */
g_io_channel_set_close_on_unref(client->channel, true);
diff --git a/src/server_socket.c b/src/server_socket.c
index bb7a6f09..c1074067 100644
--- a/src/server_socket.c
+++ b/src/server_socket.c
@@ -22,6 +22,7 @@
#include "socket_util.h"
#include "fd_util.h"
#include "glib_compat.h"
+#include "glib_socket.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -218,7 +219,7 @@ server_socket_open(struct server_socket *ss, GError **error_r)
/* register in the GLib main loop */
- GIOChannel *channel = g_io_channel_unix_new(s->fd);
+ GIOChannel *channel = g_io_channel_new_socket(s->fd);
s->source_id = g_io_add_watch(channel, G_IO_IN,
server_socket_in_event, s);
g_io_channel_unref(channel);