mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 20:40:21 +01:00
bluez: don't use GIOChannel to watch plain file descriptor
Also, don't track the GSource via the guint ID but the full GSource pointer.
This commit is contained in:
parent
cccfeb3891
commit
c15411d7c9
1 changed files with 48 additions and 41 deletions
|
|
@ -31,12 +31,12 @@ typedef struct {
|
|||
|
||||
GError *rfcomm_sdp_search_error;
|
||||
|
||||
GSource *source;
|
||||
|
||||
gint64 connect_open_tty_started_at;
|
||||
|
||||
gulong cancelled_id;
|
||||
|
||||
guint source_id;
|
||||
|
||||
guint8 sdp_session_try_count;
|
||||
} ConnectData;
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ _connect_open_tty_retry_cb (gpointer user_data)
|
|||
if (nm_utils_get_monotonic_timestamp_nsec () > context->cdat->connect_open_tty_started_at + (30 * 100 * NM_UTILS_NSEC_PER_MSEC)) {
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
context->cdat->source_id = 0;
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
g_set_error (&error,
|
||||
NM_BT_ERROR,
|
||||
NM_BT_ERROR_DUN_CONNECT_FAILED,
|
||||
|
|
@ -174,15 +174,18 @@ _connect_open_tty (NMBluez5DunContext *context)
|
|||
if (fd < 0) {
|
||||
errsv = NM_ERRNO_NATIVE (errno);
|
||||
|
||||
if (context->cdat->source_id == 0) {
|
||||
if (!context->cdat->source) {
|
||||
_LOGD (context, "failed opening tty "RFCOMM_FMT": %s (%d). Start polling...",
|
||||
context->rfcomm_tty_no,
|
||||
nm_strerror_native (errsv),
|
||||
errsv);
|
||||
context->cdat->connect_open_tty_started_at = nm_utils_get_monotonic_timestamp_nsec ();
|
||||
context->cdat->source_id = g_timeout_add (100,
|
||||
_connect_open_tty_retry_cb,
|
||||
context);
|
||||
context->cdat->source = nm_g_timeout_source_new (100,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_connect_open_tty_retry_cb,
|
||||
context,
|
||||
NULL);
|
||||
g_source_attach (context->cdat->source, NULL);
|
||||
}
|
||||
return -errsv;
|
||||
}
|
||||
|
|
@ -263,7 +266,7 @@ _connect_create_rfcomm (NMBluez5DunContext *context)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
_connect_socket_connect_cb (GIOChannel *stream,
|
||||
_connect_socket_connect_cb (int fd,
|
||||
GIOCondition condition,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
|
@ -273,7 +276,7 @@ _connect_socket_connect_cb (GIOChannel *stream,
|
|||
socklen_t slen = sizeof(errsv);
|
||||
int r;
|
||||
|
||||
context->cdat->source_id = 0;
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
|
||||
r = getsockopt (context->rfcomm_sock_fd, SOL_SOCKET, SO_ERROR, &errsv, &slen);
|
||||
|
||||
|
|
@ -346,7 +349,6 @@ _connect_socket_connect (NMBluez5DunContext *context)
|
|||
if (connect (context->rfcomm_sock_fd,
|
||||
(struct sockaddr *) &sa,
|
||||
sizeof (sa)) != 0) {
|
||||
nm_auto_unref_io_channel GIOChannel *io_channel = NULL;
|
||||
|
||||
errsv = errno;
|
||||
if (errsv != EINPROGRESS) {
|
||||
|
|
@ -363,11 +365,13 @@ _connect_socket_connect (NMBluez5DunContext *context)
|
|||
context->dst_str,
|
||||
context->rfcomm_channel);
|
||||
|
||||
io_channel = g_io_channel_unix_new (context->rfcomm_sock_fd);
|
||||
context->cdat->source_id = g_io_add_watch (io_channel,
|
||||
G_IO_OUT,
|
||||
_connect_socket_connect_cb,
|
||||
context);
|
||||
context->cdat->source = nm_g_unix_fd_source_new (context->rfcomm_sock_fd,
|
||||
G_IO_OUT,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_connect_socket_connect_cb,
|
||||
context,
|
||||
NULL);
|
||||
g_source_attach (context->cdat->source, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -466,7 +470,7 @@ _connect_sdp_search_cb (uint8_t type,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
_connect_sdp_search_io_cb (GIOChannel *io_channel,
|
||||
_connect_sdp_search_io_cb (int fd,
|
||||
GIOCondition condition,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
|
@ -480,7 +484,7 @@ _connect_sdp_search_io_cb (GIOChannel *io_channel,
|
|||
error = g_error_new (NM_BT_ERROR,
|
||||
NM_BT_ERROR_DUN_CONNECT_FAILED,
|
||||
"Service Discovery interrupted");
|
||||
context->cdat->source_id = 0;
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
_context_invoke_callback_fail_and_free (context, error);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
|
@ -490,7 +494,7 @@ _connect_sdp_search_io_cb (GIOChannel *io_channel,
|
|||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
context->cdat->source_id = 0;
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
|
||||
if ( context->rfcomm_channel < 0
|
||||
&& !context->cdat->rfcomm_sdp_search_error) {
|
||||
|
|
@ -524,7 +528,7 @@ _connect_sdp_session_start_on_idle_cb (gpointer user_data)
|
|||
NMBluez5DunContext *context = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
context->cdat->source_id = 0;
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
|
||||
_LOGD (context, "retry starting sdp-session...");
|
||||
|
||||
|
|
@ -535,7 +539,7 @@ _connect_sdp_session_start_on_idle_cb (gpointer user_data)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
_connect_sdp_io_cb (GIOChannel *io_channel,
|
||||
_connect_sdp_io_cb (int fd,
|
||||
GIOCondition condition,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
|
@ -544,16 +548,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel,
|
|||
sdp_list_t *attrs;
|
||||
uuid_t svclass;
|
||||
uint16_t attr;
|
||||
int fd;
|
||||
int errsv;
|
||||
int fd_err = 0;
|
||||
int r;
|
||||
socklen_t len = sizeof (fd_err);
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
context->cdat->source_id = 0;
|
||||
|
||||
fd = g_io_channel_unix_get_fd (io_channel);
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
|
||||
_LOGD (context, "sdp-session ready to connect with fd=%d", fd);
|
||||
|
||||
|
|
@ -572,10 +573,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel,
|
|||
&& --context->cdat->sdp_session_try_count > 0) {
|
||||
/* *sigh* */
|
||||
_LOGD (context, "sdp-session failed with %s (%d). Retry in a bit", nm_strerror_native (errsv), errsv);
|
||||
nm_clear_g_source (&context->cdat->source_id);
|
||||
context->cdat->source_id = g_timeout_add (1000,
|
||||
_connect_sdp_session_start_on_idle_cb,
|
||||
context);
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
context->cdat->source = nm_g_timeout_source_new (1000,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_connect_sdp_session_start_on_idle_cb,
|
||||
context,
|
||||
NULL);
|
||||
g_source_attach (context->cdat->source, NULL);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
|
|
@ -615,10 +619,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel,
|
|||
}
|
||||
|
||||
/* Set callback responsible for update the internal SDP transaction */
|
||||
context->cdat->source_id = g_io_add_watch (io_channel,
|
||||
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
||||
_connect_sdp_search_io_cb,
|
||||
context);
|
||||
context->cdat->source = nm_g_unix_fd_source_new (fd,
|
||||
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_connect_sdp_search_io_cb,
|
||||
context,
|
||||
NULL);
|
||||
g_source_attach (context->cdat->source, NULL);
|
||||
|
||||
done:
|
||||
if (error)
|
||||
|
|
@ -644,11 +651,9 @@ static gboolean
|
|||
_connect_sdp_session_start (NMBluez5DunContext *context,
|
||||
GError **error)
|
||||
{
|
||||
nm_auto_unref_io_channel GIOChannel *io_channel = NULL;
|
||||
|
||||
nm_assert (context->cdat);
|
||||
|
||||
nm_clear_g_source (&context->cdat->source_id);
|
||||
nm_clear_g_source_inst (&context->cdat->source);
|
||||
nm_clear_pointer (&context->cdat->sdp_session, sdp_close);
|
||||
|
||||
context->cdat->sdp_session = sdp_connect (&context->src, &context->dst, SDP_NON_BLOCKING);
|
||||
|
|
@ -661,11 +666,13 @@ _connect_sdp_session_start (NMBluez5DunContext *context,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
io_channel = g_io_channel_unix_new (sdp_get_socket (context->cdat->sdp_session));
|
||||
context->cdat->source_id = g_io_add_watch (io_channel,
|
||||
G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
||||
_connect_sdp_io_cb,
|
||||
context);
|
||||
context->cdat->source = nm_g_unix_fd_source_new (sdp_get_socket (context->cdat->sdp_session),
|
||||
G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
|
||||
G_PRIORITY_DEFAULT,
|
||||
_connect_sdp_io_cb,
|
||||
context,
|
||||
NULL);
|
||||
g_source_attach (context->cdat->source, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -772,7 +779,7 @@ _context_cleanup_connect_data (NMBluez5DunContext *context)
|
|||
|
||||
nm_clear_g_signal_handler (cdat->cancellable, &cdat->cancelled_id);
|
||||
|
||||
nm_clear_g_source (&cdat->source_id);
|
||||
nm_clear_g_source_inst (&cdat->source);
|
||||
|
||||
nm_clear_pointer (&cdat->sdp_session, sdp_close);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue