KineticStatus KineticClient_DestroySession(KineticSession* const session) { if (session == NULL) { LOG0("KineticSession is NULL!"); return KINETIC_STATUS_SESSION_INVALID; } KineticStatus status = KineticSession_Disconnect(session); if (status != KINETIC_STATUS_SUCCESS) {LOG0("Disconnection failed!");} KineticSession_Destroy(session); return status; }
KineticStatus KineticController_ExecuteOperation(KineticOperation* operation, KineticCompletionClosure* const closure) { KINETIC_ASSERT(operation != NULL); KINETIC_ASSERT(operation->session != NULL); KineticStatus status = KINETIC_STATUS_INVALID; KineticSession *session = operation->session; if (KineticSession_GetTerminationStatus(operation->session) != KINETIC_STATUS_SUCCESS) { return KINETIC_STATUS_SESSION_TERMINATED; } if (closure != NULL) { operation->closure = *closure; return KineticOperation_SendRequest(operation); } else { DefaultCallbackData data; pthread_mutex_init(&data.receiveCompleteMutex, NULL); pthread_cond_init(&data.receiveComplete, NULL); data.status = KINETIC_STATUS_INVALID; data.completed = false; operation->closure = DefaultClosure(&data); // Send the request status = KineticOperation_SendRequest(operation); if (status == KINETIC_STATUS_SUCCESS) { pthread_mutex_lock(&data.receiveCompleteMutex); while(data.completed == false) { pthread_cond_wait(&data.receiveComplete, &data.receiveCompleteMutex); } status = data.status; pthread_mutex_unlock(&data.receiveCompleteMutex); } pthread_cond_destroy(&data.receiveComplete); pthread_mutex_destroy(&data.receiveCompleteMutex); if (status != KINETIC_STATUS_SUCCESS) { if (KineticSession_GetTerminationStatus(session) != KINETIC_STATUS_SUCCESS) { (void)KineticSession_Disconnect(session); if (status == KINETIC_STATUS_SOCKET_ERROR) { status = KINETIC_STATUS_SESSION_TERMINATED; } } } return status; } }