From dafa53077320a7a39c61a89a7cca1d74797fb92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Thu, 26 Mar 2009 11:32:08 +0100 Subject: dccp: Port DCCP plugin to MinGW Partially fixes bug #573595. --- gst/dccp/Makefile.am | 2 +- gst/dccp/gstdccp.c | 87 ++++++++++++++++++++++++++++++++++++++------ gst/dccp/gstdccp.h | 3 +- gst/dccp/gstdccp_common.h | 40 ++++++++++++++++++++ gst/dccp/gstdccpclientsink.c | 4 -- gst/dccp/gstdccpclientsink.h | 6 +-- gst/dccp/gstdccpclientsrc.c | 5 --- gst/dccp/gstdccpclientsrc.h | 7 +--- gst/dccp/gstdccpserversink.c | 3 -- gst/dccp/gstdccpserversink.h | 7 +--- gst/dccp/gstdccpserversrc.c | 3 -- gst/dccp/gstdccpserversrc.h | 7 +--- 12 files changed, 123 insertions(+), 51 deletions(-) create mode 100644 gst/dccp/gstdccp_common.h (limited to 'gst') diff --git a/gst/dccp/Makefile.am b/gst/dccp/Makefile.am index b276d6e2..a4421c7e 100644 --- a/gst/dccp/Makefile.am +++ b/gst/dccp/Makefile.am @@ -12,7 +12,7 @@ libgstdccp_la_SOURCES = gstdccpplugin.c \ # flags used to compile this plugin libgstdccp_la_CFLAGS = $(GST_CFLAGS) -libgstdccp_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) +libgstdccp_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(DCCP_LIBS) libgstdccp_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstdccp_la_LIBTOOLFLAGS = --tag=disable-static diff --git a/gst/dccp/gstdccp.c b/gst/dccp/gstdccp.c index 48720b4e..443931bb 100644 --- a/gst/dccp/gstdccp.c +++ b/gst/dccp/gstdccp.c @@ -22,14 +22,6 @@ #endif #include "gstdccp.h" -#include -#include -#include -#include -#include -#include -#include -#include #ifdef HAVE_FIONREAD_IN_SYS_FILIO #include @@ -58,7 +50,11 @@ gst_dccp_host_to_ip (GstElement * element, const gchar * host) GST_DEBUG_OBJECT (element, "resolving host %s", host); /* first check if it already is an IP address */ +#ifndef G_OS_WIN32 if (inet_aton (host, &addr)) { +#else + if ((addr.S_un.S_addr = inet_addr (host)) != INADDR_NONE) { +#endif ip = g_strdup (host); GST_DEBUG_OBJECT (element, "resolved to IP %s", ip); return ip; @@ -102,9 +98,13 @@ gst_dccp_read_buffer (GstElement * this, int socket, GstBuffer ** buf) int maxfdp1; int ret; ssize_t bytes_read; +#ifndef G_OS_WIN32 int readsize; struct msghdr mh; struct iovec iov; +#else + unsigned long readsize; +#endif *buf = NULL; @@ -121,9 +121,15 @@ gst_dccp_read_buffer (GstElement * this, int socket, GstBuffer ** buf) } /* ask how much is available for reading on the socket */ +#ifndef G_OS_WIN32 if ((ret = ioctl (socket, FIONREAD, &readsize)) < 0) { GST_ELEMENT_ERROR (this, RESOURCE, READ, (NULL), ("read FIONREAD value failed: %s", g_strerror (errno))); +#else + if ((ret = ioctlsocket (socket, FIONREAD, &readsize)) == SOCKET_ERROR) { + GST_ELEMENT_ERROR (this, RESOURCE, READ, (NULL), + ("read FIONREAD value failed: %s", g_strerror (WSAGetLastError ()))); +#endif return GST_FLOW_ERROR; } @@ -132,8 +138,8 @@ gst_dccp_read_buffer (GstElement * this, int socket, GstBuffer ** buf) return GST_FLOW_UNEXPECTED; } - *buf = gst_buffer_new_and_alloc (readsize); - + *buf = gst_buffer_new_and_alloc ((int) readsize); +#ifndef G_OS_WIN32 memset (&mh, 0, sizeof (mh)); mh.msg_name = NULL; mh.msg_namelen = 0; @@ -143,6 +149,11 @@ gst_dccp_read_buffer (GstElement * this, int socket, GstBuffer ** buf) mh.msg_iovlen = 1; bytes_read = recvmsg (socket, &mh, 0); +#else + bytes_read = + recvfrom (socket, (char *) GST_BUFFER_DATA (*buf), (int) readsize, 0, + NULL, 0); +#endif if (bytes_read != readsize) { GST_DEBUG_OBJECT (this, ("Error while reading data")); @@ -181,9 +192,29 @@ gboolean gst_dccp_connect_to_server (GstElement * element, struct sockaddr_in server_sin, int sock_fd) { +#ifdef G_OS_WIN32 + int errorCode; +#endif GST_DEBUG_OBJECT (element, "connecting to server"); if (connect (sock_fd, (struct sockaddr *) &server_sin, sizeof (server_sin))) { +#ifdef G_OS_WIN32 + errorCode = WSAGetLastError (); + switch (errorCode) { + case WSAECONNREFUSED: + GST_ELEMENT_ERROR (element, RESOURCE, OPEN_WRITE, + ("Connection to %s:%d refused.", inet_ntoa (server_sin.sin_addr), + ntohs (server_sin.sin_port)), (NULL)); + return FALSE; + break; + default: + GST_ELEMENT_ERROR (element, RESOURCE, OPEN_READ, (NULL), + ("Connect to %s:%d failed: %s", inet_ntoa (server_sin.sin_addr), + ntohs (server_sin.sin_port), g_strerror (errorCode))); + return FALSE; + break; + } +#else switch (errno) { case ECONNREFUSED: GST_ELEMENT_ERROR (element, RESOURCE, OPEN_WRITE, @@ -198,6 +229,7 @@ gst_dccp_connect_to_server (GstElement * element, struct sockaddr_in server_sin, return FALSE; break; } +#endif } return TRUE; } @@ -223,7 +255,11 @@ gst_dccp_server_wait_connections (GstElement * element, int server_sock_fd) if ((client_sock_fd = accept (server_sock_fd, (struct sockaddr *) &client_address, +#ifndef G_OS_WIN32 &client_address_len)) == -1) { +#else + (int *) &client_address_len)) == -1) { +#endif GST_ELEMENT_ERROR (element, RESOURCE, OPEN_WRITE, (NULL), ("Could not accept client on server socket %d: %s (%d)", server_sock_fd, g_strerror (errno), errno)); @@ -310,8 +346,10 @@ gst_dccp_socket_write (GstElement * element, int socket, const void *buf, size_t bytes_written = 0; ssize_t wrote; +#ifndef G_OS_WIN32 struct iovec iov; struct msghdr mh; + memset (&mh, 0, sizeof (mh)); while (bytes_written < size) { @@ -325,6 +363,15 @@ gst_dccp_socket_write (GstElement * element, int socket, const void *buf, wrote = sendmsg (socket, &mh, 0); } while (wrote == -1 && errno == EAGAIN); +#else + int errorCode = 0; + while (bytes_written < size) { + do { + wrote = sendto (socket, (char *) buf + bytes_written, + MIN (packet_size, size - bytes_written), 0, NULL, 0); + errorCode = WSAGetLastError (); + } while (wrote == SOCKET_ERROR && errorCode == EAGAIN); +#endif /* TODO print the send error */ bytes_written += wrote; @@ -433,8 +480,14 @@ gst_dccp_set_ccid (GstElement * element, int sock_fd, uint8_t ccid) /* * Determine which CCIDs are available on the host */ +#ifndef G_OS_WIN32 ret = getsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_AVAILABLE_CCIDS, &ccids, &len); +#else + ret = + getsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_AVAILABLE_CCIDS, + (char *) &ccids, &len); +#endif if (ret < 0) { GST_ERROR_OBJECT (element, "Can not determine available CCIDs"); return FALSE; @@ -450,8 +503,11 @@ gst_dccp_set_ccid (GstElement * element, int sock_fd, uint8_t ccid) GST_ERROR_OBJECT (element, "CCID specified is not supported"); return FALSE; } - +#ifndef G_OS_WIN32 if (setsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_CCID, &ccid, +#else + if (setsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_CCID, (char *) &ccid, +#endif sizeof (ccid)) < 0) { GST_ERROR_OBJECT (element, "Can not set CCID"); return FALSE; @@ -481,7 +537,11 @@ gst_dccp_get_ccid (GstElement * element, int sock_fd, int tx_or_rx) } ccidlen = sizeof (ccid); +#ifndef G_OS_WIN32 ret = getsockopt (sock_fd, SOL_DCCP, tx_or_rx, &ccid, &ccidlen); +#else + ret = getsockopt (sock_fd, SOL_DCCP, tx_or_rx, (char *) &ccid, &ccidlen); +#endif if (ret < 0) { GST_ERROR_OBJECT (element, "Can not determine available CCIDs"); return -1; @@ -500,8 +560,13 @@ gst_dccp_get_max_packet_size (GstElement * element, int sock) { int size; socklen_t sizelen = sizeof (size); +#ifndef G_OS_WIN32 if (getsockopt (sock, SOL_DCCP, DCCP_SOCKOPT_GET_CUR_MPS, &size, &sizelen) < 0) { +#else + if (getsockopt (sock, SOL_DCCP, DCCP_SOCKOPT_GET_CUR_MPS, + (char *) &size, &sizelen) < 0) { +#endif GST_ELEMENT_ERROR (element, RESOURCE, SETTINGS, (NULL), ("Could not get current MTU %d: %s", errno, g_strerror (errno))); return -1; diff --git a/gst/dccp/gstdccp.h b/gst/dccp/gstdccp.h index f5aa2ccc..74d19523 100644 --- a/gst/dccp/gstdccp.h +++ b/gst/dccp/gstdccp.h @@ -22,8 +22,7 @@ #include #include -#include -#include /* sockaddr_in */ +#include "gstdccp_common.h" /* DCCP socket general options */ #define DCCP_BACKLOG 5 diff --git a/gst/dccp/gstdccp_common.h b/gst/dccp/gstdccp_common.h new file mode 100644 index 00000000..96578061 --- /dev/null +++ b/gst/dccp/gstdccp_common.h @@ -0,0 +1,40 @@ +/* GStreamer + * Copyright (C) <2007> Leandro Melo de Sales + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_DCCP_NET_H__ +#define __GST_DCCP_NET_H__ + +#ifndef G_OS_WIN32 +# include +# include +# include /* sockaddr_in */ +# include +# include +#else +/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later. + * minwg32 headers check WINVER before allowing the use of these */ +# define WINVER 0x0501 +# include +# include +#endif +#include +#include +#include + +#endif /* __GST_DCCP_NET_H__ */ diff --git a/gst/dccp/gstdccpclientsink.c b/gst/dccp/gstdccpclientsink.c index 348a0b87..4c1fd50f 100644 --- a/gst/dccp/gstdccpclientsink.c +++ b/gst/dccp/gstdccpclientsink.c @@ -50,10 +50,6 @@ #include "gstdccpclientsink.h" #include "gstdccp.h" -#include /* memset */ -#include -#include -#include /* signals */ enum diff --git a/gst/dccp/gstdccpclientsink.h b/gst/dccp/gstdccpclientsink.h index 89f7d5e7..2a6fb2a6 100644 --- a/gst/dccp/gstdccpclientsink.h +++ b/gst/dccp/gstdccpclientsink.h @@ -26,11 +26,7 @@ G_BEGIN_DECLS -#include /* sockaddr_in */ -#include -#include -#include /* sockaddr_in */ -#include +#include "gstdccp_common.h" #define GST_TYPE_DCCP_CLIENT_SINK \ (gst_dccp_client_sink_get_type()) diff --git a/gst/dccp/gstdccpclientsrc.c b/gst/dccp/gstdccpclientsrc.c index 73f45eb3..4cb33e7c 100644 --- a/gst/dccp/gstdccpclientsrc.c +++ b/gst/dccp/gstdccpclientsrc.c @@ -51,12 +51,7 @@ #include "gstdccpclientsrc.h" #include "gstdccp.h" -#include /* memset */ -#include -#include #include - -#include #ifdef HAVE_FIONREAD_IN_SYS_FILIO #include #endif diff --git a/gst/dccp/gstdccpclientsrc.h b/gst/dccp/gstdccpclientsrc.h index 9be42b2d..8a592732 100644 --- a/gst/dccp/gstdccpclientsrc.h +++ b/gst/dccp/gstdccpclientsrc.h @@ -26,12 +26,7 @@ G_BEGIN_DECLS -#include /* sockaddr_in */ -#include -#include -#include /* sockaddr_in */ -#include - +#include "gstdccp_common.h" #define GST_TYPE_DCCP_CLIENT_SRC \ (gst_dccp_client_src_get_type()) diff --git a/gst/dccp/gstdccpserversink.c b/gst/dccp/gstdccpserversink.c index e2a77822..e8f8a04f 100644 --- a/gst/dccp/gstdccpserversink.c +++ b/gst/dccp/gstdccpserversink.c @@ -51,9 +51,6 @@ #include "gstdccpserversink.h" #include "gstdccp.h" -#include /* memset */ -#include -#include #include /* signals */ diff --git a/gst/dccp/gstdccpserversink.h b/gst/dccp/gstdccpserversink.h index 0b2623ad..e4294a13 100644 --- a/gst/dccp/gstdccpserversink.h +++ b/gst/dccp/gstdccpserversink.h @@ -26,11 +26,8 @@ G_BEGIN_DECLS -#include /* sockaddr_in */ -#include -#include -#include /* sockaddr_in */ -#include + +#include "gstdccp_common.h" #include #define GST_TYPE_DCCP_SERVER_SINK \ diff --git a/gst/dccp/gstdccpserversrc.c b/gst/dccp/gstdccpserversrc.c index 93068bc6..4c344e42 100644 --- a/gst/dccp/gstdccpserversrc.c +++ b/gst/dccp/gstdccpserversrc.c @@ -50,9 +50,6 @@ #include "gstdccpserversrc.h" #include "gstdccp.h" -#include /* memset */ -#include -#include #include #define DCCP_DEFAULT_CAPS NULL diff --git a/gst/dccp/gstdccpserversrc.h b/gst/dccp/gstdccpserversrc.h index e0dd3f16..6c4c224b 100644 --- a/gst/dccp/gstdccpserversrc.h +++ b/gst/dccp/gstdccpserversrc.h @@ -26,12 +26,7 @@ G_BEGIN_DECLS -#include /* sockaddr_in */ -#include -#include -#include /* sockaddr_in */ -#include - +#include "gstdccp_common.h" #define GST_TYPE_DCCP_SERVER_SRC \ (gst_dccp_server_src_get_type()) -- cgit v1.2.1