gatt: Fix AcquireWrite and AcquireNotify server support 64/230964/1 accepted/tizen/unified/20200427.125827 submit/tizen/20200423.001024
authorSzymon Janc <szymon.janc@codecoup.pl>
Tue, 7 Apr 2020 01:29:06 +0000 (03:29 +0200)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 16 Apr 2020 08:05:29 +0000 (17:05 +0900)
Register read handler only for notify IO and handle socket
disconnection in sock_io_read.

Change-Id: I69349f7570aea4370bfb85809a3078886b7560e3
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/gatt-database.c

index ec83420..5f94576 100644 (file)
@@ -2800,7 +2800,7 @@ static bool sock_io_read(struct io *io, void *user_data)
        ssize_t bytes_read;
 
        bytes_read = read(fd, buf, sizeof(buf));
-       if (bytes_read < 0)
+       if (bytes_read <= 0)
                return false;
 
        send_notification_to_devices(chrc->service->app->database,
@@ -2821,8 +2821,6 @@ static struct io *sock_io_new(int fd, void *user_data)
 
        io_set_close_on_destroy(io, true);
 
-       io_set_read_handler(io, sock_io_read, user_data, NULL);
-
        io_set_disconnect_handler(io, sock_hup, user_data, NULL);
 
        return io;
@@ -2963,6 +2961,7 @@ static void acquire_notify_reply(DBusMessage *message, void *user_data)
        DBG("AcquireNotify success: fd %d MTU %u\n", fd, mtu);
 
        chrc->notify_io = sock_io_new(fd, chrc);
+       io_set_read_handler(chrc->notify_io, sock_io_read, chrc, NULL);
 
        __sync_fetch_and_add(&chrc->ntfy_cnt, 1);