in zookeeper-client/zookeeper-client-c/src/zookeeper.c [5177:5293]
static void process_sync_completion(zhandle_t *zh,
completion_list_t *cptr,
struct sync_completion *sc,
struct iarchive *ia)
{
LOG_DEBUG(LOGCALLBACK(zh), "Processing sync_completion with type=%d xid=%#x rc=%d",
cptr->c.type, cptr->xid, sc->rc);
switch(cptr->c.type) {
case COMPLETION_DATA:
if (sc->rc==0) {
struct GetDataResponse res;
int len;
deserialize_GetDataResponse(ia, "reply", &res);
if (res.data.len <= sc->u.data.buff_len) {
len = res.data.len;
} else {
len = sc->u.data.buff_len;
}
sc->u.data.buff_len = len;
// check if len is negative
// just of NULL which is -1 int
if (len == -1) {
sc->u.data.buffer = NULL;
} else {
memcpy(sc->u.data.buffer, res.data.buff, len);
}
sc->u.data.stat = res.stat;
deallocate_GetDataResponse(&res);
}
break;
case COMPLETION_STAT:
if (sc->rc==0) {
struct SetDataResponse res;
deserialize_SetDataResponse(ia, "reply", &res);
sc->u.stat = res.stat;
deallocate_SetDataResponse(&res);
}
break;
case COMPLETION_STRINGLIST:
if (sc->rc==0) {
struct GetChildrenResponse res;
deserialize_GetChildrenResponse(ia, "reply", &res);
sc->u.strs2 = res.children;
/* We don't deallocate since we are passing it back */
// deallocate_GetChildrenResponse(&res);
}
break;
case COMPLETION_STRINGLIST_STAT:
if (sc->rc==0) {
struct GetChildren2Response res;
deserialize_GetChildren2Response(ia, "reply", &res);
sc->u.strs_stat.strs2 = res.children;
sc->u.strs_stat.stat2 = res.stat;
/* We don't deallocate since we are passing it back */
// deallocate_GetChildren2Response(&res);
}
break;
case COMPLETION_STRING:
if (sc->rc==0) {
struct CreateResponse res;
int len;
const char * client_path;
deserialize_CreateResponse(ia, "reply", &res);
//ZOOKEEPER-1027
client_path = sub_string(zh, res.path);
len = strlen(client_path) + 1;if (len > sc->u.str.str_len) {
len = sc->u.str.str_len;
}
if (len > 0) {
memcpy(sc->u.str.str, client_path, len - 1);
sc->u.str.str[len - 1] = '\0';
}
free_duplicate_path(client_path, res.path);
deallocate_CreateResponse(&res);
}
break;
case COMPLETION_STRING_STAT:
if (sc->rc==0) {
struct Create2Response res;
int len;
const char * client_path;
deserialize_Create2Response(ia, "reply", &res);
client_path = sub_string(zh, res.path);
len = strlen(client_path) + 1;
if (len > sc->u.str.str_len) {
len = sc->u.str.str_len;
}
if (len > 0) {
memcpy(sc->u.str.str, client_path, len - 1);
sc->u.str.str[len - 1] = '\0';
}
free_duplicate_path(client_path, res.path);
sc->u.stat = res.stat;
deallocate_Create2Response(&res);
}
break;
case COMPLETION_ACLLIST:
if (sc->rc==0) {
struct GetACLResponse res;
deserialize_GetACLResponse(ia, "reply", &res);
sc->u.acl.acl = res.acl;
sc->u.acl.stat = res.stat;
/* We don't deallocate since we are passing it back */
//deallocate_GetACLResponse(&res);
}
break;
case COMPLETION_VOID:
break;
case COMPLETION_MULTI:
sc->rc = deserialize_multi(zh, cptr->xid, cptr, ia);
break;
default:
LOG_DEBUG(LOGCALLBACK(zh), "Unsupported completion type=%d", cptr->c.type);
break;
}
}