Commit 405571a6 authored by Peter Kjellerstedt's avatar Peter Kjellerstedt Committed by Wim Taymans

gst/tcp/: Removed fdset and stress test, they are now known as GstPoll in core.

Original commit message from CVS:
Patch by: Peter Kjellerstedt  <pkj at axis com>
* gst/tcp/Makefile.am:
* gst/tcp/fdsetstress.c:
* gst/tcp/gstfdset.c:
* gst/tcp/gstfdset.h:
Removed fdset and stress test, they are now known as GstPoll in
core.
* gst/tcp/gstmultifdsink.c: (gst_multi_fd_sink_class_init),
(gst_multi_fd_sink_add_full), (gst_multi_fd_sink_remove),
(gst_multi_fd_sink_clear), (gst_multi_fd_sink_remove_client_link),
(gst_multi_fd_sink_handle_client_write),
(gst_multi_fd_sink_queue_buffer),
(gst_multi_fd_sink_handle_clients), (gst_multi_fd_sink_start),
(gst_multi_fd_sink_stop):
* gst/tcp/gstmultifdsink.h:
* gst/tcp/gsttcp.c: (gst_tcp_socket_read), (gst_tcp_socket_close),
(gst_tcp_read_buffer), (gst_tcp_gdp_read_buffer),
(gst_tcp_gdp_read_caps):
* gst/tcp/gsttcp.h:
* gst/tcp/gsttcpclientsink.c: (gst_tcp_client_sink_init),
(gst_tcp_client_sink_setcaps), (gst_tcp_client_sink_render),
(gst_tcp_client_sink_start), (gst_tcp_client_sink_stop):
* gst/tcp/gsttcpclientsink.h:
* gst/tcp/gsttcpclientsrc.c: (gst_tcp_client_src_init),
(gst_tcp_client_src_create), (gst_tcp_client_src_start),
(gst_tcp_client_src_stop), (gst_tcp_client_src_unlock):
* gst/tcp/gsttcpclientsrc.h:
* gst/tcp/gsttcpserversink.c: (gst_tcp_server_sink_handle_wait),
(gst_tcp_server_sink_init_send), (gst_tcp_server_sink_close):
* gst/tcp/gsttcpserversink.h:
* gst/tcp/gsttcpserversrc.c: (gst_tcp_server_src_init),
(gst_tcp_server_src_create), (gst_tcp_server_src_start),
(gst_tcp_server_src_stop), (gst_tcp_server_src_unlock):
* gst/tcp/gsttcpserversrc.h:
Port to GstPoll. See #505417.
parent 45e039dd
2008-02-28 Wim Taymans <wim.taymans@collabora.co.uk>
Patch by: Peter Kjellerstedt <pkj at axis com>
* gst/tcp/Makefile.am:
* gst/tcp/fdsetstress.c:
* gst/tcp/gstfdset.c:
* gst/tcp/gstfdset.h:
Removed fdset and stress test, they are now known as GstPoll in
core.
* gst/tcp/gstmultifdsink.c: (gst_multi_fd_sink_class_init),
(gst_multi_fd_sink_add_full), (gst_multi_fd_sink_remove),
(gst_multi_fd_sink_clear), (gst_multi_fd_sink_remove_client_link),
(gst_multi_fd_sink_handle_client_write),
(gst_multi_fd_sink_queue_buffer),
(gst_multi_fd_sink_handle_clients), (gst_multi_fd_sink_start),
(gst_multi_fd_sink_stop):
* gst/tcp/gstmultifdsink.h:
* gst/tcp/gsttcp.c: (gst_tcp_socket_read), (gst_tcp_socket_close),
(gst_tcp_read_buffer), (gst_tcp_gdp_read_buffer),
(gst_tcp_gdp_read_caps):
* gst/tcp/gsttcp.h:
* gst/tcp/gsttcpclientsink.c: (gst_tcp_client_sink_init),
(gst_tcp_client_sink_setcaps), (gst_tcp_client_sink_render),
(gst_tcp_client_sink_start), (gst_tcp_client_sink_stop):
* gst/tcp/gsttcpclientsink.h:
* gst/tcp/gsttcpclientsrc.c: (gst_tcp_client_src_init),
(gst_tcp_client_src_create), (gst_tcp_client_src_start),
(gst_tcp_client_src_stop), (gst_tcp_client_src_unlock):
* gst/tcp/gsttcpclientsrc.h:
* gst/tcp/gsttcpserversink.c: (gst_tcp_server_sink_handle_wait),
(gst_tcp_server_sink_init_send), (gst_tcp_server_sink_close):
* gst/tcp/gsttcpserversink.h:
* gst/tcp/gsttcpserversrc.c: (gst_tcp_server_src_init),
(gst_tcp_server_src_create), (gst_tcp_server_src_start),
(gst_tcp_server_src_stop), (gst_tcp_server_src_unlock):
* gst/tcp/gsttcpserversrc.h:
Port to GstPoll. See #505417.
2008-02-28 Wim Taymans <wim.taymans@collabora.co.uk>
Patch by: Peter Kjellerstedt <pkj at axis com>
......@@ -15,7 +15,6 @@ BUILT_SOURCES = $(built_sources) $(built_headers)
libgsttcp_la_SOURCES = \
gsttcpplugin.c \
gsttcp.c \
gstfdset.c \
gstmultifdsink.c \
gsttcpclientsrc.c gsttcpclientsink.c \
gsttcpserversrc.c gsttcpserversink.c
......@@ -31,7 +30,6 @@ libgsttcp_la_LIBADD = $(GST_BASE_LIBS) $(GST_GDP_LIBS) $(GST_LIBS)
noinst_HEADERS = \
gsttcpplugin.h \
gsttcp.h \
gstfdset.h \
gstmultifdsink.h \
gsttcpclientsrc.h gsttcpclientsink.h \
gsttcpserversrc.h gsttcpserversink.h
......@@ -39,9 +37,3 @@ noinst_HEADERS = \
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = gsttcp-marshal.list
noinst_PROGRAMS = fdsetstress
fdsetstress_SOURCES = fdsetstress.c gstfdset.c
fdsetstress_CFLAGS = $(GST_CFLAGS)
fdsetstress_LDFLAGS = $(GST_LIBS)
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
*
* 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.
*/
#include <stdlib.h>
#include <gst/gst.h>
#include "gstfdset.h"
static GstFDSet *set;
static GList *fds = NULL;
static GMutex *fdlock;
static GTimer *timer;
#define MAX_THREADS 100
static void
mess_some_more ()
{
GList *walk;
gint random;
gint removed = 0;
g_mutex_lock (fdlock);
for (walk = fds; walk;) {
GstFD *fd = (GstFD *) walk->data;
walk = g_list_next (walk);
random = (gint) (10.0 * rand () / (RAND_MAX + 1.0));
switch (random) {
case 0:
{
/*
GstFD *newfd = g_new0 (GstFD, 1);
gst_fdset_add_fd (set, newfd);
fds = g_list_prepend (fds, newfd);
*/
break;
}
case 1:
if ((gint) (10.0 * rand () / (RAND_MAX + 1.0)) < 2) {
gst_fdset_remove_fd (set, fd);
fds = g_list_remove (fds, fd);
g_free (fd);
removed++;
}
break;
case 2:
gst_fdset_fd_ctl_write (set, fd, TRUE);
break;
case 3:
gst_fdset_fd_ctl_write (set, fd, FALSE);
break;
case 4:
gst_fdset_fd_ctl_read (set, fd, TRUE);
break;
case 5:
gst_fdset_fd_ctl_read (set, fd, FALSE);
break;
case 6:
gst_fdset_fd_has_closed (set, fd);
break;
case 7:
gst_fdset_fd_has_error (set, fd);
break;
case 8:
gst_fdset_fd_can_read (set, fd);
break;
case 9:
gst_fdset_fd_can_write (set, fd);
break;
default:
g_assert_not_reached ();
break;
}
}
if (g_list_length (fds) < 900) {
random = removed + (gint) (2.0 * rand () / (RAND_MAX + 1.0));
while (random) {
GstFD *newfd = g_new0 (GstFD, 1);
gst_fdset_add_fd (set, newfd);
fds = g_list_prepend (fds, newfd);
random--;
}
}
g_mutex_unlock (fdlock);
}
void *
run_test (void *threadid)
{
gint id = GPOINTER_TO_INT (threadid);
while (TRUE) {
if (id == 0) {
gint res = gst_fdset_wait (set, 10);
if (res < 0) {
g_print ("error %d %s\n", errno, g_strerror (errno));
}
} else {
mess_some_more ();
if (g_timer_elapsed (timer, NULL) > 0.5) {
g_mutex_lock (fdlock);
g_print ("active fds :%d\n", g_list_length (fds));
g_timer_start (timer);
g_mutex_unlock (fdlock);
}
g_usleep (1);
}
}
g_thread_exit (NULL);
return NULL;
}
gint
main (gint argc, gchar * argv[])
{
GThread *threads[MAX_THREADS];
gint num_threads;
gint t;
gst_init (&argc, &argv);
fdlock = g_mutex_new ();
timer = g_timer_new ();
if (argc != 2) {
g_print ("usage: %s <num_threads>\n", argv[0]);
exit (-1);
}
num_threads = atoi (argv[1]);
set = gst_fdset_new (GST_FDSET_MODE_POLL);
for (t = 0; t < num_threads; t++) {
GError *error = NULL;
threads[t] = g_thread_create (run_test, GINT_TO_POINTER (t), TRUE, &error);
if (error) {
printf ("ERROR: g_thread_create() %s\n", error->message);
exit (-1);
}
}
printf ("main(): Created %d threads.\n", t);
for (t = 0; t < num_threads; t++) {
g_thread_join (threads[t]);
}
gst_fdset_free (set);
return 0;
}
This diff is collapsed.
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2004> Wim Taymans <wim@fluendo.com>
*
* gstfdset.h: fdset datastructure
*
* 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_FDSET_H__
#define __GST_FDSET_H__
#include <gst/gst.h>
G_BEGIN_DECLS
typedef struct _GstFDSet GstFDSet;
typedef struct {
int fd;
gint idx;
} GstFD;
typedef enum {
GST_FDSET_MODE_SELECT,
GST_FDSET_MODE_POLL,
GST_FDSET_MODE_EPOLL
} GstFDSetMode;
#define GST_TYPE_FDSET_MODE (gst_fdset_mode_get_type())
GType gst_fdset_mode_get_type (void);
GstFDSet* gst_fdset_new (GstFDSetMode mode);
void gst_fdset_free (GstFDSet *set);
void gst_fdset_set_mode (GstFDSet *set, GstFDSetMode mode);
GstFDSetMode gst_fdset_get_mode (GstFDSet *set);
gboolean gst_fdset_add_fd (GstFDSet *set, GstFD *fd);
gboolean gst_fdset_remove_fd (GstFDSet *set, GstFD *fd);
void gst_fdset_fd_ctl_write (GstFDSet *set, GstFD *fd, gboolean active);
void gst_fdset_fd_ctl_read (GstFDSet *set, GstFD *fd, gboolean active);
gboolean gst_fdset_fd_has_closed (GstFDSet *set, GstFD *fd);
gboolean gst_fdset_fd_has_error (GstFDSet *set, GstFD *fd);
gboolean gst_fdset_fd_can_read (GstFDSet *set, GstFD *fd);
gboolean gst_fdset_fd_can_write (GstFDSet *set, GstFD *fd);
gint gst_fdset_wait (GstFDSet *set, int timeout);
G_END_DECLS
#endif /* __GST_FDSET_H__ */
This diff is collapsed.
......@@ -28,7 +28,6 @@
G_BEGIN_DECLS
#include "gsttcp.h"
#include "gstfdset.h"
#define GST_TYPE_MULTI_FD_SINK \
(gst_multi_fd_sink_get_type())
......@@ -140,7 +139,7 @@ typedef enum
/* structure for a client
*/
typedef struct {
GstFD fd;
GstPollFD fd;
gint bufpos; /* position of this client in the global queue */
gint flushcount; /* the remaining number of buffers to flush out or -1 if the
......@@ -201,10 +200,8 @@ struct _GstMultiFdSink {
GHashTable *fd_hash; /* index on fd to client */
guint clients_cookie; /* Cookie to detect changes to the clients list */
GstFDSetMode mode;
GstFDSet *fdset;
GstFD control_sock[2];/* sockets for controlling the select call */
GstPollMode mode;
GstPoll *fdset;
GSList *streamheader; /* GSList of GstBuffers to use as streamheader */
gboolean previous_buffer_in_caps;
......@@ -259,7 +256,7 @@ struct _GstMultiFdSinkClass {
/* vtable */
gboolean (*init) (GstMultiFdSink *sink);
gboolean (*wait) (GstMultiFdSink *sink, GstFDSet *set);
gboolean (*wait) (GstMultiFdSink *sink, GstPoll *set);
gboolean (*close) (GstMultiFdSink *sink);
void (*removed) (GstMultiFdSink *sink, int fd);
......
......@@ -29,7 +29,6 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <string.h> /* memset, in FD_ZERO macro */
#include <unistd.h>
#include <sys/ioctl.h>
......@@ -128,30 +127,24 @@ gst_tcp_socket_write (int socket, const void *buf, size_t count)
*/
static GstFlowReturn
gst_tcp_socket_read (GstElement * this, int socket, void *buf, size_t count,
int cancel_fd)
GstPoll * fdset)
{
fd_set testfds;
int maxfdp1;
ssize_t n;
size_t bytes_read;
int num_to_read;
int ret;
bytes_read = 0;
while (bytes_read < count) {
/* do a blocking select on the socket */
FD_ZERO (&testfds);
FD_SET (socket, &testfds);
if (cancel_fd >= 0)
FD_SET (cancel_fd, &testfds);
maxfdp1 = MAX (socket, cancel_fd) + 1;
/* no action (0) is an error too in our case */
if (select (maxfdp1, &testfds, NULL, NULL, 0) <= 0)
goto select_error;
if (cancel_fd >= 0 && FD_ISSET (cancel_fd, &testfds))
goto cancelled;
if ((ret = gst_poll_wait (fdset, GST_CLOCK_TIME_NONE)) <= 0) {
if (ret == -1 && errno == EBUSY)
goto cancelled;
else
goto select_error;
}
/* ask how much is available for reading on the socket */
if (ioctl (socket, FIONREAD, &num_to_read) < 0)
......@@ -216,10 +209,12 @@ short_read:
/* close the socket and reset the fd. Used to clean up after errors. */
void
gst_tcp_socket_close (int *socket)
gst_tcp_socket_close (GstPollFD * socket)
{
close (*socket);
*socket = -1;
if (socket->fd >= 0) {
close (socket->fd);
socket->fd = -1;
}
}
/* read a buffer from the given socket
......@@ -229,30 +224,23 @@ gst_tcp_socket_close (int *socket)
* EOS
*/
GstFlowReturn
gst_tcp_read_buffer (GstElement * this, int socket, int cancel_fd,
gst_tcp_read_buffer (GstElement * this, int socket, GstPoll * fdset,
GstBuffer ** buf)
{
fd_set testfds;
int ret;
int maxfdp1;
ssize_t bytes_read;
int readsize;
*buf = NULL;
/* do a blocking select on the socket */
FD_ZERO (&testfds);
FD_SET (socket, &testfds);
if (cancel_fd >= 0)
FD_SET (cancel_fd, &testfds);
maxfdp1 = MAX (socket, cancel_fd) + 1;
/* no action (0) is an error too in our case */
if ((ret = select (maxfdp1, &testfds, NULL, NULL, 0)) <= 0)
goto select_error;
if (cancel_fd >= 0 && FD_ISSET (cancel_fd, &testfds))
goto cancelled;
if ((ret = gst_poll_wait (fdset, GST_CLOCK_TIME_NONE)) <= 0) {
if (ret == -1 && errno == EBUSY)
goto cancelled;
else
goto select_error;
}
/* ask how much is available for reading on the socket */
if ((ret = ioctl (socket, FIONREAD, &readsize)) < 0)
......@@ -326,7 +314,7 @@ short_read:
* EOS
*/
GstFlowReturn
gst_tcp_gdp_read_buffer (GstElement * this, int socket, int cancel_fd,
gst_tcp_gdp_read_buffer (GstElement * this, int socket, GstPoll * fdset,
GstBuffer ** buf)
{
GstFlowReturn ret;
......@@ -338,8 +326,7 @@ gst_tcp_gdp_read_buffer (GstElement * this, int socket, int cancel_fd,
*buf = NULL;
header = g_malloc (GST_DP_HEADER_LENGTH);
ret = gst_tcp_socket_read (this, socket, header, GST_DP_HEADER_LENGTH,
cancel_fd);
ret = gst_tcp_socket_read (this, socket, header, GST_DP_HEADER_LENGTH, fdset);
if (ret != GST_FLOW_OK)
goto header_read_error;
......@@ -357,7 +344,7 @@ gst_tcp_gdp_read_buffer (GstElement * this, int socket, int cancel_fd,
g_free (header);
ret = gst_tcp_socket_read (this, socket, GST_BUFFER_DATA (*buf),
GST_BUFFER_SIZE (*buf), cancel_fd);
GST_BUFFER_SIZE (*buf), fdset);
if (ret != GST_FLOW_OK)
goto data_read_error;
......@@ -394,7 +381,7 @@ data_read_error:
}
GstFlowReturn
gst_tcp_gdp_read_caps (GstElement * this, int socket, int cancel_fd,
gst_tcp_gdp_read_caps (GstElement * this, int socket, GstPoll * fdset,
GstCaps ** caps)
{
GstFlowReturn ret;
......@@ -408,8 +395,7 @@ gst_tcp_gdp_read_caps (GstElement * this, int socket, int cancel_fd,
*caps = NULL;
header = g_malloc (GST_DP_HEADER_LENGTH);
ret = gst_tcp_socket_read (this, socket, header, GST_DP_HEADER_LENGTH,
cancel_fd);
ret = gst_tcp_socket_read (this, socket, header, GST_DP_HEADER_LENGTH, fdset);
if (ret != GST_FLOW_OK)
goto header_read_error;
......@@ -429,7 +415,7 @@ gst_tcp_gdp_read_caps (GstElement * this, int socket, int cancel_fd,
"Reading %" G_GSIZE_FORMAT " bytes for caps packet payload",
payload_length);
ret = gst_tcp_socket_read (this, socket, payload, payload_length, cancel_fd);
ret = gst_tcp_socket_read (this, socket, payload, payload_length, fdset);
if (ret != GST_FLOW_OK)
goto payload_read_error;
......
......@@ -44,14 +44,14 @@ gchar * gst_tcp_host_to_ip (GstElement *element, const gchar *host);
gint gst_tcp_socket_write (int socket, const void *buf, size_t count);
void gst_tcp_socket_close (int *socket);
void gst_tcp_socket_close (GstPollFD *socket);
GstFlowReturn gst_tcp_read_buffer (GstElement * this, int socket, int cancel_fd, GstBuffer **buf);
GstFlowReturn gst_tcp_read_buffer (GstElement * this, int socket, GstPoll * fdset, GstBuffer **buf);
GstFlowReturn gst_tcp_gdp_read_buffer (GstElement * this, int socket, int cancel_fd, GstBuffer **buf);
GstFlowReturn gst_tcp_gdp_read_caps (GstElement * this, int socket, int cancel_fd, GstCaps **caps);
GstFlowReturn gst_tcp_gdp_read_buffer (GstElement * this, int socket, GstPoll * fdset, GstBuffer **buf);
GstFlowReturn gst_tcp_gdp_read_caps (GstElement * this, int socket, GstPoll * fdset, GstCaps **caps);
GstEvent * gst_tcp_gdp_read_event (GstElement *elem, int socket, int cancel_fd);
GstEvent * gst_tcp_gdp_read_event (GstElement *elem, int socket, GstPoll * fdset);
gboolean gst_tcp_gdp_write_buffer (GstElement *elem, int socket, GstBuffer *buffer, gboolean fatal, const gchar *host, int port);
gboolean gst_tcp_gdp_write_event (GstElement *elem, int socket, GstEvent *event, gboolean fatal, const gchar *host, int port);
......
......@@ -160,7 +160,7 @@ gst_tcp_client_sink_init (GstTCPClientSink * this)
this->host = g_strdup (TCP_DEFAULT_HOST);
this->port = TCP_DEFAULT_PORT;
this->sock_fd = -1;
this->sock_fd.fd = -1;
this->protocol = GST_TCP_PROTOCOL_NONE;
GST_OBJECT_FLAG_UNSET (this, GST_TCP_CLIENT_SINK_OPEN);
}
......@@ -198,8 +198,8 @@ gst_tcp_client_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
GST_DEBUG_OBJECT (sink, "Sending caps %s through GDP", string);
g_free (string);
if (!gst_tcp_gdp_write_caps (GST_ELEMENT (sink), sink->sock_fd, caps,
TRUE, sink->host, sink->port))
if (!gst_tcp_gdp_write_caps (GST_ELEMENT (sink), sink->sock_fd.fd,
caps, TRUE, sink->host, sink->port))
goto gdp_write_error;
sink->caps_sent = TRUE;
......@@ -241,7 +241,7 @@ gst_tcp_client_sink_render (GstBaseSink * bsink, GstBuffer * buf)
break;
case GST_TCP_PROTOCOL_GDP:
GST_LOG_OBJECT (sink, "Sending buffer header through GDP");
if (!gst_tcp_gdp_write_buffer (GST_ELEMENT (sink), sink->sock_fd, buf,
if (!gst_tcp_gdp_write_buffer (GST_ELEMENT (sink), sink->sock_fd.fd, buf,
TRUE, sink->host, sink->port))
goto gdp_write_error;
break;
......@@ -250,7 +250,7 @@ gst_tcp_client_sink_render (GstBaseSink * bsink, GstBuffer * buf)
}
/* write buffer data */
wrote = gst_tcp_socket_write (sink->sock_fd, GST_BUFFER_DATA (buf), size);
wrote = gst_tcp_socket_write (sink->sock_fd.fd, GST_BUFFER_DATA (buf), size);
if (wrote < size)
goto write_error;
......@@ -348,12 +348,12 @@ gst_tcp_client_sink_start (GstTCPClientSink * this)
/* create sending client socket */
GST_DEBUG_OBJECT (this, "opening sending client socket to %s:%d", this->host,
this->port);
if ((this->sock_fd = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
if ((this->sock_fd.fd = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_WRITE, (NULL), GST_ERROR_SYSTEM);
return FALSE;
}
GST_DEBUG_OBJECT (this, "opened sending client socket with fd %d",
this->sock_fd);
this->sock_fd.fd);
/* look up name if we need to */
ip = gst_tcp_host_to_ip (GST_ELEMENT (this), this->host);
......@@ -371,7 +371,7 @@ gst_tcp_client_sink_start (GstTCPClientSink * this)
g_free (ip);
GST_DEBUG_OBJECT (this, "connecting to server");
ret = connect (this->sock_fd, (struct sockaddr *) &this->server_sin,
ret = connect (this->sock_fd.fd, (struct sockaddr *) &this->server_sin,
sizeof (this->server_sin));
if (ret) {
......@@ -405,10 +405,7 @@ gst_tcp_client_sink_stop (GstTCPClientSink * this)
if (!GST_OBJECT_FLAG_IS_SET (this, GST_TCP_CLIENT_SINK_OPEN))
return TRUE;
if (this->sock_fd != -1) {
close (this->sock_fd);
this->sock_fd = -1;
}
gst_tcp_socket_close (&this->sock_fd);
GST_OBJECT_FLAG_UNSET (this, GST_TCP_CLIENT_SINK_OPEN);
......
......@@ -73,7 +73,7 @@ struct _GstTCPClientSink {
struct sockaddr_in server_sin;
/* socket */
int sock_fd;
GstPollFD sock_fd;
size_t data_written; /* how much bytes have we written ? */
GstTCPProtocol protocol; /* used with the protocol enum */
......
......@@ -32,24 +32,6 @@
#include <fcntl.h>
/* control stuff stolen from fdsrc */
#define CONTROL_STOP 'S' /* stop the select call */
#define CONTROL_SOCKETS(o) o->control_fds
#define WRITE_SOCKET(o) o->control_fds[1]
#define READ_SOCKET(o) o->control_fds[0]
#define SEND_COMMAND(o, command) \
G_STMT_START { \
unsigned char c; c = command; \
write (WRITE_SOCKET(o), &c, 1); \
} G_STMT_END
#define READ_COMMAND(o, command, res) \
G_STMT_START { \
res = read(READ_SOCKET(o), &command, 1); \
} G_STMT_END
GST_DEBUG_CATEGORY_STATIC (tcpclientsrc_debug);
#define GST_CAT_DEFAULT tcpclientsrc_debug
......@@ -150,13 +132,10 @@ gst_tcp_client_src_init (GstTCPClientSrc * this, GstTCPClientSrcClass * g_class)
{
this->port = TCP_DEFAULT_PORT;
this->host = g_strdup (TCP_DEFAULT_HOST);
this->sock_fd = -1;
this->sock_fd.fd = -1;
this->protocol = GST_TCP_PROTOCOL_NONE;
this->caps = NULL;
READ_SOCKET (this) = -1;
WRITE_SOCKET (this) = -1;
gst_base_src_set_live (GST_BASE_SRC (this), TRUE);
GST_OBJECT_FLAG_UNSET (this, GST_TCP_CLIENT_SRC_OPEN);
......@@ -207,8 +186,8 @@ gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
/* read the buffer header if we're using a protocol */
switch (src->protocol) {
case GST_TCP_PROTOCOL_NONE:
ret = gst_tcp_read_buffer (GST_ELEMENT (src), src->sock_fd,
READ_SOCKET (src), outbuf);
ret = gst_tcp_read_buffer (GST_ELEMENT (src), src->sock_fd.fd,
src->fdset, outbuf);
break;
case GST_TCP_PROTOCOL_GDP:
......@@ -217,8 +196,8 @@ gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
GstCaps *caps;
GST_DEBUG_OBJECT (src, "getting caps through GDP");
ret = gst_tcp_gdp_read_caps (GST_ELEMENT (src), src->sock_fd,
READ_SOCKET (src), &caps);
ret = gst_tcp_gdp_read_caps (GST_ELEMENT (src), src->sock_fd.fd,
src->fdset, &caps);
if (ret != GST_FLOW_OK)
goto no_caps;
......@@ -227,8 +206,8 @@ gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
src->caps = caps;
}
ret = gst_tcp_gdp_read_buffer (GST_ELEMENT (src), src->sock_fd,
READ_SOCKET (src), outbuf);
ret = gst_tcp_gdp_read_buffer (GST_ELEMENT (src), src->sock_fd.fd,
src->fdset, outbuf);
break;
default:
/* need to assert as buf == NULL */
......@@ -323,22 +302,18 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
gchar *ip;
GstTCPClientSrc *src = GST_TCP_CLIENT_SRC (bsrc);
/* create the control sockets before anything */
if (socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (src)) < 0)
if ((src->fdset = gst_poll_new (GST_POLL_MODE_AUTO, TRUE)) == NULL)
goto socket_pair;
fcntl (READ_SOCKET (src), F_SETFL, O_NONBLOCK);
fcntl (WRITE_SOCKET (src), F_SETFL, O_NONBLOCK);
/* create receiving client socket */
GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d",
src->host, src->port);
if ((src->sock_fd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
if ((src->sock_fd.fd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
goto no_socket;
GST_DEBUG_OBJECT (src, "opened receiving client socket with fd %d",
src->sock_fd);
src->sock_fd.fd);
GST_OBJECT_FLAG_SET (src, GST_TCP_CLIENT_SRC_OPEN);
/* look up name if we need to */
......@@ -355,7 +330,7 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
g_free (ip);
GST_DEBUG_OBJECT (src, "connecting to server");
ret = connect (src->sock_fd, (struct sockaddr *) &src->server_sin,
ret = connect (src->sock_fd.fd, (struct sockaddr *) &src->server_sin,
sizeof (src->server_sin));
if (ret) {
......@@ -406,10 +381,13 @@ gst_tcp_client_src_stop (GstBaseSrc * bsrc)
src = GST_TCP_CLIENT_SRC (bsrc);
GST_DEBUG_OBJECT (src, "closing socket");
if (src->sock_fd != -1) {
close (src->sock_fd);
src->sock_fd = -1;