[OTP] Fix Object Read logic 23/131523/2
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Mon, 29 May 2017 13:41:03 +0000 (19:11 +0530)
committerGowtham Anandha Babu <gowtham.ab@samsung.com>
Mon, 29 May 2017 13:55:32 +0000 (19:25 +0530)
Change-Id: Iac4e6ca7593e6127ba100fbf3ae49a80f1ac90f2
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
src/bluetooth-otp.c

index 3224664d551fac57bcd112b0231162eb460e25ba..3ed8125c5adc461b2e0ed03b4944688d9a9fe88b 100644 (file)
@@ -1298,7 +1298,7 @@ static bool __bt_otc_connection_timeout_cb(gpointer user_data)
        _bt_convert_address_to_hex(&addr_hex, address);
        bluetooth_otp_disconnect_otc(&addr_hex);
 
-       return FALSE;
+       return TRUE;
 }
 
 static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
@@ -1382,16 +1382,15 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
                oacp_read_op->fp = fp;
                oacp_read_op->size = object_info->curr_size;
                oacp_read_op->file_path = g_strdup(file_path);
-       } else {
-               oacp_read_op->offset += (oacp_read_op->length - oacp_read_op->offset);
        }
 
-       fseek(oacp_read_op->fp, oacp_read_op->offset, SEEK_SET);
-       written = fwrite(buffer, 1, len, oacp_read_op->fp);
-       oacp_read_op->length += len;
-       BT_DBG("written [%d], offset [%lu], length [%lu], size [%lu]",
-                                                       written, oacp_read_op->offset,
-                                                       oacp_read_op->length, oacp_read_op->size);
+       if (oacp_read_op->length <= oacp_read_op->size) {
+               written = fwrite(buffer, 1, len, oacp_read_op->fp);
+               oacp_read_op->length += written;
+               BT_DBG("written [%d], length_sofar [%lu], received_buff_len [%d], size [%lu]",
+                                       written, oacp_read_op->length, len, oacp_read_op->size);
+       }
+
        if (timeout_id > 0) {
                g_source_remove(timeout_id);
                timeout_id = g_timeout_add(BT_OTC_CONNECTION_MAX_TIMEOUT,