author | Senko Rasic <senko.rasic@collabora.co.uk> |
Sun, 30 Nov 2008 10:20:08 +0100 | |
changeset 575 | daad23d59b56 |
parent 552 | 137471c948ae |
permissions | -rw-r--r-- |
147 | 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
2 |
/* |
|
3 |
* Copyright (C) 2006 Imendio AB |
|
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
4 |
* Copyright (C) 2006 Nokia Corporation. All rights reserved. |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
5 |
* Copyright (C) 2007 Collabora Ltd. |
147 | 6 |
* |
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU Lesser General Public License as |
|
9 |
* published by the Free Software Foundation; either version 2 of the |
|
10 |
* License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
* Lesser General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU Lesser General Public |
|
18 |
* License along with this program; if not, write to the |
|
19 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
20 |
* Boston, MA 02111-1307, USA. |
|
21 |
*/ |
|
22 |
||
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
23 |
#include <config.h> |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
24 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
25 |
#include <string.h> |
257
d2df6b962601
Compile fix for Solaris
Mikael Hallendal <micke@imendio.com>
parents:
256
diff
changeset
|
26 |
#include <sys/types.h> |
337
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
27 |
|
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
28 |
/* Needed on Mac OS X */ |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
29 |
#if HAVE_NETINET_IN_H |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
30 |
#include <netinet/in.h> |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
31 |
#endif |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
32 |
|
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
33 |
/* Needed on Mac OS X */ |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
34 |
#if HAVE_ARPA_NAMESER_COMPAT_H |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
35 |
#include <arpa/nameser_compat.h> |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
36 |
#endif |
7bc0c6ad11ff
Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents:
325
diff
changeset
|
37 |
|
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
38 |
#include <arpa/nameser.h> |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
39 |
#include <resolv.h> |
147 | 40 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
41 |
#include "lm-debug.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
42 |
#include "lm-internals.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
43 |
#include "lm-misc.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
44 |
#include "lm-ssl.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
45 |
#include "lm-ssl-internals.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
46 |
#include "lm-proxy.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
47 |
#include "lm-socket.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
48 |
#include "lm-sock.h" |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
49 |
#include "lm-error.h" |
149 | 50 |
|
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
51 |
#ifdef HAVE_ASYNCNS |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
52 |
#include <asyncns.h> |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
53 |
#define freeaddrinfo(x) asyncns_freeaddrinfo(x) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
54 |
#endif |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
55 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
56 |
#define IN_BUFFER_SIZE 1024 |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
57 |
#define MIN_PORT 1 |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
58 |
#define MAX_PORT 65536 |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
59 |
#define SRV_LEN 8192 |
154 | 60 |
|
149 | 61 |
struct _LmSocket { |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
62 |
LmConnection *connection; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
63 |
GMainContext *context; |
151 | 64 |
|
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
65 |
gchar *domain; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
66 |
gchar *server; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
67 |
guint port; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
68 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
69 |
gboolean blocking; |
149 | 70 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
71 |
LmSSL *ssl; |
298
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
72 |
gboolean ssl_started; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
73 |
LmProxy *proxy; |
147 | 74 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
75 |
GIOChannel *io_channel; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
76 |
GSource *watch_in; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
77 |
GSource *watch_err; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
78 |
GSource *watch_hup; |
154 | 79 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
80 |
LmSocketT fd; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
81 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
82 |
GSource *watch_connect; |
154 | 83 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
84 |
gboolean cancel_open; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
85 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
86 |
GSource *watch_out; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
87 |
GString *out_buf; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
88 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
89 |
LmConnectData *connect_data; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
90 |
|
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
91 |
IncomingDataFunc data_func; |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
92 |
SocketClosedFunc closed_func; |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
93 |
ConnectResultFunc connect_func; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
94 |
gpointer user_data; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
95 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
96 |
guint ref_count; |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
97 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
98 |
#ifdef HAVE_ASYNCNS |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
99 |
GSource *watch_resolv; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
100 |
asyncns_query_t *resolv_query; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
101 |
asyncns_t *asyncns_ctx; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
102 |
GIOChannel *resolv_channel; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
103 |
#endif |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
104 |
}; |
154 | 105 |
|
249 | 106 |
static void socket_free (LmSocket *socket); |
107 |
static gboolean socket_do_connect (LmConnectData *connect_data); |
|
108 |
static gboolean socket_connect_cb (GIOChannel *source, |
|
109 |
GIOCondition condition, |
|
110 |
LmConnectData *connect_data); |
|
111 |
static gboolean socket_in_event (GIOChannel *source, |
|
112 |
GIOCondition condition, |
|
113 |
LmSocket *socket); |
|
114 |
static gboolean socket_hup_event (GIOChannel *source, |
|
115 |
GIOCondition condition, |
|
116 |
LmSocket *socket); |
|
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
117 |
static gboolean socket_error_event (GIOChannel *source, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
118 |
GIOCondition condition, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
119 |
LmSocket *socket); |
249 | 120 |
static gboolean socket_buffered_write_cb (GIOChannel *source, |
121 |
GIOCondition condition, |
|
122 |
LmSocket *socket); |
|
123 |
static gboolean socket_parse_srv_response (unsigned char *srv, |
|
124 |
int srv_len, |
|
125 |
gchar **out_server, |
|
126 |
guint *out_port); |
|
346
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
127 |
static void socket_close_io_channel (GIOChannel *io_channel); |
147 | 128 |
|
129 |
static void |
|
149 | 130 |
socket_free (LmSocket *socket) |
147 | 131 |
{ |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
132 |
g_free (socket->server); |
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
133 |
g_free (socket->domain); |
151 | 134 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
135 |
if (socket->ssl) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
136 |
lm_ssl_unref (socket->ssl); |
154 | 137 |
} |
138 |
||
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
139 |
if (socket->proxy) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
140 |
lm_proxy_unref (socket->proxy); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
141 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
142 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
143 |
if (socket->out_buf) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
144 |
g_string_free (socket->out_buf, TRUE); |
151 | 145 |
} |
146 |
||
154 | 147 |
g_free (socket); |
148 |
} |
|
149 | 149 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
150 |
gint |
249 | 151 |
lm_socket_do_write (LmSocket *socket, const gchar *buf, gint len) |
149 | 152 |
{ |
151 | 153 |
gint b_written; |
154 |
||
298
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
155 |
if (socket->ssl_started) { |
151 | 156 |
b_written = _lm_ssl_send (socket->ssl, buf, len); |
157 |
} else { |
|
158 |
GIOStatus io_status = G_IO_STATUS_AGAIN; |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
159 |
gsize bytes_written; |
151 | 160 |
|
161 |
while (io_status == G_IO_STATUS_AGAIN) { |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
162 |
io_status = g_io_channel_write_chars (socket->io_channel, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
163 |
buf, len, |
151 | 164 |
&bytes_written, |
165 |
NULL); |
|
166 |
} |
|
167 |
||
168 |
b_written = bytes_written; |
|
169 |
||
170 |
if (io_status != G_IO_STATUS_NORMAL) { |
|
171 |
b_written = -1; |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
return b_written; |
|
149 | 176 |
} |
177 |
||
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
178 |
static gboolean |
249 | 179 |
socket_read_incoming (LmSocket *socket, |
180 |
gchar *buf, |
|
181 |
gsize buf_size, |
|
182 |
gsize *bytes_read, |
|
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
183 |
gboolean *hangup, |
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
184 |
gint *reason) |
149 | 185 |
{ |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
186 |
GIOStatus status; |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
187 |
|
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
188 |
*hangup = FALSE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
189 |
|
298
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
190 |
if (socket->ssl_started) { |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
191 |
status = _lm_ssl_read (socket->ssl, |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
192 |
buf, buf_size - 1, bytes_read); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
193 |
} else { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
194 |
status = g_io_channel_read_chars (socket->io_channel, |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
195 |
buf, buf_size - 1, |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
196 |
bytes_read, |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
197 |
NULL); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
198 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
199 |
|
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
200 |
if (status != G_IO_STATUS_NORMAL || *bytes_read < 0) { |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
201 |
switch (status) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
202 |
case G_IO_STATUS_EOF: |
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
203 |
*reason = LM_DISCONNECT_REASON_HUP; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
204 |
break; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
205 |
case G_IO_STATUS_AGAIN: |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
206 |
/* No data readable but we didn't hangup */ |
552
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
207 |
/* No need to do anything since we will get a new in_event when data is |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
208 |
* available or writable. */ |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
209 |
return FALSE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
210 |
break; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
211 |
case G_IO_STATUS_ERROR: |
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
212 |
*reason = LM_DISCONNECT_REASON_ERROR; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
213 |
break; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
214 |
default: |
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
215 |
*reason = LM_DISCONNECT_REASON_UNKNOWN; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
216 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
217 |
|
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
218 |
/* Notify connection_in_event that we hangup the connection */ |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
219 |
*hangup = TRUE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
220 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
221 |
return FALSE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
222 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
223 |
|
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
224 |
buf[*bytes_read] = '\0'; |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
225 |
|
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
226 |
/* There is more data to be read */ |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
227 |
return TRUE; |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
228 |
} |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
229 |
|
552
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
230 |
/* |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
231 |
* When a non-blocking socket is used we will simply try to read again but when using a blocking socket |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
232 |
* it means that the read operation will block in case there is no data available. |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
233 |
* This function checks if the socket is in blocking mode and checks the IO Condition to see whether there |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
234 |
* is more data to be read before trying to read again |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
235 |
*/ |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
236 |
static gboolean |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
237 |
socket_attempt_another_read (LmSocket *socket, GIOCondition condition) |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
238 |
{ |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
239 |
if (socket->blocking) { |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
240 |
return (condition & G_IO_IN); |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
241 |
} |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
242 |
|
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
243 |
return TRUE; |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
244 |
} |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
245 |
|
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
246 |
static gboolean |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
247 |
socket_in_event (GIOChannel *source, |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
248 |
GIOCondition condition, |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
249 |
LmSocket *socket) |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
250 |
{ |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
251 |
gchar buf[IN_BUFFER_SIZE]; |
322
9d591fb31bc2
Make blocking reads work
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
308
diff
changeset
|
252 |
gsize bytes_read = 0; |
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
253 |
gboolean read_anything = FALSE; |
322
9d591fb31bc2
Make blocking reads work
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
308
diff
changeset
|
254 |
gboolean hangup = 0; |
9d591fb31bc2
Make blocking reads work
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
308
diff
changeset
|
255 |
gint reason = 0; |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
256 |
|
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
257 |
if (!socket->io_channel) { |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
258 |
return FALSE; |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
259 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
260 |
|
552
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
261 |
while (socket_attempt_another_read (socket, condition) && |
137471c948ae
Only check for IO Condition before trying another read when the socket is blocking [#23]
Mikael Hallendal <micke@imendio.com>
parents:
346
diff
changeset
|
262 |
socket_read_incoming (socket, buf, IN_BUFFER_SIZE, |
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
263 |
&bytes_read, &hangup, &reason)) { |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
264 |
|
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
265 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV [%d]:\n", |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
266 |
(int)bytes_read); |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
267 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
268 |
"-----------------------------------\n"); |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
269 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "'%s'\n", buf); |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
270 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
271 |
"-----------------------------------\n"); |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
272 |
|
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
273 |
lm_verbose ("Read: %d chars\n", (int)bytes_read); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
274 |
|
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
275 |
(socket->data_func) (socket, buf, socket->user_data); |
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
276 |
|
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
277 |
read_anything = TRUE; |
322
9d591fb31bc2
Make blocking reads work
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
308
diff
changeset
|
278 |
|
9d591fb31bc2
Make blocking reads work
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
308
diff
changeset
|
279 |
condition = g_io_channel_get_buffer_condition (socket->io_channel); |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
280 |
} |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
281 |
|
272
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
282 |
/* If we have read something, delay the hangup so that the data can be |
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
283 |
* processed. */ |
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
284 |
if (hangup && !read_anything) { |
00c0890d19c0
If data was read before hangup, delay signalling hangup so that the data can
Dafydd Harries <daf@rhydd.org>
parents:
271
diff
changeset
|
285 |
(socket->closed_func) (socket, reason, socket->user_data); |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
286 |
return FALSE; |
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
287 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
288 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
289 |
return TRUE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
290 |
} |
202
42d0b1ed1b96
Forward port of fix to LM-71.
Mikael Hallendal <micke@imendio.com>
parents:
196
diff
changeset
|
291 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
292 |
static gboolean |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
293 |
socket_hup_event (GIOChannel *source, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
294 |
GIOCondition condition, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
295 |
LmSocket *socket) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
296 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
297 |
lm_verbose ("HUP event: %d->'%s'\n", |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
298 |
condition, lm_misc_io_condition_to_str (condition)); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
299 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
300 |
if (!socket->io_channel) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
301 |
return FALSE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
302 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
303 |
|
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
304 |
(socket->closed_func) (socket, LM_DISCONNECT_REASON_HUP, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
305 |
socket->user_data); |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
306 |
|
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
307 |
return TRUE; |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
308 |
} |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
309 |
|
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
310 |
static gboolean |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
311 |
socket_error_event (GIOChannel *source, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
312 |
GIOCondition condition, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
313 |
LmSocket *socket) |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
314 |
{ |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
315 |
lm_verbose ("ERROR event: %d->'%s'\n", |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
316 |
condition, lm_misc_io_condition_to_str (condition)); |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
317 |
|
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
318 |
if (!socket->io_channel) { |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
319 |
return FALSE; |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
320 |
} |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
321 |
|
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
322 |
(socket->closed_func) (socket, LM_DISCONNECT_REASON_ERROR, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
323 |
socket->user_data); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
324 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
325 |
return TRUE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
326 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
327 |
|
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
328 |
static gboolean |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
329 |
_lm_socket_ssl_init (LmSocket *socket, gboolean delayed) |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
330 |
{ |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
331 |
GError *error = NULL; |
277
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
332 |
const gchar *ssl_verify_domain = NULL; |
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
333 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
334 |
lm_verbose ("Setting up SSL...\n"); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
335 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
336 |
_lm_ssl_initialize (socket->ssl); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
337 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
338 |
#ifdef HAVE_GNUTLS |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
339 |
/* GNU TLS requires the socket to be blocking */ |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
340 |
_lm_sock_set_blocking (socket->fd, TRUE); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
341 |
#endif |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
342 |
|
277
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
343 |
/* If we're using StartTLS, the correct thing is to verify against |
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
344 |
* the domain. If we're using old SSL, we should verify against the |
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
345 |
* hostname. */ |
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
346 |
if (delayed) |
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
347 |
ssl_verify_domain = socket->domain; |
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
348 |
else |
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
349 |
ssl_verify_domain = socket->server; |
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
350 |
|
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
351 |
if (!_lm_ssl_begin (socket->ssl, socket->fd, ssl_verify_domain, &error)) { |
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
352 |
lm_verbose ("Could not begin SSL\n"); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
353 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
354 |
if (error) { |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
355 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
356 |
"%s\n", error->message); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
357 |
g_error_free (error); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
358 |
} |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
359 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
360 |
_lm_sock_shutdown (socket->fd); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
361 |
_lm_sock_close (socket->fd); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
362 |
|
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
363 |
if (!delayed && socket->connect_func) { |
277
f3ad3d16c8b5
Fixed SSL verification when old-style SSL connection is used.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
276
diff
changeset
|
364 |
(socket->connect_func) (socket, FALSE, socket->user_data); |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
365 |
} |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
366 |
|
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
367 |
return FALSE; |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
368 |
} |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
369 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
370 |
#ifdef HAVE_GNUTLS |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
371 |
_lm_sock_set_blocking (socket->fd, FALSE); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
372 |
#endif |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
373 |
|
298
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
374 |
socket->ssl_started = TRUE; |
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
375 |
|
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
376 |
return TRUE; |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
377 |
} |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
378 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
379 |
gboolean |
291
cebf76f7f0e9
Simplify and fix SSL/StartTLS handling in LmSocket
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
282
diff
changeset
|
380 |
lm_socket_starttls (LmSocket *socket) |
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
381 |
{ |
298
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
382 |
g_return_val_if_fail (lm_ssl_get_use_starttls (socket->ssl) == TRUE, FALSE); |
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
383 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
384 |
return _lm_socket_ssl_init (socket, TRUE); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
385 |
} |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
386 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
387 |
|
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
388 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
389 |
void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
390 |
_lm_socket_succeeded (LmConnectData *connect_data) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
391 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
392 |
LmSocket *socket; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
393 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
394 |
socket = connect_data->socket; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
395 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
396 |
if (socket->watch_connect) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
397 |
g_source_destroy (socket->watch_connect); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
398 |
socket->watch_connect = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
399 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
400 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
401 |
/* Need some way to report error/success */ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
402 |
if (socket->cancel_open) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
403 |
lm_verbose ("Cancelling connection...\n"); |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
404 |
if (socket->connect_func) { |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
405 |
(socket->connect_func) (socket, FALSE, socket->user_data); |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
406 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
407 |
return; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
408 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
409 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
410 |
socket->fd = connect_data->fd; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
411 |
socket->io_channel = connect_data->io_channel; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
412 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
413 |
freeaddrinfo (connect_data->resolved_addrs); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
414 |
socket->connect_data = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
415 |
g_free (connect_data); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
416 |
|
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
417 |
/* old-style ssl should be started immediately */ |
298
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
418 |
if (socket->ssl && (lm_ssl_get_use_starttls (socket->ssl) == FALSE)) { |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
419 |
if (!_lm_socket_ssl_init (socket, FALSE)) { |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
420 |
return; |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
421 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
422 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
423 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
424 |
socket->watch_in = |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
425 |
lm_misc_add_io_watch (socket->context, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
426 |
socket->io_channel, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
427 |
G_IO_IN, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
428 |
(GIOFunc) socket_in_event, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
429 |
socket); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
430 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
431 |
/* FIXME: if we add these, we don't get ANY |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
432 |
* response from the server, this is to do with the way that |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
433 |
* windows handles watches, see bug #331214. |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
434 |
*/ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
435 |
#ifndef G_OS_WIN32 |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
436 |
socket->watch_err = |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
437 |
lm_misc_add_io_watch (socket->context, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
438 |
socket->io_channel, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
439 |
G_IO_ERR, |
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
440 |
(GIOFunc) socket_error_event, |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
441 |
socket); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
442 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
443 |
socket->watch_hup = |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
444 |
lm_misc_add_io_watch (socket->context, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
445 |
socket->io_channel, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
446 |
G_IO_HUP, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
447 |
(GIOFunc) socket_hup_event, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
448 |
socket); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
449 |
#endif |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
450 |
|
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
451 |
if (socket->connect_func) { |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
452 |
(socket->connect_func) (socket, TRUE, socket->user_data); |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
453 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
454 |
} |
151 | 455 |
|
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
456 |
gboolean |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
457 |
_lm_socket_failed_with_error (LmConnectData *connect_data, int error) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
458 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
459 |
LmSocket *socket; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
460 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
461 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
462 |
"Connection failed: %s (error %d)\n", |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
463 |
_lm_sock_get_error_str (error), error); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
464 |
|
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
465 |
socket = lm_socket_ref (connect_data->socket); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
466 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
467 |
connect_data->current_addr = connect_data->current_addr->ai_next; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
468 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
469 |
if (socket->watch_connect) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
470 |
g_source_destroy (socket->watch_connect); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
471 |
socket->watch_connect = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
472 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
473 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
474 |
if (connect_data->io_channel != NULL) { |
346
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
475 |
socket_close_io_channel (connect_data->io_channel); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
476 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
477 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
478 |
if (connect_data->current_addr == NULL) { |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
479 |
if (socket->connect_func) { |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
480 |
(socket->connect_func) (socket, FALSE, socket->user_data); |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
481 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
482 |
|
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
483 |
/* if the user callback called connection_close(), this is already freed */ |
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
484 |
if (socket->connect_data != NULL) { |
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
485 |
freeaddrinfo (connect_data->resolved_addrs); |
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
486 |
socket->connect_data = NULL; |
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
487 |
g_free (connect_data); |
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
488 |
} |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
489 |
} else { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
490 |
/* try to connect to the next host */ |
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
491 |
return socket_do_connect (connect_data); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
492 |
} |
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
493 |
|
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
494 |
lm_socket_unref(socket); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
495 |
|
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
496 |
return FALSE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
497 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
498 |
|
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
499 |
gboolean |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
500 |
_lm_socket_failed (LmConnectData *connect_data) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
501 |
{ |
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
502 |
return _lm_socket_failed_with_error (connect_data, |
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
503 |
_lm_sock_get_last_error()); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
504 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
505 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
506 |
static gboolean |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
507 |
socket_connect_cb (GIOChannel *source, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
508 |
GIOCondition condition, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
509 |
LmConnectData *connect_data) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
510 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
511 |
LmSocket *socket; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
512 |
struct addrinfo *addr; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
513 |
int err; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
514 |
socklen_t len; |
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
515 |
LmSocketT fd; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
516 |
gboolean result = FALSE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
517 |
|
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
518 |
socket = lm_socket_ref (connect_data->socket); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
519 |
addr = connect_data->current_addr; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
520 |
fd = g_io_channel_unix_get_fd (source); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
521 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
522 |
if (condition == G_IO_ERR) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
523 |
len = sizeof (err); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
524 |
_lm_sock_get_error (fd, &err, &len); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
525 |
if (!_lm_sock_is_blocking_error (err)) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
526 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
527 |
"Connection failed.\n"); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
528 |
|
330
f606ce2a849e
Properly behave if we manage to connect in the second attempt.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
325
diff
changeset
|
529 |
/* error condition, but might be possible to recover |
f606ce2a849e
Properly behave if we manage to connect in the second attempt.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
325
diff
changeset
|
530 |
* from it (by connecting to the next host) */ |
f606ce2a849e
Properly behave if we manage to connect in the second attempt.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
325
diff
changeset
|
531 |
if (!_lm_socket_failed_with_error (connect_data, err)) { |
f606ce2a849e
Properly behave if we manage to connect in the second attempt.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
325
diff
changeset
|
532 |
socket->watch_connect = NULL; |
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
533 |
goto out; |
330
f606ce2a849e
Properly behave if we manage to connect in the second attempt.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
325
diff
changeset
|
534 |
} |
151 | 535 |
} |
536 |
} |
|
537 |
||
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
538 |
if (_lm_connection_async_connect_waiting (socket->connection)) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
539 |
gint res; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
540 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
541 |
fd = g_io_channel_unix_get_fd (source); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
542 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
543 |
res = _lm_sock_connect (fd, addr->ai_addr, (int)addr->ai_addrlen); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
544 |
if (res < 0) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
545 |
err = _lm_sock_get_last_error (); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
546 |
if (_lm_sock_is_blocking_success (err)) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
547 |
_lm_connection_set_async_connect_waiting (socket->connection, FALSE); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
548 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
549 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
550 |
"Connection success (1).\n"); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
551 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
552 |
_lm_socket_succeeded (connect_data); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
553 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
554 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
555 |
if (_lm_connection_async_connect_waiting (socket->connection) && |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
556 |
!_lm_sock_is_blocking_error (err)) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
557 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
558 |
"Connection failed.\n"); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
559 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
560 |
_lm_sock_close (connect_data->fd); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
561 |
_lm_socket_failed_with_error (connect_data, err); |
151 | 562 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
563 |
socket->watch_connect = NULL; |
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
564 |
goto out; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
565 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
566 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
567 |
} else { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
568 |
/* for blocking sockets, G_IO_OUT means we are connected */ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
569 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
570 |
"Connection success (2).\n"); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
571 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
572 |
_lm_socket_succeeded (connect_data); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
573 |
} |
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
574 |
|
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
575 |
result = TRUE; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
576 |
|
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
577 |
out: |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
578 |
lm_socket_unref(socket); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
579 |
|
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
580 |
return result; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
581 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
582 |
|
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
583 |
static gboolean |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
584 |
socket_do_connect (LmConnectData *connect_data) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
585 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
586 |
LmSocket *socket; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
587 |
LmSocketT fd; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
588 |
int res, err; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
589 |
int port; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
590 |
char name[NI_MAXHOST]; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
591 |
char portname[NI_MAXSERV]; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
592 |
struct addrinfo *addr; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
593 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
594 |
socket = connect_data->socket; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
595 |
addr = connect_data->current_addr; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
596 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
597 |
if (socket->proxy) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
598 |
port = htons (lm_proxy_get_port (socket->proxy)); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
599 |
} else { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
600 |
port = htons (socket->port); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
601 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
602 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
603 |
((struct sockaddr_in *) addr->ai_addr)->sin_port = port; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
604 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
605 |
res = getnameinfo (addr->ai_addr, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
606 |
(socklen_t)addr->ai_addrlen, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
607 |
name, sizeof (name), |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
608 |
portname, sizeof (portname), |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
609 |
NI_NUMERICHOST | NI_NUMERICSERV); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
610 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
611 |
if (res < 0) { |
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
612 |
return _lm_socket_failed (connect_data); |
151 | 613 |
} |
614 |
||
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
615 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
616 |
"Trying %s port %s...\n", name, portname); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
617 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
618 |
fd = _lm_sock_makesocket (addr->ai_family, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
619 |
addr->ai_socktype, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
620 |
addr->ai_protocol); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
621 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
622 |
if (!_LM_SOCK_VALID (fd)) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
623 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
624 |
"Failed making socket, error:%d...\n", |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
625 |
_lm_sock_get_last_error ()); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
626 |
|
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
627 |
return _lm_socket_failed (connect_data); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
628 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
629 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
630 |
/* Even though it says _unix_new(), it is supported by glib on |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
631 |
* win32 because glib does some cool stuff to find out if it |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
632 |
* can treat it as a FD or a windows SOCKET. |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
633 |
*/ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
634 |
connect_data->fd = fd; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
635 |
connect_data->io_channel = g_io_channel_unix_new (fd); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
636 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
637 |
g_io_channel_set_encoding (connect_data->io_channel, NULL, NULL); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
638 |
g_io_channel_set_buffered (connect_data->io_channel, FALSE); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
639 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
640 |
_lm_sock_set_blocking (connect_data->fd, socket->blocking); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
641 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
642 |
if (socket->proxy) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
643 |
socket->watch_connect = |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
644 |
lm_misc_add_io_watch (socket->context, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
645 |
connect_data->io_channel, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
646 |
G_IO_OUT|G_IO_ERR, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
647 |
(GIOFunc) _lm_proxy_connect_cb, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
648 |
connect_data); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
649 |
} else { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
650 |
socket->watch_connect = |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
651 |
lm_misc_add_io_watch (socket->context, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
652 |
connect_data->io_channel, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
653 |
G_IO_OUT|G_IO_ERR, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
654 |
(GIOFunc) socket_connect_cb, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
655 |
connect_data); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
656 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
657 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
658 |
_lm_connection_set_async_connect_waiting (socket->connection, !socket->blocking); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
659 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
660 |
res = _lm_sock_connect (connect_data->fd, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
661 |
addr->ai_addr, (int)addr->ai_addrlen); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
662 |
if (res < 0) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
663 |
err = _lm_sock_get_last_error (); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
664 |
if (!_lm_sock_is_blocking_error (err)) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
665 |
_lm_sock_close (connect_data->fd); |
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
666 |
return _lm_socket_failed_with_error (connect_data, err); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
667 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
668 |
} |
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
669 |
|
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
670 |
return TRUE; |
149 | 671 |
} |
672 |
||
673 |
gboolean |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
674 |
lm_socket_output_is_buffered (LmSocket *socket, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
675 |
const gchar *buffer, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
676 |
gint len) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
677 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
678 |
if (socket->out_buf) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
679 |
lm_verbose ("Appending %d bytes to output buffer\n", len); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
680 |
g_string_append_len (socket->out_buf, buffer, len); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
681 |
return TRUE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
682 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
683 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
684 |
return FALSE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
685 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
686 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
687 |
void |
249 | 688 |
lm_socket_setup_output_buffer (LmSocket *socket, const gchar *buffer, gint len) |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
689 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
690 |
lm_verbose ("OUTPUT BUFFER ENABLED\n"); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
691 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
692 |
socket->out_buf = g_string_new_len (buffer, len); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
693 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
694 |
socket->watch_out = |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
695 |
lm_misc_add_io_watch (socket->context, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
696 |
socket->io_channel, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
697 |
G_IO_OUT, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
698 |
(GIOFunc) socket_buffered_write_cb, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
699 |
socket); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
700 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
701 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
702 |
static gboolean |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
703 |
socket_buffered_write_cb (GIOChannel *source, |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
704 |
GIOCondition condition, |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
705 |
LmSocket *socket) |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
706 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
707 |
gint b_written; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
708 |
GString *out_buf; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
709 |
/* FIXME: Do the writing */ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
710 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
711 |
out_buf = socket->out_buf; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
712 |
if (!out_buf) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
713 |
/* Should not be possible */ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
714 |
return FALSE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
715 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
716 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
717 |
b_written = lm_socket_do_write (socket, out_buf->str, out_buf->len); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
718 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
719 |
if (b_written < 0) { |
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
720 |
(socket->closed_func) (socket, LM_DISCONNECT_REASON_ERROR, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
721 |
socket->user_data); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
722 |
return FALSE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
723 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
724 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
725 |
g_string_erase (out_buf, 0, (gsize) b_written); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
726 |
if (out_buf->len == 0) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
727 |
lm_verbose ("Output buffer is empty, going back to normal output\n"); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
728 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
729 |
if (socket->watch_out) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
730 |
g_source_destroy (socket->watch_out); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
731 |
socket->watch_out = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
732 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
733 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
734 |
g_string_free (out_buf, TRUE); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
735 |
socket->out_buf = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
736 |
return FALSE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
737 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
738 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
739 |
return TRUE; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
740 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
741 |
|
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
742 |
static gboolean |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
743 |
socket_parse_srv_response (unsigned char *srv, |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
744 |
int srv_len, |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
745 |
gchar **out_server, |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
746 |
guint *out_port) |
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
747 |
{ |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
748 |
int qdcount; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
749 |
int ancount; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
750 |
int len; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
751 |
const unsigned char *pos; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
752 |
unsigned char *end; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
753 |
HEADER *head; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
754 |
char name[256]; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
755 |
char pref_name[256]; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
756 |
guint pref_port = 0; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
757 |
guint pref_prio = 9999; |
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
758 |
|
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
759 |
pref_name[0] = 0; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
760 |
|
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
761 |
pos = srv + sizeof (HEADER); |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
762 |
end = srv + srv_len; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
763 |
head = (HEADER *) srv; |
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
764 |
|
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
765 |
qdcount = ntohs (head->qdcount); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
766 |
ancount = ntohs (head->ancount); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
767 |
|
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
768 |
/* Ignore the questions */ |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
769 |
while (qdcount-- > 0 && (len = dn_expand (srv, end, pos, name, 255)) >= 0) { |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
770 |
g_assert (len >= 0); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
771 |
pos += len + QFIXEDSZ; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
772 |
} |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
773 |
|
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
774 |
/* Parse the answers */ |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
775 |
while (ancount-- > 0 && (len = dn_expand (srv, end, pos, name, 255)) >= 0) { |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
776 |
/* Ignore the initial string */ |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
777 |
uint16_t pref, weight, port; |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
778 |
|
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
779 |
g_assert (len >= 0); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
780 |
pos += len; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
781 |
/* Ignore type, ttl, class and dlen */ |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
782 |
pos += 10; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
783 |
GETSHORT (pref, pos); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
784 |
GETSHORT (weight, pos); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
785 |
GETSHORT (port, pos); |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
786 |
|
243
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
787 |
len = dn_expand (srv, end, pos, name, 255); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
788 |
if (pref < pref_prio) { |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
789 |
pref_prio = pref; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
790 |
strcpy (pref_name, name); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
791 |
pref_port = port; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
792 |
} |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
793 |
pos += len; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
794 |
} |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
795 |
|
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
796 |
if (pref_name[0]) { |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
797 |
*out_server = g_strdup (pref_name); |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
798 |
*out_port = pref_port; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
799 |
return TRUE; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
800 |
} |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
801 |
return FALSE; |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
802 |
} |
fa0794ef3570
Implement SRV lookups, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents:
212
diff
changeset
|
803 |
|
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
804 |
static void |
346
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
805 |
socket_close_io_channel (GIOChannel *io_channel) |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
806 |
{ |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
807 |
gint fd; |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
808 |
|
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
809 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
810 |
"Freeing up IOChannel and file descriptor\n"); |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
811 |
|
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
812 |
fd = g_io_channel_unix_get_fd (io_channel); |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
813 |
|
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
814 |
g_io_channel_unref (io_channel); |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
815 |
|
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
816 |
_lm_sock_close (fd); |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
817 |
} |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
818 |
|
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
819 |
static void |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
820 |
_lm_socket_create_phase1 (LmSocket *socket, unsigned char *srv_ans, int len); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
821 |
static void |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
822 |
_lm_socket_create_phase2 (LmSocket *socket, struct addrinfo *ans); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
823 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
824 |
#ifdef HAVE_ASYNCNS |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
825 |
#define PHASE_1 0 |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
826 |
#define PHASE_2 1 |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
827 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
828 |
static gboolean |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
829 |
_lm_socket_resolver_done (GSource *source, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
830 |
GIOCondition condition, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
831 |
gpointer data); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
832 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
833 |
|
280
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
834 |
static void |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
835 |
_asyncns_done (LmSocket *socket) |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
836 |
{ |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
837 |
if (socket->resolv_channel != NULL) { |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
838 |
g_io_channel_unref (socket->resolv_channel); |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
839 |
socket->resolv_channel = NULL; |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
840 |
} |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
841 |
|
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
842 |
if (socket->watch_resolv) { |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
843 |
g_source_destroy(socket->watch_resolv); |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
844 |
socket->watch_resolv = NULL; |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
845 |
} |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
846 |
|
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
847 |
if (socket->asyncns_ctx) { |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
848 |
asyncns_free (socket->asyncns_ctx); |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
849 |
socket->asyncns_ctx = NULL; |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
850 |
} |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
851 |
|
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
852 |
socket->resolv_query = NULL; |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
853 |
} |
f1bfa3d3ad1c
hoist _asyncns_done to above where it is first called
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
279
diff
changeset
|
854 |
|
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
855 |
void _asyncns_cancel (LmSocket *socket) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
856 |
{ |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
857 |
if (socket == NULL) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
858 |
return; |
276
3b05eae99e1a
Fixed (double) asyncns cancellation bug, and made the code more robust.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
275
diff
changeset
|
859 |
|
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
860 |
if (socket->asyncns_ctx) { |
282
0bd1892a18d3
Fix another crash in asyncns cancel code
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
280
diff
changeset
|
861 |
if (socket->resolv_query) |
0bd1892a18d3
Fix another crash in asyncns cancel code
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
280
diff
changeset
|
862 |
asyncns_cancel (socket->asyncns_ctx, socket->resolv_query); |
0bd1892a18d3
Fix another crash in asyncns cancel code
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
280
diff
changeset
|
863 |
|
276
3b05eae99e1a
Fixed (double) asyncns cancellation bug, and made the code more robust.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
275
diff
changeset
|
864 |
_asyncns_done (socket); |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
865 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
866 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
867 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
868 |
static gboolean |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
869 |
_asyncns_prep (LmSocket *socket, GError **error) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
870 |
{ |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
871 |
if (socket->asyncns_ctx) { |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
872 |
return TRUE; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
873 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
874 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
875 |
socket->asyncns_ctx = asyncns_new (1); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
876 |
if (socket->asyncns_ctx == NULL) { |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
877 |
g_set_error (error, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
878 |
LM_ERROR, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
879 |
LM_ERROR_CONNECTION_FAILED, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
880 |
"can't initialise libasyncns"); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
881 |
return FALSE; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
882 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
883 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
884 |
socket->resolv_channel = |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
885 |
g_io_channel_unix_new (asyncns_fd (socket->asyncns_ctx)); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
886 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
887 |
socket->watch_resolv = |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
888 |
lm_misc_add_io_watch (socket->context, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
889 |
socket->resolv_channel, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
890 |
G_IO_IN, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
891 |
(GIOFunc) _lm_socket_resolver_done, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
892 |
socket); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
893 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
894 |
return TRUE; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
895 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
896 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
897 |
static gboolean |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
898 |
_lm_socket_resolver_done (GSource *source, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
899 |
GIOCondition condition, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
900 |
gpointer data) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
901 |
{ |
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
902 |
LmSocket *socket = lm_socket_ref ((LmSocket *) data); |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
903 |
struct addrinfo *ans; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
904 |
unsigned char *srv_ans; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
905 |
int err; |
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
906 |
gboolean result = FALSE; |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
907 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
908 |
/* process pending data */ |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
909 |
asyncns_wait (socket->asyncns_ctx, FALSE); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
910 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
911 |
if (!asyncns_isdone (socket->asyncns_ctx, socket->resolv_query)) { |
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
912 |
result = TRUE; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
913 |
} else { |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
914 |
switch ((guint) asyncns_getuserdata (socket->asyncns_ctx, socket->resolv_query)) { |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
915 |
case PHASE_1: |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
916 |
err = asyncns_res_done (socket->asyncns_ctx, socket->resolv_query, &srv_ans); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
917 |
socket->resolv_query = NULL; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
918 |
_lm_socket_create_phase1 (socket, (err <= 0) ? NULL : srv_ans, err); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
919 |
result = TRUE; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
920 |
break; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
921 |
case PHASE_2: |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
922 |
err = asyncns_getaddrinfo_done (socket->asyncns_ctx, socket->resolv_query, &ans); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
923 |
socket->resolv_query = NULL; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
924 |
_lm_socket_create_phase2 (socket, (err) ? NULL : ans); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
925 |
_asyncns_done (socket); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
926 |
break; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
927 |
default: |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
928 |
g_assert_not_reached(); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
929 |
break; |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
930 |
} |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
931 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
932 |
|
343
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
933 |
lm_socket_unref(socket); |
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
934 |
|
35a19649d773
Fixed reentrancy problem for async connections. Fixes first bit of LM-117.
Owen Taylor <otaylor@redhat.com>
parents:
338
diff
changeset
|
935 |
return result; |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
936 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
937 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
938 |
#endif |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
939 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
940 |
static void |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
941 |
_lm_socket_create_phase1 (LmSocket *socket, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
942 |
unsigned char *srv_ans, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
943 |
int len) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
944 |
{ |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
945 |
const char *remote_addr; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
946 |
LmConnectData *data; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
947 |
struct addrinfo req; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
948 |
#ifndef HAVE_ASYNCNS |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
949 |
struct addrinfo *ans; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
950 |
int err; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
951 |
#endif |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
952 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
953 |
if (srv_ans != NULL) { |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
954 |
gchar *new_server; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
955 |
guint new_port; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
956 |
gboolean result; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
957 |
result = socket_parse_srv_response (srv_ans, len, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
958 |
&new_server, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
959 |
&new_port); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
960 |
if (result == TRUE) { |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
961 |
g_free (socket->server); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
962 |
socket->server = new_server; |
325
6e561a2cc542
Always use the port provided by the SRV lookup.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
322
diff
changeset
|
963 |
socket->port = new_port; |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
964 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
965 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
966 |
|
275
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
967 |
/* If server wasn't specified and SRV failed, use domain */ |
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
968 |
if (!socket->server) { |
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
969 |
lm_verbose ("SRV lookup failed, trying jid domain\n"); |
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
970 |
socket->server = g_strdup (socket->domain); |
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
971 |
} |
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
972 |
|
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
973 |
if (socket->proxy) { |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
974 |
remote_addr = lm_proxy_get_server (socket->proxy); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
975 |
} else { |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
976 |
remote_addr = socket->server; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
977 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
978 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
979 |
g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
980 |
"Going to connect to %s%s:%u\n", (socket->proxy) ? "proxy " : "", |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
981 |
remote_addr, socket->port); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
982 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
983 |
data = g_new0 (LmConnectData, 1); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
984 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
985 |
data->socket = socket; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
986 |
data->connection = socket->connection; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
987 |
data->fd = -1; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
988 |
socket->connect_data = data; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
989 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
990 |
memset (&req, 0, sizeof(req)); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
991 |
req.ai_family = AF_UNSPEC; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
992 |
req.ai_socktype = SOCK_STREAM; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
993 |
req.ai_protocol = IPPROTO_TCP; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
994 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
995 |
#ifdef HAVE_ASYNCNS |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
996 |
if (!_asyncns_prep (socket, NULL)) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
997 |
return; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
998 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
999 |
socket->resolv_query = |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1000 |
asyncns_getaddrinfo (socket->asyncns_ctx, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1001 |
remote_addr, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1002 |
NULL, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1003 |
&req); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1004 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1005 |
asyncns_setuserdata (socket->asyncns_ctx, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1006 |
socket->resolv_query, |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1007 |
(gpointer) PHASE_2); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1008 |
#else |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1009 |
err = getaddrinfo (remote_addr, NULL, &req, &ans); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1010 |
_lm_socket_create_phase2 (socket, (err) ? NULL : ans); |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1011 |
if (err != 0) { |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1012 |
return; |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1013 |
} |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1014 |
#endif |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1015 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1016 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1017 |
static void |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1018 |
_lm_socket_create_phase2 (LmSocket *socket, struct addrinfo *ans) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1019 |
{ |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1020 |
if (ans == NULL) { |
275
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
1021 |
lm_verbose ("error while resolving, bailing out\n"); |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1022 |
if (socket->connect_func) { |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1023 |
(socket->connect_func) (socket, FALSE, socket->user_data); |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1024 |
} |
575
daad23d59b56
Don't check for sync dns problems when using asyncns [#33]
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
552
diff
changeset
|
1025 |
g_free (socket->connect_data); |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1026 |
socket->connect_data = NULL; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1027 |
return; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1028 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1029 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1030 |
socket->connect_data->resolved_addrs = ans; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1031 |
socket->connect_data->current_addr = ans; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1032 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1033 |
socket_do_connect (socket->connect_data); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1034 |
} |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1035 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1036 |
LmSocket * |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1037 |
lm_socket_create (GMainContext *context, |
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
1038 |
IncomingDataFunc data_func, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
1039 |
SocketClosedFunc closed_func, |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
1040 |
ConnectResultFunc connect_func, |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1041 |
gpointer user_data, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1042 |
LmConnection *connection, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1043 |
gboolean blocking, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1044 |
const gchar *server, |
275
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
1045 |
const gchar *domain, |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1046 |
guint port, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1047 |
LmSSL *ssl, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1048 |
LmProxy *proxy, |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1049 |
GError **error) |
149 | 1050 |
{ |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1051 |
LmSocket *socket; |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1052 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1053 |
#ifndef HAVE_ASYNCNS |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1054 |
unsigned char srv_ans[SRV_LEN]; |
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
1055 |
int len; |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1056 |
#endif |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
1057 |
|
275
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
1058 |
g_return_val_if_fail (domain != NULL, NULL); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1059 |
g_return_val_if_fail ((port >= MIN_PORT && port <= MAX_PORT), NULL); |
256
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
1060 |
g_return_val_if_fail (data_func != NULL, NULL); |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
1061 |
g_return_val_if_fail (closed_func != NULL, NULL); |
2266e56746ed
Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents:
249
diff
changeset
|
1062 |
g_return_val_if_fail (connect_func != NULL, NULL); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1063 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1064 |
socket = g_new0 (LmSocket, 1); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1065 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1066 |
socket->ref_count = 1; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1067 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1068 |
socket->connection = connection; |
275
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
1069 |
socket->domain = g_strdup (domain); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1070 |
socket->server = g_strdup (server); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1071 |
socket->port = port; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1072 |
socket->cancel_open = FALSE; |
291
cebf76f7f0e9
Simplify and fix SSL/StartTLS handling in LmSocket
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
282
diff
changeset
|
1073 |
socket->ssl = ssl; |
298
71aaed5a9c34
Properly detect if SSL has been started in case of StartTLS usage.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
292
diff
changeset
|
1074 |
socket->ssl_started = FALSE; |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1075 |
socket->proxy = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1076 |
socket->blocking = blocking; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1077 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1078 |
if (context) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1079 |
socket->context = g_main_context_ref (context); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1080 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1081 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1082 |
if (proxy) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1083 |
socket->proxy = lm_proxy_ref (proxy); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1084 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1085 |
|
275
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
1086 |
if (!server) { |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1087 |
char *srv; |
275
37937c612f62
Made SRV handling more sane, and implemented fallback using jid domain name.
Senko Rasic <senko@phyrexia.(none)>
parents:
274
diff
changeset
|
1088 |
srv = g_strdup_printf ("_xmpp-client._tcp.%s", socket->domain); |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1089 |
lm_verbose ("Performing a SRV lookup for %s\n", srv); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1090 |
|
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1091 |
#ifdef HAVE_ASYNCNS |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1092 |
if (!_asyncns_prep (socket, error)) |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1093 |
return NULL; |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1094 |
|
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1095 |
socket->resolv_query = |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1096 |
asyncns_res_query (socket->asyncns_ctx, srv, C_IN, T_SRV); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1097 |
asyncns_setuserdata (socket->asyncns_ctx, socket->resolv_query, (gpointer) PHASE_1); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1098 |
#else |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1099 |
res_init (); |
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1100 |
|
274
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
1101 |
len = res_query (srv, C_IN, T_SRV, srv_ans, SRV_LEN); |
c32a7011e435
Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents:
272
diff
changeset
|
1102 |
_lm_socket_create_phase1 (socket, (len < 1) ? NULL : srv_ans, len); |
271
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1103 |
g_free (srv); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1104 |
#endif |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1105 |
} else { |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1106 |
lm_verbose ("SRV lookup disabled for %s\n", socket->server); |
52ea4e0b897a
Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents:
257
diff
changeset
|
1107 |
_lm_socket_create_phase1 (socket, NULL, 0); |
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
1108 |
} |
244
8a05b79bad24
Make use_srv optional in LmSocket and plugged a leak.
Mikael Hallendal <micke@imendio.com>
parents:
243
diff
changeset
|
1109 |
|
575
daad23d59b56
Don't check for sync dns problems when using asyncns [#33]
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
552
diff
changeset
|
1110 |
#ifndef HAVE_ASYNCNS |
daad23d59b56
Don't check for sync dns problems when using asyncns [#33]
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
552
diff
changeset
|
1111 |
/* Only do this check if we are not using asyncns or it will crash. |
daad23d59b56
Don't check for sync dns problems when using asyncns [#33]
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
552
diff
changeset
|
1112 |
* Report and patch by Senko. |
daad23d59b56
Don't check for sync dns problems when using asyncns [#33]
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
552
diff
changeset
|
1113 |
*/ |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1114 |
if (socket->connect_data == NULL) { |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1115 |
/* Open failed synchronously, probably a DNS lookup problem */ |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1116 |
lm_socket_unref(socket); |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1117 |
|
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1118 |
g_set_error (error, |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1119 |
LM_ERROR, |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1120 |
LM_ERROR_CONNECTION_FAILED, |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1121 |
"Failed to resolve server"); |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1122 |
|
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1123 |
return NULL; |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1124 |
} |
575
daad23d59b56
Don't check for sync dns problems when using asyncns [#33]
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
552
diff
changeset
|
1125 |
#endif /* HAVE_ASYNCNS */ |
344
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1126 |
|
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1127 |
|
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1128 |
/* If the connection fails synchronously, we don't want to call the |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1129 |
* connect_func to indicate an error, we return an error indication |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1130 |
* instead. So, we delay saving the functions until after we know |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1131 |
* we are going to return success. |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1132 |
*/ |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1133 |
socket->data_func = data_func; |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1134 |
socket->closed_func = closed_func; |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1135 |
socket->connect_func = connect_func; |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1136 |
socket->user_data = user_data; |
11473296fea5
Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents:
343
diff
changeset
|
1137 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1138 |
return socket; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1139 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1140 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1141 |
void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1142 |
lm_socket_flush (LmSocket *socket) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1143 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1144 |
g_return_if_fail (socket != NULL); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1145 |
g_return_if_fail (socket->io_channel != NULL); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1146 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1147 |
g_io_channel_flush (socket->io_channel, NULL); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1148 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1149 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1150 |
void |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1151 |
lm_socket_close (LmSocket *socket) |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1152 |
{ |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1153 |
LmConnectData *data; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1154 |
|
212
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
1155 |
g_return_if_fail (socket != NULL); |
87bc6b37a9e9
Improved error checking in LmSocket when connecting.
Mikael Hallendal <micke@imendio.com>
parents:
202
diff
changeset
|
1156 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1157 |
if (socket->watch_connect) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1158 |
g_source_destroy (socket->watch_connect); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1159 |
socket->watch_connect = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1160 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1161 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1162 |
data = socket->connect_data; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1163 |
if (data) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1164 |
freeaddrinfo (data->resolved_addrs); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1165 |
socket->connect_data = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1166 |
g_free (data); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1167 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1168 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1169 |
if (socket->io_channel) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1170 |
if (socket->watch_in) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1171 |
g_source_destroy (socket->watch_in); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1172 |
socket->watch_in = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1173 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1174 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1175 |
if (socket->watch_err) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1176 |
g_source_destroy (socket->watch_err); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1177 |
socket->watch_err = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1178 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1179 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1180 |
if (socket->watch_hup) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1181 |
g_source_destroy (socket->watch_hup); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1182 |
socket->watch_hup = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1183 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1184 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1185 |
if (socket->watch_out) { |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1186 |
g_source_destroy (socket->watch_out); |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1187 |
socket->watch_out = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1188 |
} |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1189 |
|
346
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
1190 |
socket_close_io_channel (socket->io_channel); |
ca353cc81e9a
Close the socket before setting it to -1. This hopefully solves LM-95.
Mikael Hallendal <micke@imendio.com>
parents:
344
diff
changeset
|
1191 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1192 |
socket->io_channel = NULL; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1193 |
socket->fd = -1; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1194 |
} |
149 | 1195 |
} |
1196 |
||
308
7e2050a6df75
Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
299
diff
changeset
|
1197 |
gchar * |
7e2050a6df75
Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
299
diff
changeset
|
1198 |
lm_socket_get_local_host (LmSocket *socket) |
7e2050a6df75
Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
299
diff
changeset
|
1199 |
{ |
7e2050a6df75
Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
299
diff
changeset
|
1200 |
return _lm_sock_get_local_host (socket->fd); |
7e2050a6df75
Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
299
diff
changeset
|
1201 |
} |
7e2050a6df75
Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
299
diff
changeset
|
1202 |
|
149 | 1203 |
LmSocket * |
1204 |
lm_socket_ref (LmSocket *socket) |
|
1205 |
{ |
|
1206 |
g_return_val_if_fail (socket != NULL, NULL); |
|
151 | 1207 |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1208 |
socket->ref_count++; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1209 |
|
149 | 1210 |
return socket; |
1211 |
} |
|
1212 |
||
1213 |
void |
|
1214 |
lm_socket_unref (LmSocket *socket) |
|
1215 |
{ |
|
1216 |
g_return_if_fail (socket != NULL); |
|
196
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1217 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1218 |
socket->ref_count--; |
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1219 |
|
209bfa124066
Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents:
161
diff
changeset
|
1220 |
if (socket->ref_count <= 0) { |
149 | 1221 |
socket_free (socket); |
147 | 1222 |
} |
1223 |
} |
|
149 | 1224 |
|
292
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1225 |
gboolean |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1226 |
lm_socket_set_keepalive (LmSocket *socket, int delay) |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1227 |
{ |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1228 |
#ifdef USE_TCP_KEEPALIVES |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1229 |
return _lm_sock_set_keepalive (socket->fd, delay); |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1230 |
#else |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1231 |
return FALSE; |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1232 |
#endif /* USE_TCP_KEEPALIVES */ |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1233 |
} |
bb7269466be2
Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents:
291
diff
changeset
|
1234 |