Commit c163b09c authored by Johan Dahlin's avatar Johan Dahlin

ext/tcp/*: Revert Zaheer changes, to make things actually work again.

Original commit message from CVS:
* ext/tcp/*: Revert Zaheer changes, to make things actually work again.
parent ae8739f7
2004-06-17 Johan Dahlin <johan@gnome.org>
* ext/tcp/*: Revert Zaheer changes.
2004-06-16 Wim Taymans <wim@fluendo.com>
* sys/v4l/gstv4lmjpegsrc.c: (gst_v4lmjpegsrc_get):
......
......@@ -302,9 +302,8 @@ gst_tcpclientsink_get_property (GObject * object, guint prop_id, GValue * value,
static gboolean
gst_tcpclientsink_init_send (GstTCPClientSink * this)
{
int ret, error;
gchar *tempport;
struct addrinfo hints, *res, *ressave;
int ret;
gchar *ip;
/* reset caps_sent flag */
this->caps_sent = FALSE;
......@@ -312,50 +311,45 @@ gst_tcpclientsink_init_send (GstTCPClientSink * this)
/* create sending client socket */
GST_DEBUG_OBJECT (this, "opening sending client socket to %s:%d", this->host,
this->port);
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
tempport = g_strdup_printf ("%d", this->port);
error = getaddrinfo (this->host, tempport, &hints, &res);
g_free (tempport);
if (error != 0) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ,
(_("Error getting address info (%s:%d): %s"), this->host, this->port,
gai_strerror (error)), (NULL));
if ((this->sock_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);
ressave = res;
this->sock_fd = -1;
while (res) {
this->sock_fd = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
if (this->sock_fd >= 0) {
ret = connect (this->sock_fd, res->ai_addr, res->ai_addrlen);
if (ret == 0)
/* look up name if we need to */
ip = gst_tcp_host_to_ip (GST_ELEMENT (this), this->host);
if (!ip)
return FALSE;
GST_DEBUG_OBJECT (this, "IP address for host %s is %s", this->host, ip);
/* connect to server */
memset (&this->server_sin, 0, sizeof (this->server_sin));
this->server_sin.sin_family = AF_INET; /* network socket */
this->server_sin.sin_port = htons (this->port); /* on port */
this->server_sin.sin_addr.s_addr = inet_addr (ip); /* on host ip */
GST_DEBUG_OBJECT (this, "connecting to server");
ret = connect (this->sock_fd, (struct sockaddr *) &this->server_sin,
sizeof (this->server_sin));
if (ret) {
switch (errno) {
case ECONNREFUSED:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_WRITE,
(_("Connection to %s:%d refused."), this->host, this->port),
(NULL));
return FALSE;
break;
default:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("connect to %s:%d failed: %s", this->host, this->port,
g_strerror (errno)));
return FALSE;
break;
close (this->sock_fd);
this->sock_fd = -1;
}
res = res->ai_next;
}
freeaddrinfo (ressave);
if (errno == ECONNREFUSED) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ,
(_("Connection to %s:%d refused."), this->host, this->port), (NULL));
return FALSE;
}
if (this->sock_fd == -1) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL), GST_ERROR_SYSTEM);
return FALSE;
}
GST_DEBUG_OBJECT (this, "opened sending client socket with fd %d",
this->sock_fd);
GST_FLAG_SET (this, GST_TCPCLIENTSINK_OPEN);
......
......@@ -73,6 +73,7 @@ struct _GstTCPClientSink {
/* server information */
int port;
gchar *host;
struct sockaddr_in server_sin;
/* socket */
int sock_fd;
......
......@@ -393,60 +393,51 @@ gst_tcpclientsrc_get_property (GObject * object, guint prop_id, GValue * value,
static gboolean
gst_tcpclientsrc_init_receive (GstTCPClientSrc * this)
{
int ret, error;
gchar *tempport;
struct addrinfo hints, *res, *ressave;
int ret;
gchar *ip;
/* create receiving client socket */
GST_DEBUG_OBJECT (this, "opening receiving client socket to %s:%d",
this->host, this->port);
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
tempport = g_strdup_printf ("%d", this->port);
error = getaddrinfo (this->host, tempport, &hints, &res);
g_free (tempport);
if (error != 0) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ,
(_("Error getting address info (%s:%d): %s"), this->host, this->port,
gai_strerror (error)), (NULL));
return FALSE;
}
ressave = res;
this->sock_fd = -1;
while (res) {
this->sock_fd = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
if (this->sock_fd >= 0) {
ret = connect (this->sock_fd, res->ai_addr, res->ai_addrlen);
if (ret == 0)
break;
close (this->sock_fd);
this->sock_fd = -1;
}
res = res->ai_next;
}
freeaddrinfo (ressave);
if (errno == ECONNREFUSED) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ,
(_("Connection to %s:%d refused."), this->host, this->port), (NULL));
return FALSE;
}
if (this->sock_fd == -1) {
if ((this->sock_fd = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL), GST_ERROR_SYSTEM);
return FALSE;
}
GST_DEBUG_OBJECT (this, "opened receiving client socket with fd %d",
this->sock_fd);
/* look up name if we need to */
ip = gst_tcp_host_to_ip (GST_ELEMENT (this), this->host);
if (!ip)
return FALSE;
GST_DEBUG_OBJECT (this, "IP address for host %s is %s", this->host, ip);
/* connect to server */
memset (&this->server_sin, 0, sizeof (this->server_sin));
this->server_sin.sin_family = AF_INET; /* network socket */
this->server_sin.sin_port = htons (this->port); /* on port */
this->server_sin.sin_addr.s_addr = inet_addr (ip); /* on host ip */
GST_DEBUG_OBJECT (this, "connecting to server");
ret = connect (this->sock_fd, (struct sockaddr *) &this->server_sin,
sizeof (this->server_sin));
if (ret) {
switch (errno) {
case ECONNREFUSED:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ,
(_("Connection to %s:%d refused."), this->host, this->port),
(NULL));
return FALSE;
break;
default:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("connect to %s:%d failed: %s", this->host, this->port,
g_strerror (errno)));
return FALSE;
break;
}
}
this->send_discont = TRUE;
this->buffer_after_discont = NULL;
......
......@@ -62,6 +62,7 @@ struct _GstTCPClientSrc {
/* server information */
int port;
gchar *host;
struct sockaddr_in server_sin;
/* socket */
int sock_fd;
......
......@@ -29,8 +29,6 @@
#include <sys/filio.h>
#endif
#include <glib.h>
#include "gsttcpserversink.h"
#include "gsttcp-marshal.h"
......@@ -189,7 +187,6 @@ gst_tcpserversink_init (GstTCPServerSink * this)
this->protocol = GST_TCP_PROTOCOL_TYPE_NONE;
this->clock = NULL;
this->host = NULL;
}
static void
......@@ -211,11 +208,8 @@ gst_tcpserversink_handle_server_read (GstTCPServerSink * sink)
{
/* new client */
int client_sock_fd;
struct sockaddr_storage client_address;
struct sockaddr_in client_address;
int client_address_len;
char clienthost[NI_MAXHOST];
char clientservice[NI_MAXSERV];
int error;
client_sock_fd =
accept (sink->server_sock_fd, (struct sockaddr *) &client_address,
......@@ -226,19 +220,11 @@ gst_tcpserversink_handle_server_read (GstTCPServerSink * sink)
return FALSE;
}
FD_SET (client_sock_fd, &(sink->clientfds));
error = getnameinfo ((struct sockaddr *) &client_address, client_address_len,
clienthost, sizeof (clienthost), clientservice,
sizeof (clientservice), NI_NUMERICHOST);
if (error != 0) {
GST_DEBUG_OBJECT (sink, "added new client address %s with fd %d",
clienthost, client_sock_fd);
} else {
GST_DEBUG_OBJECT (sink, "problem error received from getnameinfo: %d",
error);
}
GST_DEBUG_OBJECT (sink, "added new client ip %s with fd %d",
inet_ntoa (client_address.sin_addr), client_sock_fd);
g_signal_emit (G_OBJECT (sink),
gst_tcpserversink_signals[SIGNAL_CLIENT_ADDED], 0,
g_strdup (clienthost), client_sock_fd);
inet_ntoa (client_address.sin_addr), client_sock_fd);
return TRUE;
}
......@@ -560,49 +546,15 @@ gst_tcpserversink_get_property (GObject * object, guint prop_id, GValue * value,
static gboolean
gst_tcpserversink_init_send (GstTCPServerSink * this)
{
int ret, error;
struct addrinfo hints, *res, *ressave;
char *tempport;
int ret;
/* name the socket */
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
tempport = g_strdup_printf ("%d", this->server_port);
error = getaddrinfo (this->host, tempport, &hints, &res);
g_free (tempport);
if (error != 0) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("getaddrinfo failed: %s", gai_strerror (error)));
return FALSE;
}
ressave = res;
/* Try open socket with each address getaddrinfo returned, until getting
a valid listening socket */
this->server_sock_fd = -1;
while (res) {
this->server_sock_fd =
socket (res->ai_family, res->ai_socktype, res->ai_protocol);
if (this->server_sock_fd >= 0) {
ret = bind (this->server_sock_fd, res->ai_addr, res->ai_addrlen);
if (ret == 0)
break;
close (this->server_sock_fd);
this->server_sock_fd = -1;
}
res = res->ai_next;
}
freeaddrinfo (ressave);
if (this->server_sock_fd < 0) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("bind failed: %s", g_strerror (errno)));
/* 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;
}
GST_DEBUG_OBJECT (this, "opened sending server socket with fd %d",
this->server_sock_fd);
/* make address reusable */
if (setsockopt (this->server_sock_fd, SOL_SOCKET, SO_REUSEADDR, &ret,
......@@ -618,6 +570,28 @@ gst_tcpserversink_init_send (GstTCPServerSink * this)
("Could not setsockopt: %s", g_strerror (errno)));
return FALSE;
}
/* name the socket */
memset (&this->server_sin, 0, sizeof (this->server_sin));
this->server_sin.sin_family = AF_INET; /* network socket */
this->server_sin.sin_port = htons (this->server_port); /* on port */
this->server_sin.sin_addr.s_addr = htonl (INADDR_ANY); /* for hosts */
/* bind it */
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) {
switch (errno) {
default:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("bind failed: %s", g_strerror (errno)));
return FALSE;
break;
}
}
/* set the server socket to nonblocking */
fcntl (this->server_sock_fd, F_SETFL, O_NONBLOCK);
......
......@@ -73,6 +73,7 @@ struct _GstTCPServerSink {
/* server information */
int server_port;
gchar *host;
struct sockaddr_in server_sin;
/* socket */
int server_sock_fd;
......
......@@ -456,50 +456,18 @@ gst_tcpserversrc_get_property (GObject * object, guint prop_id, GValue * value,
static gboolean
gst_tcpserversrc_init_receive (GstTCPServerSrc * this)
{
int ret, error;
struct addrinfo hints, *res, *ressave;
gchar *tempport;
struct sockaddr_storage client_address;
int client_address_len;
/* name the socket */
memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
tempport = g_strdup_printf ("%d", this->server_port);
error = getaddrinfo (this->host, tempport, &hints, &res);
g_free (tempport);
if (error != 0) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("getaddrinfo failed: %s", gai_strerror (error)));
return FALSE;
}
ressave = res;
int ret;
/* Try open socket with each address getaddrinfo returned, until getting
a valid listening socket */
this->server_sock_fd = -1;
while (res) {
this->server_sock_fd =
socket (res->ai_family, res->ai_socktype, res->ai_protocol);
if (this->server_sock_fd >= 0) {
ret = bind (this->server_sock_fd, res->ai_addr, res->ai_addrlen);
if (ret == 0)
break;
close (this->server_sock_fd);
this->server_sock_fd = -1;
}
res = res->ai_next;
}
freeaddrinfo (ressave);
/* reset caps_received flag */
this->caps_received = FALSE;
if (this->server_sock_fd < 0) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("bind failed: %s", g_strerror (errno)));
/* create the server listener socket */
if ((this->server_sock_fd = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL), GST_ERROR_SYSTEM);
return FALSE;
}
GST_DEBUG_OBJECT (this, "opened receiving server socket with fd %d",
this->server_sock_fd);
/* make address reusable */
if (setsockopt (this->server_sock_fd, SOL_SOCKET, SO_REUSEADDR, &ret,
......@@ -509,8 +477,35 @@ gst_tcpserversrc_init_receive (GstTCPServerSrc * this)
return FALSE;
}
/* reset caps_received flag */
this->caps_received = FALSE;
/* name the socket */
memset (&this->server_sin, 0, sizeof (this->server_sin));
this->server_sin.sin_family = AF_INET; /* network socket */
this->server_sin.sin_port = htons (this->server_port); /* on port */
if (this->host) {
gchar *host = gst_tcp_host_to_ip (GST_ELEMENT (this), this->host);
if (!host)
return FALSE;
this->server_sin.sin_addr.s_addr = inet_addr (host);
g_free (host);
} else
this->server_sin.sin_addr.s_addr = htonl (INADDR_ANY);
/* bind it */
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) {
switch (errno) {
default:
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("bind failed: %s", g_strerror (errno)));
return FALSE;
break;
}
}
GST_DEBUG_OBJECT (this, "listening on server socket %d with queue of %d",
this->server_sock_fd, TCP_BACKLOG);
......@@ -524,8 +519,8 @@ gst_tcpserversrc_init_receive (GstTCPServerSrc * this)
somewhere else */
GST_DEBUG_OBJECT (this, "waiting for client");
this->client_sock_fd =
accept (this->server_sock_fd, (struct sockaddr *) &client_address,
&client_address_len);
accept (this->server_sock_fd, (struct sockaddr *) &this->client_sin,
&this->client_sin_len);
if (this->client_sock_fd == -1) {
GST_ELEMENT_ERROR (this, RESOURCE, OPEN_READ, (NULL),
("Could not accept client on server socket: %s", g_strerror (errno)));
......
......@@ -72,6 +72,8 @@ struct _GstTCPServerSrc {
int server_sock_fd;
/* client information */
struct sockaddr_in client_sin;
socklen_t client_sin_len;
int client_sock_fd;
/* number of bytes we've gotten */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment