fixed the jira IOT-712 issue in blockwise-transfer
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Thu, 24 Sep 2015 11:20:28 +0000 (20:20 +0900)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Fri, 25 Sep 2015 16:01:25 +0000 (16:01 +0000)
if request data is bulk data with block option1 and
response data is not bulk data, response data will
be sent with only block option1. this case we have to
add the received data to receive queue.
This patch addresses the first part of IOT-712.

Change-Id: I62645ae9592f59ed16758e4ff4a2b635cb834e04
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3039
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
resource/csdk/connectivity/src/cablockwisetransfer.c

index 41efc98..54aaa57 100644 (file)
@@ -852,11 +852,23 @@ CAResult_t CASetNextBlockOption1(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
         if (0 == block.m &&
                 (CA_REQUEST_ENTITY_INCOMPLETE != code && CA_REQUEST_ENTITY_TOO_LARGE != code))
         {
-            OIC_LOG(INFO, TAG, "Data has sent");
-            // initialize block number for response message
-            data->block1.num = 0;
-            CADestroyBlockID(blockDataID);
-            return CA_STATUS_OK;
+            int isBlock2 = coap_get_block(pdu, COAP_OPTION_BLOCK2, &block);
+            if (isBlock2)
+            {
+                OIC_LOG(INFO, TAG, "received data is combining block1 and block2");
+                // initialize block number for response message
+                data->block1.num = 0;
+                CADestroyBlockID(blockDataID);
+                return CA_STATUS_OK;
+            }
+            else
+            {
+                OIC_LOG(INFO, TAG, "received data is not bulk data");
+                CAReceiveLastBlock(blockDataID, receivedData);
+                CARemoveBlockDataFromList(blockDataID);
+                CADestroyBlockID(blockDataID);
+                return CA_STATUS_OK;
+            }
         }
 
         blockWiseStatus = CA_OPTION1_ACK;
@@ -1638,6 +1650,12 @@ CAResult_t CAAddBlockOption1(coap_pdu_t **pdu, const CAInfo_t *info, size_t data
             return res;
         }
 
+        if (!coap_add_data(*pdu, dataLength, (const unsigned char *) info->payload))
+        {
+            OIC_LOG(ERROR, TAG, "failed to add payload");
+            return CA_STATUS_FAILED;
+        }
+
         // reset block-list after write block
         if (0 == block1->m)
         {