Skip to content

Commit

Permalink
synchronous "create" method is now asynchronous behind your back
Browse files Browse the repository at this point in the history
  • Loading branch information
lehenbauer committed Jan 13, 2017
1 parent f8daa94 commit 64da4fd
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions generic/zookeepertcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,30 @@ zootcl_sync_data_completion_callback (int rc, const char *value, int valueLen, c
zootcl_queue_null_event (zsc);
}

/*
*--------------------------------------------------------------
*
* zootcl_sync_string_completion_callback -- string completion callback function
*
*--------------------------------------------------------------
*/
void
zootcl_sync_string_completion_callback (int rc, const char *value, const void *context)
{
zootcl_syncCallbackContext *zsc = (zootcl_syncCallbackContext *)context;
zsc->rc = rc;

// if value is NULL then there is no value associated with this znode
// we set to NULL and the other end (the event handler) will discriminate
if (value == NULL) {
zsc->dataObj = NULL;
} else {
zsc->dataObj = Tcl_NewStringObj (value, -1);
}
zsc->syncDone = 1;
zootcl_queue_null_event (zsc);
}

/*
*--------------------------------------------------------------
*
Expand Down Expand Up @@ -1792,15 +1816,21 @@ zootcl_create_subcommand(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], ZO
}
}

char returnPathBuf[1024*1024];

int status;

if (callbackObj == NULL) {
status = zoo_create (zh, path, value, valueLen, &ZOO_OPEN_ACL_UNSAFE, flags, returnPathBuf, sizeof(returnPathBuf));
zootcl_syncCallbackContext *zsc = (zootcl_syncCallbackContext *)ckalloc (sizeof (zootcl_syncCallbackContext));
zsc->zo = zo;
zsc->syncDone = 0;
status = zoo_acreate (zh, path, value, valueLen, &ZOO_OPEN_ACL_UNSAFE, flags, zootcl_sync_string_completion_callback, zsc);
if (zootcl_wait (zo, zsc) == TCL_ERROR) {
ckfree (zsc);
return TCL_ERROR;
}
if (status == ZOK) {
Tcl_SetObjResult (interp, Tcl_NewStringObj (returnPathBuf, -1));
Tcl_SetObjResult (interp, zsc->dataObj);
}
ckfree (zsc);
} else {
zootcl_callbackContext *ztc = (zootcl_callbackContext *)ckalloc (sizeof (zootcl_callbackContext));
ztc->callbackObj = callbackObj;
Expand Down

0 comments on commit 64da4fd

Please sign in to comment.