* [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup
@ 2012-07-23 14:36 Claudio Takahasi
2012-07-23 14:36 ` [PATCH BlueZ] btio: Rescue lost errorneous numbers Claudio Takahasi
2012-07-24 9:49 ` [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup Johan Hedberg
0 siblings, 2 replies; 7+ messages in thread
From: Claudio Takahasi @ 2012-07-23 14:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
Cosmetic change renaming attio cleanup function. attio prefix is more
suitable since attio implements GIOChannel abstraction in the top of
the GAttrib.
---
src/device.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/device.c b/src/device.c
index a937fcc..cd571f7 100644
--- a/src/device.c
+++ b/src/device.c
@@ -201,7 +201,7 @@ static void browse_request_free(struct browse_req *req)
g_free(req);
}
-static void att_cleanup(struct btd_device *device)
+static void attio_cleanup(struct btd_device *device)
{
if (device->attachid) {
attrib_channel_detach(device->attrib, device->attachid);
@@ -238,7 +238,7 @@ static void browse_request_cancel(struct browse_req *req)
bt_cancel_discovery(&src, &device->bdaddr);
- att_cleanup(device);
+ attio_cleanup(device);
device->browse = NULL;
browse_request_free(req);
@@ -263,7 +263,7 @@ static void device_free(gpointer user_data)
g_slist_free_full(device->attios, g_free);
g_slist_free_full(device->attios_offline, g_free);
- att_cleanup(device);
+ attio_cleanup(device);
if (device->tmp_records)
sdp_list_free(device->tmp_records,
@@ -1825,7 +1825,7 @@ static gboolean attrib_disconnected_cb(GIOChannel *io, GIOCondition cond,
att_connect_dispatched);
done:
- att_cleanup(device);
+ attio_cleanup(device);
return FALSE;
}
@@ -1867,7 +1867,7 @@ static void appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
done:
att_data_list_free(list);
if (device->attios == NULL && device->attios_offline == NULL)
- att_cleanup(device);
+ attio_cleanup(device);
}
static void primary_cb(GSList *services, guint8 status, gpointer user_data)
@@ -1910,7 +1910,7 @@ static void primary_cb(GSList *services, guint8 status, gpointer user_data)
gatt_read_char_by_uuid(device->attrib, gap_prim->range.start,
gap_prim->range.end, &uuid, appearance_cb, device);
} else if (device->attios == NULL && device->attios_offline == NULL)
- att_cleanup(device);
+ attio_cleanup(device);
g_slist_free(uuids);
@@ -3127,7 +3127,7 @@ gboolean btd_device_remove_attio_callback(struct btd_device *device, guint id)
device->auto_id = 0;
}
- att_cleanup(device);
+ attio_cleanup(device);
return TRUE;
}
--
1.7.8.6
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH BlueZ] btio: Rescue lost errorneous numbers
2012-07-23 14:36 [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup Claudio Takahasi
@ 2012-07-23 14:36 ` Claudio Takahasi
2012-07-23 16:16 ` Anderson Lizardo
2012-07-24 9:49 ` Johan Hedberg
2012-07-24 9:49 ` [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup Johan Hedberg
1 sibling, 2 replies; 7+ messages in thread
From: Claudio Takahasi @ 2012-07-23 14:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Paulo Alcantara
From: Paulo Alcantara <paulo.alcantara@openbossa.org>
The BT_IO_ERROR_* flags are not used for anything else and we just
loosing errorneous numbers set in the sockets that might be more
useful for handling specific errors.
A use case would be disconnect errors that should not allow BlueZ to
enable auto connections since the connection would never be possible in
some cases.
This patch removes BT_IO_ERROR_* flags and use the errors set in the
sockets instead. Now, the errors passed in connect/disconnect callbacks
should contain proper error numbers passed to them.
---
btio/btio.c | 78 ++++++++++++++++++++++++++++++++++++----------------------
btio/btio.h | 7 -----
2 files changed, 48 insertions(+), 37 deletions(-)
diff --git a/btio/btio.c b/btio/btio.c
index e81fb75..f2a9d4b 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -43,7 +43,7 @@
#endif
#define ERROR_FAILED(gerr, str, err) \
- g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_FAILED, \
+ g_set_error(gerr, BT_IO_ERROR, err, \
str ": %s (%d)", strerror(err), err)
#define DEFAULT_DEFER_TIMEOUT 30
@@ -124,19 +124,29 @@ static gboolean accept_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
struct accept *accept = user_data;
- GError *err = NULL;
+ GError *gerr = NULL;
/* If the user aborted this accept attempt */
if ((cond & G_IO_NVAL) || check_nval(io))
return FALSE;
- if (cond & (G_IO_HUP | G_IO_ERR))
- g_set_error(&err, BT_IO_ERROR, BT_IO_ERROR_DISCONNECTED,
- "HUP or ERR on socket");
+ if (cond & (G_IO_HUP | G_IO_ERR)) {
+ int err, sk_err, sock = g_io_channel_unix_get_fd(io);
+ socklen_t len = sizeof(sk_err);
+
+ if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0)
+ err = -errno;
+ else
+ err = -sk_err;
+
+ if (err < 0)
+ g_set_error(&gerr, BT_IO_ERROR, -err,
+ "HUP or ERR on socket");
+ }
- accept->connect(io, err, accept->user_data);
+ accept->connect(io, gerr, accept->user_data);
- g_clear_error(&err);
+ g_clear_error(&gerr);
return FALSE;
}
@@ -146,14 +156,15 @@ static gboolean connect_cb(GIOChannel *io, GIOCondition cond,
{
struct connect *conn = user_data;
GError *gerr = NULL;
+ int err, sk_err, sock;
+ socklen_t len = sizeof(sk_err);
/* If the user aborted this connect attempt */
if ((cond & G_IO_NVAL) || check_nval(io))
return FALSE;
if (cond & G_IO_OUT) {
- int err, sk_err = 0, sock = g_io_channel_unix_get_fd(io);
- socklen_t len = sizeof(sk_err);
+ sock = g_io_channel_unix_get_fd(io);
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0)
err = -errno;
@@ -161,17 +172,24 @@ static gboolean connect_cb(GIOChannel *io, GIOCondition cond,
err = -sk_err;
if (err < 0)
- g_set_error(&gerr, BT_IO_ERROR,
- BT_IO_ERROR_CONNECT_FAILED, "%s (%d)",
- strerror(-err), -err);
- } else if (cond & (G_IO_HUP | G_IO_ERR))
- g_set_error(&gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
- "HUP or ERR on socket");
+ g_set_error(&gerr, BT_IO_ERROR, -err, "%s (%d)",
+ strerror(-err), -err);
+ } else if (cond & (G_IO_HUP | G_IO_ERR)) {
+ sock = g_io_channel_unix_get_fd(io);
+
+ if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0)
+ err = -errno;
+ else
+ err = -sk_err;
+
+ if (err < 0)
+ g_set_error(&gerr, BT_IO_ERROR, -err,
+ "HUP or ERR on socket");
+ }
conn->connect(io, gerr, conn->user_data);
- if (gerr)
- g_error_free(gerr);
+ g_clear_error(&gerr);
return FALSE;
}
@@ -390,7 +408,7 @@ static gboolean set_sec_level(int sock, BtIOType type, int level, GError **err)
int ret;
if (level < BT_SECURITY_LOW || level > BT_SECURITY_HIGH) {
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Valid security level range is %d-%d",
BT_SECURITY_LOW, BT_SECURITY_HIGH);
return FALSE;
@@ -764,7 +782,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
opts->priority = va_arg(args, int);
break;
default:
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Unknown option %d", opt);
return FALSE;
}
@@ -883,7 +901,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
bacpy(va_arg(args, bdaddr_t *), &dst.l2_bdaddr);
break;
case BT_IO_OPT_DEST_TYPE:
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Not implemented");
return FALSE;
case BT_IO_OPT_DEFER_TIMEOUT:
@@ -961,7 +979,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
*(va_arg(args, uint32_t *)) = priority;
break;
default:
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Unknown option %d", opt);
return FALSE;
}
@@ -1068,7 +1086,7 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1,
memcpy(va_arg(args, uint8_t *), dev_class, 3);
break;
default:
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Unknown option %d", opt);
return FALSE;
}
@@ -1151,7 +1169,7 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args)
memcpy(va_arg(args, uint8_t *), dev_class, 3);
break;
default:
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Unknown option %d", opt);
return FALSE;
}
@@ -1180,7 +1198,7 @@ static gboolean get_valist(GIOChannel *io, BtIOType type, GError **err,
return sco_get(sock, err, opt1, args);
}
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Unknown BtIO type %d", type);
return FALSE;
}
@@ -1245,7 +1263,7 @@ gboolean bt_io_set(GIOChannel *io, BtIOType type, GError **err,
return sco_set(sock, opts.mtu, err);
}
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Unknown BtIO type %d", type);
return FALSE;
}
@@ -1334,7 +1352,7 @@ static GIOChannel *create_io(BtIOType type, gboolean server,
goto failed;
break;
default:
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Unknown BtIO type %d", type);
return NULL;
}
@@ -1392,14 +1410,14 @@ GIOChannel *bt_io_connect(BtIOType type, BtIOConnect connect,
err = sco_connect(sock, &opts.dst);
break;
default:
- g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(gerr, BT_IO_ERROR, EINVAL,
"Unknown BtIO type %d", type);
return NULL;
}
if (err < 0) {
- g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
- "connect: %s (%d)", strerror(-err), -err);
+ g_set_error(gerr, BT_IO_ERROR, -err, "connect: %s (%d)",
+ strerror(-err), -err);
g_io_channel_unref(io);
return NULL;
}
@@ -1421,7 +1439,7 @@ GIOChannel *bt_io_listen(BtIOType type, BtIOConnect connect,
gboolean ret;
if (type == BT_IO_L2RAW) {
- g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
+ g_set_error(err, BT_IO_ERROR, EINVAL,
"Server L2CAP RAW sockets not supported");
return NULL;
}
diff --git a/btio/btio.h b/btio/btio.h
index cf0e070..70b32d6 100644
--- a/btio/btio.h
+++ b/btio/btio.h
@@ -26,13 +26,6 @@
#include <glib.h>
-typedef enum {
- BT_IO_ERROR_DISCONNECTED,
- BT_IO_ERROR_CONNECT_FAILED,
- BT_IO_ERROR_FAILED,
- BT_IO_ERROR_INVALID_ARGS,
-} BtIOError;
-
#define BT_IO_ERROR bt_io_error_quark()
GQuark bt_io_error_quark(void);
--
1.7.8.6
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH BlueZ] btio: Rescue lost errorneous numbers
2012-07-23 14:36 ` [PATCH BlueZ] btio: Rescue lost errorneous numbers Claudio Takahasi
@ 2012-07-23 16:16 ` Anderson Lizardo
2012-07-24 9:54 ` Johan Hedberg
2012-07-24 9:49 ` Johan Hedberg
1 sibling, 1 reply; 7+ messages in thread
From: Anderson Lizardo @ 2012-07-23 16:16 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth, Paulo Alcantara
Hi Claudio,
On Mon, Jul 23, 2012 at 10:36 AM, Claudio Takahasi
<claudio.takahasi@openbossa.org> wrote:
> #define ERROR_FAILED(gerr, str, err) \
> - g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_FAILED, \
> + g_set_error(gerr, BT_IO_ERROR, err, \
> str ": %s (%d)", strerror(err), err)
> [...]
> if (err < 0)
> - g_set_error(&gerr, BT_IO_ERROR,
> - BT_IO_ERROR_CONNECT_FAILED, "%s (%d)",
> - strerror(-err), -err);
> - } else if (cond & (G_IO_HUP | G_IO_ERR))
> - g_set_error(&gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
> - "HUP or ERR on socket");
> + g_set_error(&gerr, BT_IO_ERROR, -err, "%s (%d)",
> + strerror(-err), -err);
why not use the ERROR_FAILED() macro here?
> if (err < 0) {
> - g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
> - "connect: %s (%d)", strerror(-err), -err);
> + g_set_error(gerr, BT_IO_ERROR, -err, "connect: %s (%d)",
> + strerror(-err), -err);
and here?
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup
2012-07-23 14:36 [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup Claudio Takahasi
2012-07-23 14:36 ` [PATCH BlueZ] btio: Rescue lost errorneous numbers Claudio Takahasi
@ 2012-07-24 9:49 ` Johan Hedberg
1 sibling, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2012-07-24 9:49 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth
Hi Claudio,
On Mon, Jul 23, 2012, Claudio Takahasi wrote:
> Cosmetic change renaming attio cleanup function. attio prefix is more
> suitable since attio implements GIOChannel abstraction in the top of
> the GAttrib.
> ---
> src/device.c | 14 +++++++-------
> 1 files changed, 7 insertions(+), 7 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH BlueZ] btio: Rescue lost errorneous numbers
2012-07-23 14:36 ` [PATCH BlueZ] btio: Rescue lost errorneous numbers Claudio Takahasi
2012-07-23 16:16 ` Anderson Lizardo
@ 2012-07-24 9:49 ` Johan Hedberg
1 sibling, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2012-07-24 9:49 UTC (permalink / raw)
To: Claudio Takahasi; +Cc: linux-bluetooth, Paulo Alcantara
Hi Claudio,
On Mon, Jul 23, 2012, Claudio Takahasi wrote:
> From: Paulo Alcantara <paulo.alcantara@openbossa.org>
>
> The BT_IO_ERROR_* flags are not used for anything else and we just
> loosing errorneous numbers set in the sockets that might be more
> useful for handling specific errors.
>
> A use case would be disconnect errors that should not allow BlueZ to
> enable auto connections since the connection would never be possible in
> some cases.
>
> This patch removes BT_IO_ERROR_* flags and use the errors set in the
> sockets instead. Now, the errors passed in connect/disconnect callbacks
> should contain proper error numbers passed to them.
> ---
> btio/btio.c | 78 ++++++++++++++++++++++++++++++++++++----------------------
> btio/btio.h | 7 -----
> 2 files changed, 48 insertions(+), 37 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH BlueZ] btio: Rescue lost errorneous numbers
2012-07-23 16:16 ` Anderson Lizardo
@ 2012-07-24 9:54 ` Johan Hedberg
2012-07-24 13:39 ` Claudio Takahasi
0 siblings, 1 reply; 7+ messages in thread
From: Johan Hedberg @ 2012-07-24 9:54 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: Claudio Takahasi, linux-bluetooth, Paulo Alcantara
Hi Lizardo,
On Mon, Jul 23, 2012, Anderson Lizardo wrote:
> On Mon, Jul 23, 2012 at 10:36 AM, Claudio Takahasi
> <claudio.takahasi@openbossa.org> wrote:
> > #define ERROR_FAILED(gerr, str, err) \
> > - g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_FAILED, \
> > + g_set_error(gerr, BT_IO_ERROR, err, \
> > str ": %s (%d)", strerror(err), err)
> > [...]
> > if (err < 0)
> > - g_set_error(&gerr, BT_IO_ERROR,
> > - BT_IO_ERROR_CONNECT_FAILED, "%s (%d)",
> > - strerror(-err), -err);
> > - } else if (cond & (G_IO_HUP | G_IO_ERR))
> > - g_set_error(&gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
> > - "HUP or ERR on socket");
> > + g_set_error(&gerr, BT_IO_ERROR, -err, "%s (%d)",
> > + strerror(-err), -err);
>
> why not use the ERROR_FAILED() macro here?
>
> > if (err < 0) {
> > - g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
> > - "connect: %s (%d)", strerror(-err), -err);
> > + g_set_error(gerr, BT_IO_ERROR, -err, "connect: %s (%d)",
> > + strerror(-err), -err);
>
> and here?
Good point. Unfortunately I didn't notice this before applying so please
(Claudio) send a fix on top of your patch.
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH BlueZ] btio: Rescue lost errorneous numbers
2012-07-24 9:54 ` Johan Hedberg
@ 2012-07-24 13:39 ` Claudio Takahasi
0 siblings, 0 replies; 7+ messages in thread
From: Claudio Takahasi @ 2012-07-24 13:39 UTC (permalink / raw)
To: Anderson Lizardo, Claudio Takahasi, linux-bluetooth, Paulo Alcantara
Hi Johan/Lizardo:
On Tue, Jul 24, 2012 at 6:54 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Lizardo,
>
> On Mon, Jul 23, 2012, Anderson Lizardo wrote:
>> On Mon, Jul 23, 2012 at 10:36 AM, Claudio Takahasi
>> <claudio.takahasi@openbossa.org> wrote:
>> > #define ERROR_FAILED(gerr, str, err) \
>> > - g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_FAILED, \
>> > + g_set_error(gerr, BT_IO_ERROR, err, \
>> > str ": %s (%d)", strerror(err), err)
>> > [...]
>> > if (err < 0)
>> > - g_set_error(&gerr, BT_IO_ERROR,
>> > - BT_IO_ERROR_CONNECT_FAILED, "%s (%d)",
>> > - strerror(-err), -err);
>> > - } else if (cond & (G_IO_HUP | G_IO_ERR))
>> > - g_set_error(&gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
>> > - "HUP or ERR on socket");
>> > + g_set_error(&gerr, BT_IO_ERROR, -err, "%s (%d)",
>> > + strerror(-err), -err);
>>
>> why not use the ERROR_FAILED() macro here?
>>
>> > if (err < 0) {
>> > - g_set_error(gerr, BT_IO_ERROR, BT_IO_ERROR_CONNECT_FAILED,
>> > - "connect: %s (%d)", strerror(-err), -err);
>> > + g_set_error(gerr, BT_IO_ERROR, -err, "connect: %s (%d)",
>> > + strerror(-err), -err);
>>
>> and here?
>
> Good point. Unfortunately I didn't notice this before applying so please
> (Claudio) send a fix on top of your patch.
>
> Johan
ok. I will send a patch to fix it.
BR,
Claudio
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-07-24 13:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-23 14:36 [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup Claudio Takahasi
2012-07-23 14:36 ` [PATCH BlueZ] btio: Rescue lost errorneous numbers Claudio Takahasi
2012-07-23 16:16 ` Anderson Lizardo
2012-07-24 9:54 ` Johan Hedberg
2012-07-24 13:39 ` Claudio Takahasi
2012-07-24 9:49 ` Johan Hedberg
2012-07-24 9:49 ` [PATCH BlueZ] attio: Rename att_cleanup to attio_cleanup Johan Hedberg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.