5 * Purple is the legal property of its developers, whose names are too numerous
6 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #include "purple-gio.h"
31 GOutputStream
*output
;
35 graceful_close_cb(gpointer user_data
)
37 GracefulCloseData
*data
= user_data
;
40 if (g_input_stream_has_pending(data
->input
) ||
41 g_output_stream_has_pending(data
->output
)) {
42 /* Has pending operations. Not ready to close yet.
45 return G_SOURCE_CONTINUE
;
48 /* Finally can gracefully close */
50 /* Close input stream, from wrapper or GIOStream */
51 if (!g_input_stream_close(data
->input
, NULL
, &error
)) {
52 purple_debug_warning("gio",
53 "Error closing input stream: %s",
55 g_clear_error(&error
);
58 g_clear_object(&data
->input
);
60 /* Close output stream, from wrapper or GIOStream */
61 if (!g_output_stream_close(data
->output
, NULL
, &error
)) {
62 purple_debug_warning("gio",
63 "Error closing output stream: %s",
65 g_clear_error(&error
);
68 g_clear_object(&data
->output
);
71 if (!g_io_stream_close(data
->stream
, NULL
, &error
)) {
72 purple_debug_warning("gio",
73 "Error closing stream: %s",
75 g_clear_error(&error
);
78 g_clear_object(&data
->stream
);
82 return G_SOURCE_REMOVE
;
86 purple_gio_graceful_close(GIOStream
*stream
,
87 GInputStream
*input
, GOutputStream
*output
)
89 GracefulCloseData
*data
;
91 g_return_if_fail(G_IS_IO_STREAM(stream
));
92 g_return_if_fail(input
== NULL
|| G_IS_INPUT_STREAM(input
));
93 g_return_if_fail(output
== NULL
|| G_IS_OUTPUT_STREAM(output
));
95 data
= g_new(GracefulCloseData
, 1);
96 data
->stream
= g_object_ref(stream
);
99 input
= g_io_stream_get_input_stream(stream
);
100 data
->input
= g_object_ref(input
);
103 output
= g_io_stream_get_output_stream(stream
);
104 data
->output
= g_object_ref(output
);
106 /* Try gracefully closing the stream synchronously */
107 if (graceful_close_cb(data
) == G_SOURCE_CONTINUE
) {
108 /* Has pending operations. Do so asynchronously */
109 g_idle_add(graceful_close_cb
, data
);
114 purple_gio_socket_client_new(PurpleAccount
*account
, GError
**error
)
116 GProxyResolver
*resolver
;
117 GSocketClient
*client
;
119 resolver
= purple_proxy_get_proxy_resolver(account
, error
);
121 if (resolver
== NULL
) {
125 client
= g_socket_client_new();
126 g_socket_client_set_proxy_resolver(client
, resolver
);
127 g_object_unref(resolver
);