From d63b6ee0b151a21677743a8c2bd8dd2b48898764 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 28 Feb 2014 14:51:46 -0500 Subject: [PATCH] C max_chunk_size server bits continued Signed-off-by: Bill Erickson --- src/libopensrf/osrf_application.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/libopensrf/osrf_application.c b/src/libopensrf/osrf_application.c index 2bda572..cbd9371 100644 --- a/src/libopensrf/osrf_application.c +++ b/src/libopensrf/osrf_application.c @@ -753,8 +753,10 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int ); // see how long this chunk is. If this is the last - // chunk, it will likely not be equal to chunk_size + // chunk, it will likely be less than chunk_size int partial_size = strlen(&data_str[i]); + if (partial_size > chunk_size) + partial_size = chunk_size; // substr(data_str, i, partial_size) char partial_buf[partial_size + 1]; @@ -766,10 +768,17 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int osrf_message_set_result(msg, partial_obj); jsonObjectFree(partial_obj); - // Serialize the OSRF message as JSON for delivery - char* json = jsonObjectToJSON(osrfMessageToJSON(msg)); + // package the osrf message within an array then + // serialize to json for delivery + jsonObject* arr = jsonNewObject(NULL); + + // msg json freed when arr is freed + jsonObjectPush(arr, osrfMessageToJSON(msg)); + char* json = jsonObjectToJSON(arr); + osrfSendTransportPayload(ctx->session, json); osrfMessageFree(msg); + jsonObjectFree(arr); free(json); } @@ -782,9 +791,12 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int OSRF_STATUS_NOCONTENT ); - char* json = jsonObjectToJSON(osrfMessageToJSON(msg)); + jsonObject* arr = jsonNewObject(NULL); + jsonObjectPush(arr, osrfMessageToJSON(msg)); + char* json = jsonObjectToJSON(arr); osrfSendTransportPayload(ctx->session, json); osrfMessageFree(msg); + jsonObjectFree(arr); free(json); -- 2.11.0