From 8130ae6ad7052df458105a61d91bcaca09987d88 Mon Sep 17 00:00:00 2001 From: "hyuna0213.jo" Date: Thu, 23 Jul 2015 18:21:13 +0900 Subject: [PATCH] Fixed CA linux sample bug for bulk data we have to create text file for bulk data only. so I fixed the condition for data size check. Change-Id: I96f9441e475dbe67729391e29571cdb8ab443e21 Signed-off-by: hyuna0213.jo Reviewed-on: https://gerrit.iotivity.org/gerrit/1847 Tested-by: jenkins-iotivity Reviewed-by: Erich Keane --- resource/csdk/connectivity/samples/linux/sample_main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/resource/csdk/connectivity/samples/linux/sample_main.c b/resource/csdk/connectivity/samples/linux/sample_main.c index f37089a..a48d391 100644 --- a/resource/csdk/connectivity/samples/linux/sample_main.c +++ b/resource/csdk/connectivity/samples/linux/sample_main.c @@ -43,6 +43,8 @@ #define SYSTEM_INVOKE_ERROR 127 #define SYSTEM_ERROR -1 +#define BLOCK_SIZE(arg) (1 << ((arg) + 4)) + /** * @def RS_IDENTITY * @brief @@ -1039,7 +1041,8 @@ void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestI } // if received message is bulk data, create output file - if ((requestInfo->info.payload) && (requestInfo->info.payloadSize > CA_DEFAULT_BLOCK_SIZE)) + if ((requestInfo->info.payload) && + (requestInfo->info.payloadSize > BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE))) { create_file(requestInfo->info.payload, requestInfo->info.payloadSize); } @@ -1092,7 +1095,8 @@ void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *respon } // if received message is bulk data, create output file - if ((responseInfo->info.payload) && (responseInfo->info.payloadSize > CA_DEFAULT_BLOCK_SIZE)) + if ((responseInfo->info.payload) && + (responseInfo->info.payloadSize > BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE))) { create_file(responseInfo->info.payload, responseInfo->info.payloadSize); } @@ -1584,7 +1588,10 @@ int get_address_set(const char *pAddress, addressSet_t* outAddress) void create_file(CAPayload_t bytes, size_t length) { FILE *fp = fopen("sample_output.txt", "wb"); - fwrite(bytes, 1, length, fp); + if (!fp) + { + fwrite(bytes, 1, length, fp); + } fclose(fp); } -- 2.7.4