summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-05-11 13:44:33 (GMT)
committerAlexander Larsson <alexl@redhat.com>2009-05-11 13:44:33 (GMT)
commitcb1680d99bbed890671070613c2546e6a6d34178 (patch)
tree201f6a2b4e1b4efef37882ed991a444251509c96
parent5cf0e62e2761c3822af3eb251001a76d324a8020 (diff)
downloadgnio-cb1680d99bbed890671070613c2546e6a6d34178.tar.gz
gnio-cb1680d99bbed890671070613c2546e6a6d34178.tar.xz
Add g_socket_listener_set_backlog
-rw-r--r--gio/gsocketlistener.c78
-rw-r--r--gio/gsocketlistener.h3
2 files changed, 81 insertions, 0 deletions
diff --git a/gio/gsocketlistener.c b/gio/gsocketlistener.c
index 1f3d19c..db964bd 100644
--- a/gio/gsocketlistener.c
+++ b/gio/gsocketlistener.c
@@ -35,12 +35,20 @@
G_DEFINE_TYPE (GSocketListener, g_socket_listener, G_TYPE_OBJECT);
+enum
+{
+ PROP_0,
+ PROP_LISTEN_BACKLOG
+};
+
+
static GQuark source_quark = 0;
struct _GSocketListenerPrivate
{
GPtrArray *sockets;
GMainContext *main_context;
+ int listen_backlog;
guint closed : 1;
};
@@ -62,6 +70,45 @@ g_socket_listener_finalize (GObject *object)
}
static void
+g_socket_listener_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GSocketListener *listener = G_SOCKET_LISTENER (object);
+
+ switch (prop_id)
+ {
+ case PROP_LISTEN_BACKLOG:
+ g_value_set_int (value, listener->priv->listen_backlog);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+g_socket_listener_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GSocketListener *listener = G_SOCKET_LISTENER (object);
+
+ switch (prop_id)
+ {
+ case PROP_LISTEN_BACKLOG:
+ g_socket_listener_set_backlog (listener, g_value_get_int (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+
+static void
g_socket_listener_class_init (GSocketListenerClass *klass)
{
GObjectClass *gobject_class G_GNUC_UNUSED = G_OBJECT_CLASS (klass);
@@ -69,6 +116,16 @@ g_socket_listener_class_init (GSocketListenerClass *klass)
g_type_class_add_private (klass, sizeof (GSocketListenerPrivate));
gobject_class->finalize = g_socket_listener_finalize;
+ gobject_class->set_property = g_socket_listener_set_property;
+ gobject_class->get_property = g_socket_listener_get_property;
+ g_object_class_install_property (gobject_class, PROP_LISTEN_BACKLOG,
+ g_param_spec_int ("listen-backlog",
+ P_("Listen backlog"),
+ P_("outstanding connections in the listen queue"),
+ 0,
+ 2000,
+ 10,
+ G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
source_quark = g_quark_from_static_string ("g-socket-listener-source");
}
@@ -81,6 +138,7 @@ g_socket_listener_init (GSocketListener *listener)
GSocketListenerPrivate);
listener->priv->sockets =
g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+ listener->priv->listen_backlog = 10;
}
GSocketListener *
@@ -122,6 +180,7 @@ g_socket_listener_add_socket (GSocketListener *listener,
}
g_ptr_array_add (listener->priv->sockets, socket);
+ g_socket_set_listen_backlog (socket, listener->priv->listen_backlog);
if (source_object)
g_object_set_qdata_full (G_OBJECT (socket), source_quark,
@@ -492,6 +551,25 @@ g_socket_listener_accept_finish (GSocketListener *listener,
}
void
+g_socket_listener_set_backlog (GSocketListener *listener,
+ int listen_backlog)
+{
+ GSocket *socket;
+ int i;
+
+ if (listener->priv->closed)
+ return;
+
+ listener->priv->listen_backlog = listen_backlog;
+
+ for (i = 0; i < listener->priv->sockets->len; i++)
+ {
+ socket = listener->priv->sockets->pdata[i];
+ g_socket_set_listen_backlog (socket, listen_backlog);
+ }
+}
+
+void
g_socket_listener_close (GSocketListener *listener)
{
GSocket *socket;
diff --git a/gio/gsocketlistener.h b/gio/gsocketlistener.h
index 66f3829..2ce15b1 100644
--- a/gio/gsocketlistener.h
+++ b/gio/gsocketlistener.h
@@ -61,6 +61,9 @@ GType g_socket_listener_get_type (void);
GSocketListener * g_socket_listener_new (void);
+void g_socket_listener_set_backlog (GSocketListener *listener,
+ int listen_backlog);
+
gboolean g_socket_listener_add_socket (GSocketListener *listener,
GSocket *socket,
GObject *source_object,