gst/tcp/: Fix regression in clientsrc because we did not add the fd to the poll set anymore. Fixes #532364.

Original commit message from CVS:
Patch by: Hannes Bistry <hannesb at gmx dot de>
* gst/tcp/gsttcpclientsrc.c: (gst_tcp_client_src_start):
* gst/tcp/gsttcpserversink.c:
(gst_tcp_server_sink_handle_server_read),
(gst_tcp_server_sink_handle_wait), (gst_tcp_server_sink_init_send):
Fix regression in clientsrc because we did not add the fd to the poll
set anymore. Fixes #532364.
Do some cleanups here and there.
This commit is contained in:
Hannes Bistry 2008-05-13 16:02:19 +00:00 committed by Wim Taymans
parent 05349cc354
commit b9bc12afd8
3 changed files with 107 additions and 61 deletions

View file

@ -1,3 +1,15 @@
2008-05-13 Wim Taymans <wim.taymans@collabora.co.uk>
Patch by: Hannes Bistry <hannesb at gmx dot de>
* gst/tcp/gsttcpclientsrc.c: (gst_tcp_client_src_start):
* gst/tcp/gsttcpserversink.c:
(gst_tcp_server_sink_handle_server_read),
(gst_tcp_server_sink_handle_wait), (gst_tcp_server_sink_init_send):
Fix regression in clientsrc because we did not add the fd to the poll
set anymore. Fixes #532364.
Do some cleanups here and there.
2008-05-13 Sebastian Dröge <slomo@circular-chaos.org>
* gst/playback/gstdecodebin.c: (gst_decode_bin_class_init):

View file

@ -334,23 +334,12 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
GST_DEBUG_OBJECT (src, "connecting to server");
ret = connect (src->sock_fd.fd, (struct sockaddr *) &src->server_sin,
sizeof (src->server_sin));
if (ret)
goto connect_failed;
if (ret) {
gst_tcp_client_src_stop (GST_BASE_SRC (src));
switch (errno) {
case ECONNREFUSED:
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
(_("Connection to %s:%d refused."), src->host, src->port), (NULL));
return FALSE;
break;
default:
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
("connect to %s:%d failed: %s", src->host, src->port,
g_strerror (errno)));
return FALSE;
break;
}
}
/* add the socket to the poll */
gst_poll_add_fd (src->fdset, &src->sock_fd);
gst_poll_fd_ctl_read (src->fdset, &src->sock_fd, TRUE);
return TRUE;
@ -370,6 +359,22 @@ name_resolv:
gst_tcp_client_src_stop (GST_BASE_SRC (src));
return FALSE;
}
connect_failed:
{
gst_tcp_client_src_stop (GST_BASE_SRC (src));
switch (errno) {
case ECONNREFUSED:
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
(_("Connection to %s:%d refused."), src->host, src->port), (NULL));
break;
default:
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
("connect to %s:%d failed: %s", src->host, src->port,
g_strerror (errno)));
break;
}
return FALSE;
}
}
/* close the socket and associated resources

View file

@ -155,12 +155,8 @@ gst_tcp_server_sink_handle_server_read (GstTCPServerSink * sink)
client_sock_fd =
accept (sink->server_sock.fd, (struct sockaddr *) &client_address,
&client_address_len);
if (client_sock_fd == -1) {
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL),
("Could not accept client on server socket %d: %s (%d)",
sink->server_sock.fd, g_strerror (errno), errno));
return FALSE;
}
if (client_sock_fd == -1)
goto accept_failed;
gst_multi_fd_sink_add (GST_MULTI_FD_SINK (sink), client_sock_fd);
@ -168,6 +164,15 @@ gst_tcp_server_sink_handle_server_read (GstTCPServerSink * sink)
inet_ntoa (client_address.sin_addr), client_sock_fd);
return TRUE;
/* ERRORS */
accept_failed:
{
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL),
("Could not accept client on server socket %d: %s (%d)",
sink->server_sock.fd, g_strerror (errno), errno));
return FALSE;
}
}
static void
@ -191,13 +196,18 @@ gst_tcp_server_sink_handle_wait (GstMultiFdSink * sink, GstPoll * set)
if (gst_poll_fd_can_read (set, &this->server_sock)) {
/* handle new client connection on server socket */
if (!gst_tcp_server_sink_handle_server_read (this)) {
GST_ELEMENT_ERROR (this, RESOURCE, READ, (NULL),
("client connection failed: %s", g_strerror (errno)));
return FALSE;
}
if (!gst_tcp_server_sink_handle_server_read (this))
goto connection_failed;
}
return TRUE;
/* ERRORS */
connection_failed:
{
GST_ELEMENT_ERROR (this, RESOURCE, READ, (NULL),
("client connection failed: %s", g_strerror (errno)));
return FALSE;
}
}
static void
@ -260,31 +270,23 @@ gst_tcp_server_sink_init_send (GstMultiFdSink * parent)
GstTCPServerSink *this = GST_TCP_SERVER_SINK (parent);
/* create sending server socket */
if ((this->server_sock.fd = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_WRITE, (NULL), GST_ERROR_SYSTEM);
return FALSE;
}
if ((this->server_sock.fd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
goto no_socket;
GST_DEBUG_OBJECT (this, "opened sending server socket with fd %d",
this->server_sock.fd);
/* make address reusable */
ret = 1;
if (setsockopt (this->server_sock.fd, SOL_SOCKET, SO_REUSEADDR,
(void *) &ret, sizeof (ret)) < 0) {
gst_tcp_socket_close (&this->server_sock);
GST_ELEMENT_ERROR (this, RESOURCE, SETTINGS, (NULL),
("Could not setsockopt: %s", g_strerror (errno)));
return FALSE;
}
(void *) &ret, sizeof (ret)) < 0)
goto reuse_failed;
/* keep connection alive; avoids SIGPIPE during write */
ret = 1;
if (setsockopt (this->server_sock.fd, SOL_SOCKET, SO_KEEPALIVE,
(void *) &ret, sizeof (ret)) < 0) {
gst_tcp_socket_close (&this->server_sock);
GST_ELEMENT_ERROR (this, RESOURCE, SETTINGS, (NULL),
("Could not setsockopt: %s", g_strerror (errno)));
return FALSE;
}
(void *) &ret, sizeof (ret)) < 0)
goto keepalive_failed;
/* name the socket */
memset (&this->server_sin, 0, sizeof (this->server_sin));
@ -296,30 +298,17 @@ gst_tcp_server_sink_init_send (GstMultiFdSink * parent)
GST_DEBUG_OBJECT (this, "binding server socket to address");
ret = bind (this->server_sock.fd, (struct sockaddr *) &this->server_sin,
sizeof (this->server_sin));
if (ret) {
gst_tcp_socket_close (&this->server_sock);
switch (errno) {
default:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("bind on port %d failed: %s", this->server_port,
g_strerror (errno)));
return FALSE;
break;
}
}
if (ret)
goto bind_failed;
/* set the server socket to nonblocking */
fcntl (this->server_sock.fd, F_SETFL, O_NONBLOCK);
GST_DEBUG_OBJECT (this, "listening on server socket %d with queue of %d",
this->server_sock.fd, TCP_BACKLOG);
if (listen (this->server_sock.fd, TCP_BACKLOG) == -1) {
gst_tcp_socket_close (&this->server_sock);
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("Could not listen on server socket: %s", g_strerror (errno)));
return FALSE;
}
if (listen (this->server_sock.fd, TCP_BACKLOG) == -1)
goto listen_failed;
GST_DEBUG_OBJECT (this,
"listened on server socket %d, returning from connection setup",
this->server_sock.fd);
@ -328,6 +317,46 @@ gst_tcp_server_sink_init_send (GstMultiFdSink * parent)
gst_poll_fd_ctl_read (parent->fdset, &this->server_sock, TRUE);
return TRUE;
/* ERRORS */
no_socket:
{
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_WRITE, (NULL), GST_ERROR_SYSTEM);
return FALSE;
}
reuse_failed:
{
gst_tcp_socket_close (&this->server_sock);
GST_ELEMENT_ERROR (this, RESOURCE, SETTINGS, (NULL),
("Could not setsockopt: %s", g_strerror (errno)));
return FALSE;
}
keepalive_failed:
{
gst_tcp_socket_close (&this->server_sock);
GST_ELEMENT_ERROR (this, RESOURCE, SETTINGS, (NULL),
("Could not setsockopt: %s", g_strerror (errno)));
return FALSE;
}
listen_failed:
{
gst_tcp_socket_close (&this->server_sock);
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("Could not listen on server socket: %s", g_strerror (errno)));
return FALSE;
}
bind_failed:
{
gst_tcp_socket_close (&this->server_sock);
switch (errno) {
default:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("bind on port %d failed: %s", this->server_port,
g_strerror (errno)));
break;
}
return FALSE;
}
}
static gboolean