Skip to contentSkip to conversation

core: Fix replying with an error for connected profile

PATCH Applied Luiz Augusto von Dentz 1 participant 2 messages Nov 20, 2015 – Nov 23, 2015 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/1 core: Fix replying with an error for connected profile

From: Luiz Augusto von Dentz <[email protected]>

If the profile(s) is already connected don't reply with an error, if the profile is in fact connecting already just wait until it completes.

---
 src/device.c  | 8 ++++++--
 src/service.c | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
src/device.c +6 -2
index e76b8bb..9021914 100644
@@ -1477,7 +1477,8 @@ static int connect_next(struct btd_device *dev)
 	while (dev->pending) {
 		service = dev->pending->data;
 
-		if (btd_service_connect(service) == 0)
+		err = btd_service_connect(service);
+		if (!err)
 			return 0;
 
 		dev->pending = g_slist_delete_link(dev->pending, dev->pending);
@@ -1732,8 +1733,11 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type
 	}
 
 	err = connect_next(dev);
-	if (err < 0)
+	if (err < 0) {
+		if (err == -EALREADY)
+			return dbus_message_new_method_return(msg);
 		return btd_error_failed(msg, strerror(-err));
+	}
 
 	dev->connect = dbus_message_ref(msg);
 
src/service.c +1 -0
index 3d07744..f7912f5 100644
@@ -228,6 +228,7 @@ int btd_service_connect(struct btd_service *service)
 	case BTD_SERVICE_STATE_DISCONNECTED:
 		break;
 	case BTD_SERVICE_STATE_CONNECTING:
+		return 0;
 	case BTD_SERVICE_STATE_CONNECTED:
 		return -EALREADY;
 	case BTD_SERVICE_STATE_DISCONNECTING:
Signature · 1 line
2.4.3
author maintainer Applied
#1 lore raw

Hi,

Quoted 49 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

If the profile(s) is already connected don't reply with an error, if the profile is in fact connecting already just wait until it completes.

---
 src/device.c  | 8 ++++++--
 src/service.c | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
src/device.c +6 -2
index e76b8bb..9021914 100644
@@ -1477,7 +1477,8 @@ static int connect_next(struct btd_device *dev)
        while (dev->pending) {
                service = dev->pending->data;
 
-               if (btd_service_connect(service) == 0)
+               err = btd_service_connect(service);
+               if (!err)
                        return 0;
 
                dev->pending = g_slist_delete_link(dev->pending, dev->pending);
@@ -1732,8 +1733,11 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type
        }
 
        err = connect_next(dev);
-       if (err < 0)
+       if (err < 0) {
+               if (err == -EALREADY)
+                       return dbus_message_new_method_return(msg);
                return btd_error_failed(msg, strerror(-err));
+       }
 
        dev->connect = dbus_message_ref(msg);
 
src/service.c +1 -1
index 3d07744..f7912f5 100644
@@ -228,6 +228,7 @@ int btd_service_connect(struct btd_service *service)
        case BTD_SERVICE_STATE_DISCONNECTED:
                break;
        case BTD_SERVICE_STATE_CONNECTING:
+               return 0;
        case BTD_SERVICE_STATE_CONNECTED:
                return -EALREADY;
        case BTD_SERVICE_STATE_DISCONNECTING:
--
Quoted 1 line

2.4.3

Applied.

Signature · 1 line
Luiz Augusto von Dentz