[gvfs/gdbus-core: 28/38] gdbus: Remove unused extra_fd stuff
- From: Tomas Bzatek <tbzatek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/gdbus-core: 28/38] gdbus: Remove unused extra_fd stuff
- Date: Mon, 23 Jul 2012 16:45:07 +0000 (UTC)
commit a20fe029f8b76ccc759e5a0c1edef0fff6b131e1
Author: Tomas Bzatek <tbzatek redhat com>
Date: Tue Jul 3 17:48:31 2012 +0200
gdbus: Remove unused extra_fd stuff
client/gvfsdaemondbus.c | 66 +++-------------------
daemon/gvfsdaemon.c | 146 ++--------------------------------------------
2 files changed, 15 insertions(+), 197 deletions(-)
---
diff --git a/client/gvfsdaemondbus.c b/client/gvfsdaemondbus.c
index 4feb0ea..b59fdda 100644
--- a/client/gvfsdaemondbus.c
+++ b/client/gvfsdaemondbus.c
@@ -39,15 +39,9 @@
#include "gsysutils.h"
#include <gvfsdbus.h>
-/* Extra vfs-specific data for DBusConnections */
+/* Extra vfs-specific data for GDBusConnections */
typedef struct {
- int extra_fd;
- int extra_fd_count;
char *async_dbus_id;
-
- /* Only used for async connections */
- GHashTable *outstanding_fds;
- GSource *extra_fd_source;
} VfsConnectionData;
typedef struct _ThreadLocalConnections ThreadLocalConnections;
@@ -186,20 +180,7 @@ connection_data_free (gpointer p)
{
VfsConnectionData *data = p;
- if (data->extra_fd != -1)
- close (data->extra_fd);
-
- if (data->extra_fd_source)
- {
- g_source_destroy (data->extra_fd_source);
- g_source_unref (data->extra_fd_source);
- }
-
- if (data->outstanding_fds)
- g_hash_table_destroy (data->outstanding_fds);
-
g_free (data->async_dbus_id);
-
g_free (data);
}
@@ -229,14 +210,11 @@ vfs_connection_closed (GDBusConnection *connection,
static void
vfs_connection_setup (GDBusConnection *connection,
- int extra_fd,
gboolean async)
{
VfsConnectionData *connection_data;
connection_data = g_new0 (VfsConnectionData, 1);
- connection_data->extra_fd = extra_fd;
- connection_data->extra_fd_count = 0;
g_object_set_data_full (G_OBJECT (connection), "connection_data", connection_data, connection_data_free);
@@ -303,7 +281,6 @@ typedef struct {
const char *dbus_id;
GDBusConnection *connection;
- int extra_fd;
GCancellable *cancellable;
GVfsAsyncDBusCallback callback;
@@ -343,14 +320,13 @@ async_got_private_connection_cb (GObject *source_object,
g_print ("async_got_private_connection_cb, connection = %p\n", connection);
if (!connection)
{
- close (async_call->extra_fd);
async_call->io_error = g_error_copy (error);
g_error_free (error);
async_call_finish (async_call);
return;
}
- vfs_connection_setup (connection, async_call->extra_fd, TRUE);
+ vfs_connection_setup (connection, TRUE);
/* Maybe we already had a connection? This happens if we requested
* the same owner several times in parallel.
@@ -388,12 +364,12 @@ async_get_connection_response (GVfsDBusDaemon *proxy,
{
AsyncDBusCall *async_call = user_data;
GError *error = NULL;
- gchar *address1, *address2;
+ gchar *address1;
g_print ("async_get_connection_response\n");
if (! gvfs_dbus_daemon_call_get_connection_finish (proxy,
- &address1, &address2,
+ &address1, NULL,
res,
&error))
{
@@ -403,18 +379,6 @@ async_get_connection_response (GVfsDBusDaemon *proxy,
return;
}
- /* I don't know of any way to do an async connect */
- error = NULL;
- async_call->extra_fd = _g_socket_connect (address2, &error);
- if (async_call->extra_fd == -1)
- {
- g_set_error (&async_call->io_error, G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Error connecting to daemon: %s"), error->message);
- g_error_free (error);
- async_call_finish (async_call);
- return;
- }
-
g_dbus_connection_new_for_address (address1,
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL, /* GDBusAuthObserver */
@@ -663,8 +627,7 @@ _g_dbus_connection_get_sync (const char *dbus_id,
ThreadLocalConnections *local;
GError *local_error;
GDBusConnection *connection;
- gchar *address1, *address2;
- int extra_fd;
+ gchar *address1;
GVfsDBusDaemon *daemon_proxy;
gboolean res;
@@ -727,7 +690,7 @@ _g_dbus_connection_get_sync (const char *dbus_id,
return bus; /* We actually wanted the session bus, so done */
}
- address1 = address2 = NULL;
+ address1 = NULL;
daemon_proxy = gvfs_dbus_daemon_proxy_new_sync (local->session_bus,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
dbus_id,
@@ -739,7 +702,7 @@ _g_dbus_connection_get_sync (const char *dbus_id,
res = gvfs_dbus_daemon_call_get_connection_sync (daemon_proxy,
&address1,
- &address2,
+ NULL,
cancellable,
error);
g_object_unref (daemon_proxy);
@@ -748,17 +711,6 @@ _g_dbus_connection_get_sync (const char *dbus_id,
return NULL;
local_error = NULL;
- extra_fd = _g_socket_connect (address2, &local_error);
- if (extra_fd == -1)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Error connecting to daemon: %s"), local_error->message);
- g_error_free (local_error);
- g_free (address1);
- g_free (address2);
- return NULL;
- }
-
connection = g_dbus_connection_new_for_address_sync (address1,
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
NULL, /* GDBusAuthObserver */
@@ -769,14 +721,12 @@ _g_dbus_connection_get_sync (const char *dbus_id,
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Error while getting peer-to-peer dbus connection: %s",
local_error->message);
- close (extra_fd);
g_error_free (local_error);
g_free (address1);
- g_free (address2);
return NULL;
}
- vfs_connection_setup (connection, extra_fd, FALSE);
+ vfs_connection_setup (connection, FALSE);
g_hash_table_insert (local->connections, g_strdup (dbus_id), connection);
diff --git a/daemon/gvfsdaemon.c b/daemon/gvfsdaemon.c
index ecfb099..8ff3b4b 100644
--- a/daemon/gvfsdaemon.c
+++ b/daemon/gvfsdaemon.c
@@ -81,12 +81,8 @@ struct _GVfsDaemon
typedef struct {
GVfsDaemon *daemon;
char *socket_dir;
- guint io_watch;
GDBusServer *server;
- gboolean got_dbus_connection;
- gboolean got_fd_connection;
- int fd;
GDBusConnection *conn;
} NewConnectionData;
@@ -603,9 +599,6 @@ new_connection_data_free (void *memory)
if (data->socket_dir)
rmdir (data->socket_dir);
- if (data->io_watch)
- g_source_remove (data->io_watch);
-
g_free (data->socket_dir);
g_free (data);
}
@@ -665,18 +658,6 @@ daemon_peer_connection_setup (GVfsDaemon *daemon,
{
GVfsDBusDaemon *daemon_skeleton;
GError *error;
-
- /* We wait until we have the extra fd */
- if (!data->got_fd_connection)
- return;
-
- if (data->fd == -1)
- {
- /* The fd connection failed, abort the whole thing */
- g_warning ("Failed to accept client: %s", "accept of extra fd failed");
- g_object_unref (data->conn);
- goto error_out;
- }
daemon_skeleton = gvfs_dbus_daemon_skeleton_new ();
g_signal_connect (daemon_skeleton, "handle-cancel", G_CALLBACK (handle_cancel), daemon);
@@ -691,7 +672,6 @@ daemon_peer_connection_setup (GVfsDaemon *daemon,
error->message, g_quark_to_string (error->domain), error->code);
g_error_free (error);
g_object_unref (data->conn);
- close (data->fd);
goto error_out;
}
g_object_set_data_full (G_OBJECT (data->conn), "daemon_skeleton", daemon_skeleton, (GDestroyNotify) g_object_unref);
@@ -808,12 +788,10 @@ create_socket_dir (void)
#endif
static void
-generate_addresses (char **address1,
- char **address2,
- char **folder)
+generate_address (char **address,
+ char **folder)
{
- *address1 = NULL;
- *address2 = NULL;
+ *address = NULL;
*folder = NULL;
#ifdef USE_ABSTRACT_SOCKETS
@@ -821,18 +799,14 @@ generate_addresses (char **address1,
gchar tmp[9];
randomize_string (tmp);
- *address1 = g_strdup_printf ("unix:abstract=/dbus-vfs-daemon/socket-%s", tmp);
-
- randomize_string (tmp);
- *address2 = g_strdup_printf ("unix:abstract=/dbus-vfs-daemon/socket-%s", tmp);
+ *address = g_strdup_printf ("unix:abstract=/dbus-vfs-daemon/socket-%s", tmp);
}
#else
{
char *dir;
dir = create_socket_dir ();
- *address1 = g_strdup_printf ("unix:path=%s/socket1", dir);
- *address2 = g_strdup_printf ("unix:path=%s/socket2", dir);
+ *address = g_strdup_printf ("unix:path=%s/socket", dir);
*folder = dir;
}
#endif
@@ -846,7 +820,6 @@ daemon_new_connection_func (GDBusServer *server,
NewConnectionData *data;
data = user_data;
- data->got_dbus_connection = TRUE;
/* Take ownership */
data->conn = g_object_ref (connection);
@@ -862,94 +835,6 @@ daemon_new_connection_func (GDBusServer *server,
return TRUE;
}
-static int
-unix_socket_at (const char *address)
-{
- int fd;
- const char *path;
- size_t path_len;
- struct sockaddr_un addr;
-
- fd = socket (PF_UNIX, SOCK_STREAM, 0);
- if (fd == -1)
- return -1;
-
-#ifdef USE_ABSTRACT_SOCKETS
- path = address + strlen ("unix:abstract=");
-#else
- path = address + strlen ("unix:path=");
-#endif
-
- memset (&addr, 0, sizeof (addr));
- addr.sun_family = AF_UNIX;
- path_len = strlen (path);
-
-#ifdef USE_ABSTRACT_SOCKETS
- addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
- path_len++; /* Account for the extra nul byte added to the start of sun_path */
-
- strncpy (&addr.sun_path[1], path, path_len);
-#else /* USE_ABSTRACT_SOCKETS */
- strncpy (addr.sun_path, path, path_len);
- unlink (path);
-#endif /* ! USE_ABSTRACT_SOCKETS */
-
- if (bind (fd, (struct sockaddr*) &addr,
- G_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
- {
- close (fd);
- return -1;
- }
-
- if (listen (fd, 30 /* backlog */) < 0)
- {
- close (fd);
- return -1;
- }
-
- return fd;
-}
-
-static gboolean
-accept_new_fd_client (GIOChannel *channel,
- GIOCondition cond,
- gpointer callback_data)
-{
- NewConnectionData *data = callback_data;
- int fd;
- int new_fd;
- struct sockaddr_un addr;
- socklen_t addrlen;
-
- g_print ("accept_new_fd_client\n");
-
- data->got_fd_connection = TRUE;
-
- fd = g_io_channel_unix_get_fd (channel);
-
- addrlen = sizeof (addr);
- new_fd = accept (fd, (struct sockaddr *) &addr, &addrlen);
-
- data->fd = new_fd;
- data->io_watch = 0;
-
- /* Did we already accept the dbus connection, if so, finish it now */
- if (data->got_dbus_connection)
- daemon_peer_connection_setup (data->daemon,
- data->conn,
- data);
- else if (data->fd == -1)
- {
- /* Didn't accept a dbus connection, and there is no need for one now */
- g_warning ("Failed to accept client: %s", "accept of extra fd failed");
- g_dbus_server_stop (data->server);
- g_object_unref (data->server);
- new_connection_data_free (data);
- }
-
- return FALSE;
-}
-
static gboolean
handle_get_connection (GVfsDBusDaemon *object,
GDBusMethodInvocation *invocation,
@@ -959,29 +844,19 @@ handle_get_connection (GVfsDBusDaemon *object,
GDBusServer *server;
GError *error;
gchar *address1;
- gchar *address2;
NewConnectionData *data;
- GIOChannel *channel;
char *socket_dir;
- int fd;
gchar *guid;
g_print ("called get_connection()\n");
- generate_addresses (&address1, &address2, &socket_dir);
+ generate_address (&address1, &socket_dir);
data = g_new (NewConnectionData, 1);
data->daemon = daemon;
data->socket_dir = socket_dir;
- data->got_fd_connection = FALSE;
- data->got_dbus_connection = FALSE;
- data->fd = -1;
data->conn = NULL;
- fd = unix_socket_at (address2);
- if (fd == -1)
- goto error_out;
-
guid = g_dbus_generate_guid ();
error = NULL;
server = g_dbus_server_new_sync (address1,
@@ -1006,25 +881,18 @@ handle_get_connection (GVfsDBusDaemon *object,
g_print ("Server is listening at: %s\n", g_dbus_server_get_client_address (server));
g_signal_connect (server, "new-connection", G_CALLBACK (daemon_new_connection_func), data);
- channel = g_io_channel_unix_new (fd);
- g_io_channel_set_close_on_unref (channel, TRUE);
- data->io_watch = g_io_add_watch (channel, G_IO_IN | G_IO_HUP, accept_new_fd_client, data);
- g_io_channel_unref (channel);
-
gvfs_dbus_daemon_complete_get_connection (object,
invocation,
address1,
- address2);
+ "");
g_free (address1);
- g_free (address2);
return TRUE;
error_out:
g_print ("handle_get_connection: error_out\n");
g_free (data);
g_free (address1);
- g_free (address2);
if (socket_dir)
{
rmdir (socket_dir);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]