Re: [PATCH] tools/mcaptest: Don't block main loop when disconnection is expected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jakub,

On Thursday 06 of November 2014 10:33:05 Jakub Tyszkowski wrote:
> This triggers action after timeout without using sleep which was
> blocking main loop and mcaplib.
> ---
>  tools/mcaptest.c | 37 +++++++++++++++++++++++++------------
>  1 file changed, 25 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/mcaptest.c b/tools/mcaptest.c
> index 42734eb..bebc890 100644
> --- a/tools/mcaptest.c
> +++ b/tools/mcaptest.c
> @@ -71,31 +71,44 @@ static gboolean no_close = FALSE;
>  
>  #define REQ_CLOCK_ACC 0x1400
>  
> -static void mdl_connected_cb(struct mcap_mdl *mdl, void *data)
> +static gboolean close_mdl_timeout(gpointer user_data)
>  {
> +	struct mcap_mdl *mdl = user_data;
>  	int fd = -1;

This initialization is not needed now.
>  
> +	fd = mcap_mdl_get_fd(mdl);
> +
> +	if (fd > 0)
> +		close(fd);

0 is also valid fd. Probably won't happen with command line tool but lets
be consistent on this.

> +
> +	return FALSE;
> +}
> +
> +static void mdl_connected_cb(struct mcap_mdl *mdl, void *data)
> +{
>  	printf("%s\n", __func__);
>  
> -	if (mdl_disconnect && mdl_disconnect_timeout >= 0) {
> -		sleep(mdl_disconnect_timeout);
> +	if (mdl_disconnect && mdl_disconnect_timeout >= 0)
> +		g_timeout_add(mdl_disconnect_timeout * 1000, close_mdl_timeout,
> +									mdl);
> +}
>  
> -		fd = mcap_mdl_get_fd(mdl);
> +static gboolean close_mcl_timeout(gpointer user_data)
> +{
> +	struct mcap_mcl *mcl = user_data;
>  
> -		if (fd > 0)
> -			close(fd);
> -	}
> +	mcap_close_mcl(mcl, TRUE);
> +
> +	return FALSE;
>  }
>  
>  static void mdl_closed_cb(struct mcap_mdl *mdl, void *data)
>  {
>  	printf("%s\n", __func__);
>  
> -	if (mcl_disconnect && mcl_disconnect_timeout >= 0) {
> -		sleep(mcl_disconnect_timeout);
> -
> -		mcap_close_mcl(mcl, TRUE);
> -	}
> +	if (mcl_disconnect && mcl_disconnect_timeout >= 0)
> +		g_timeout_add(mcl_disconnect_timeout * 1000, close_mcl_timeout,
> +									mcl);
>  }
>  
>  static void mdl_deleted_cb(struct mcap_mdl *mdl, void *data)
> 

-- 
Best regards, 
Szymon Janc
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux