/pidgin/main: 5749c9ff9c82: Add cross-platform duplicate_fd() fu...
Mike Ruprecht
cmaiku at gmail.com
Thu Jan 14 20:42:57 EST 2016
Changeset: 5749c9ff9c82e55b6c03a28cbf81c989ea772b24
Author: Mike Ruprecht <cmaiku at gmail.com>
Date: 2016-01-10 02:26 -0600
Branch: purple-proxy-to-gio
URL: https://hg.pidgin.im/pidgin/main/rev/5749c9ff9c82
Description:
Add cross-platform duplicate_fd() function to support Gio-ifying proxy.c
Since proxy_connect_* functions ultimately only return an fd and don't
keep any object data around until closing the socket, the fd created
with Gio functions must be duplicated so that freeing the Gio objects,
doesn't cause the fds to close before the calling code is finished
with them.
This function was grabbed from GLib's Gio testcases for GSocket
(gio/tests/socket.c). It can be removed once the libpurple proxy API
is ported to a Gio style (if the proxy connect functions will even
still need to exist).
diffstat:
libpurple/proxy.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diffs (37 lines):
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -2330,6 +2330,33 @@ purple_proxy_get_setup(PurpleAccount *ac
return gpi;
}
+/* Grabbed duplicate_fd() from GLib's testcases (gio/tests/socket.c).
+ * Can be dropped once this API has been converted to Gio.
+ */
+static int
+duplicate_fd (int fd)
+{
+#ifdef G_OS_WIN32
+ HANDLE newfd;
+
+ if (!DuplicateHandle (GetCurrentProcess (),
+ (HANDLE)fd,
+ GetCurrentProcess (),
+ &newfd,
+ 0,
+ FALSE,
+ DUPLICATE_SAME_ACCESS))
+ {
+ return -1;
+ }
+
+ return (int)newfd;
+#else
+ return dup (fd);
+#endif
+}
+/* End function grabbed from GLib */
+
PurpleProxyConnectData *
purple_proxy_connect(void *handle, PurpleAccount *account,
const char *host, int port,
More information about the Commits
mailing list