mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 10:41:04 +00:00
Add a new parameter _socketop_ to allow use REUSEADDR and KEEPALIVE socket options
Original commit message from CVS: Add a new parameter _socketop_ to allow use REUSEADDR and KEEPALIVE socket options
This commit is contained in:
parent
d1ef739d08
commit
c272681c11
3 changed files with 32 additions and 3 deletions
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit 6b0a313b93535f0df7956a01405ddb63a3d76b5a
|
||||
Subproject commit 6757dae2885c2c09ad6db243c73946ef387bb044
|
|
@ -47,7 +47,8 @@ enum {
|
|||
enum {
|
||||
ARG_0,
|
||||
ARG_PORT,
|
||||
ARG_CONTROL
|
||||
ARG_CONTROL,
|
||||
ARG_SOCKET_OPTIONS,
|
||||
/* FILL ME */
|
||||
};
|
||||
|
||||
|
@ -124,6 +125,10 @@ gst_tcpsrc_class_init (GstTCPSrc *klass)
|
|||
g_param_spec_enum ("control", "control", "The type of control",
|
||||
GST_TYPE_TCPSRC_CONTROL, CONTROL_TCP, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SOCKET_OPTIONS,
|
||||
g_param_spec_boolean ("socketop", "socketop", "Enable or disable socket options REUSEADDR and KEEPALIVE",
|
||||
FALSE, G_PARAM_READWRITE));
|
||||
|
||||
gobject_class->set_property = gst_tcpsrc_set_property;
|
||||
gobject_class->get_property = gst_tcpsrc_get_property;
|
||||
|
||||
|
@ -155,6 +160,7 @@ gst_tcpsrc_init (GstTCPSrc *tcpsrc)
|
|||
tcpsrc->sock = -1;
|
||||
tcpsrc->control_sock = -1;
|
||||
tcpsrc->client_sock = -1;
|
||||
tcpsrc->socket_options = FALSE;
|
||||
|
||||
GST_FLAG_UNSET (tcpsrc, GST_TCPSRC_OPEN);
|
||||
GST_FLAG_SET (tcpsrc, GST_TCPSRC_1ST_BUF);
|
||||
|
@ -323,6 +329,9 @@ gst_tcpsrc_set_property (GObject *object, guint prop_id, const GValue *value, GP
|
|||
case ARG_CONTROL:
|
||||
tcpsrc->control = g_value_get_enum (value);
|
||||
break;
|
||||
case ARG_SOCKET_OPTIONS:
|
||||
tcpsrc->socket_options = g_value_get_boolean(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -344,6 +353,9 @@ gst_tcpsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
|
|||
case ARG_CONTROL:
|
||||
g_value_set_enum (value, tcpsrc->control);
|
||||
break;
|
||||
case ARG_SOCKET_OPTIONS:
|
||||
g_value_set_boolean(value,tcpsrc->socket_options);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -354,6 +366,7 @@ gst_tcpsrc_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
|
|||
static gboolean
|
||||
gst_tcpsrc_init_receive (GstTCPSrc *src)
|
||||
{
|
||||
guint val=0;
|
||||
bzero (&src->myaddr, sizeof (src->myaddr));
|
||||
src->myaddr.sin_family = AF_INET; /* host byte order */
|
||||
src->myaddr.sin_port = htons (src->port); /* short, network byte order */
|
||||
|
@ -363,7 +376,22 @@ gst_tcpsrc_init_receive (GstTCPSrc *src)
|
|||
perror("stream_socket");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (src->socket_options)
|
||||
{
|
||||
g_print("Socket Options enabled\n");
|
||||
/* Sock Options */
|
||||
val = 1;
|
||||
/* allow local address reuse */
|
||||
if( setsockopt( src->sock,SOL_SOCKET,SO_REUSEADDR, &val, sizeof( int )) <0)
|
||||
perror( "setsockopt()" );
|
||||
val = 1;
|
||||
/* periodically test if connection still alive */
|
||||
if( setsockopt( src->sock,SOL_SOCKET,SO_KEEPALIVE, &val, sizeof( int )) <0)
|
||||
perror( "setsockopt()" );
|
||||
/* Sock Options */
|
||||
}
|
||||
|
||||
if (bind (src->sock, (struct sockaddr *) &src->myaddr, sizeof (src->myaddr)) == -1) {
|
||||
perror("stream_sock bind");
|
||||
return FALSE;
|
||||
|
|
|
@ -71,6 +71,7 @@ struct _GstTCPSrc {
|
|||
int sock;
|
||||
int client_sock;
|
||||
int control_sock;
|
||||
gboolean socket_options;
|
||||
Gst_TCP_Control control;
|
||||
|
||||
struct sockaddr_in myaddr;
|
||||
|
|
Loading…
Reference in a new issue