Loading src/lib/kinetic_operation.c +5 −1 Original line number Diff line number Diff line Loading @@ -45,10 +45,12 @@ KineticStatus KineticOperation_SendRequest(KineticOperation* const operation) assert(operation->connection != NULL); assert(operation->request != NULL); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore * const sem = operation->connection->outstandingOperations; (void)sem; KineticCountingSemaphore_Take(sem); #endif KineticStatus status = KineticOperation_SendRequestInner(operation); if (status != KINETIC_STATUS_SUCCESS) { Loading @@ -59,7 +61,9 @@ KineticStatus KineticOperation_SendRequest(KineticOperation* const operation) request->message.message.commandBytes.data = NULL; } } #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Give(sem); #endif return status; } Loading src/lib/kinetic_session.c +4 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ KineticStatus KineticSession_Create(KineticSession * const session, KineticClien return KINETIC_STATUS_MEMORY_ERROR; } #if COUNTING_SEMAPHORE_ENABLED session->connection->outstandingOperations = KineticCountingSemaphore_Create(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION); if (session->connection->outstandingOperations == NULL) { Loading @@ -63,6 +64,7 @@ KineticStatus KineticSession_Create(KineticSession * const session, KineticClien KineticAllocator_FreeConnection(session->connection); return KINETIC_STATUS_MEMORY_ERROR; } #endif return KINETIC_STATUS_SUCCESS; } Loading @@ -75,7 +77,9 @@ KineticStatus KineticSession_Destroy(KineticSession * const session) if (session->connection == NULL) { return KINETIC_STATUS_SESSION_INVALID; } #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Destroy(session->connection->outstandingOperations); #endif KineticAllocator_FreeConnection(session->connection); session->connection = NULL; return KINETIC_STATUS_SUCCESS; Loading src/lib/kinetic_types_internal.h +3 −0 Original line number Diff line number Diff line Loading @@ -30,7 +30,10 @@ #include <time.h> #include <pthread.h> #define COUNTING_SEMAPHORE_ENABLED 0 #if COUNTING_SEMAPHORE_ENABLED #define KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION (10) #endif #define KINETIC_SOCKET_DESCRIPTOR_INVALID (-1) #define KINETIC_CONNECTION_INITIAL_STATUS_TIMEOUT_SECS (3) #define KINETIC_OPERATION_TIMEOUT_SECS (20) Loading test/unit/test_kinetic_session.c +8 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,9 @@ #include <sys/time.h> static KineticConnection Connection; #if COUNTING_SEMAPHORE_ENABLED static KineticCountingSemaphore Semaphore; #endif static KineticSession Session; static KineticPDU Request, Response; static int OperationCompleteCallbackCount; Loading @@ -61,7 +63,9 @@ void setUp(void) Client.bus = &MessageBus; KineticAllocator_NewConnection_ExpectAndReturn(&MessageBus, &Session, &Connection); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore); #endif KineticStatus status = KineticSession_Create(&Session, &Client); Loading Loading @@ -105,16 +109,19 @@ void test_KineticSession_Create_should_allocate_and_destroy_KineticConnections(v KineticConnection connection; memset(&connection, 0, sizeof(connection)); connection.pSession = &session; // session.connection = &connection; KineticAllocator_NewConnection_ExpectAndReturn(&MessageBus, &session, &connection); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore); #endif KineticStatus status = KineticSession_Create(&session, &Client); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL_PTR(&connection, session.connection); TEST_ASSERT_FALSE(session.connection->connected); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Destroy_Expect(&Semaphore); #endif KineticAllocator_FreeConnection_Expect(&connection); status = KineticSession_Destroy(&session); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); Loading Loading
src/lib/kinetic_operation.c +5 −1 Original line number Diff line number Diff line Loading @@ -45,10 +45,12 @@ KineticStatus KineticOperation_SendRequest(KineticOperation* const operation) assert(operation->connection != NULL); assert(operation->request != NULL); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore * const sem = operation->connection->outstandingOperations; (void)sem; KineticCountingSemaphore_Take(sem); #endif KineticStatus status = KineticOperation_SendRequestInner(operation); if (status != KINETIC_STATUS_SUCCESS) { Loading @@ -59,7 +61,9 @@ KineticStatus KineticOperation_SendRequest(KineticOperation* const operation) request->message.message.commandBytes.data = NULL; } } #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Give(sem); #endif return status; } Loading
src/lib/kinetic_session.c +4 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ KineticStatus KineticSession_Create(KineticSession * const session, KineticClien return KINETIC_STATUS_MEMORY_ERROR; } #if COUNTING_SEMAPHORE_ENABLED session->connection->outstandingOperations = KineticCountingSemaphore_Create(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION); if (session->connection->outstandingOperations == NULL) { Loading @@ -63,6 +64,7 @@ KineticStatus KineticSession_Create(KineticSession * const session, KineticClien KineticAllocator_FreeConnection(session->connection); return KINETIC_STATUS_MEMORY_ERROR; } #endif return KINETIC_STATUS_SUCCESS; } Loading @@ -75,7 +77,9 @@ KineticStatus KineticSession_Destroy(KineticSession * const session) if (session->connection == NULL) { return KINETIC_STATUS_SESSION_INVALID; } #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Destroy(session->connection->outstandingOperations); #endif KineticAllocator_FreeConnection(session->connection); session->connection = NULL; return KINETIC_STATUS_SUCCESS; Loading
src/lib/kinetic_types_internal.h +3 −0 Original line number Diff line number Diff line Loading @@ -30,7 +30,10 @@ #include <time.h> #include <pthread.h> #define COUNTING_SEMAPHORE_ENABLED 0 #if COUNTING_SEMAPHORE_ENABLED #define KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION (10) #endif #define KINETIC_SOCKET_DESCRIPTOR_INVALID (-1) #define KINETIC_CONNECTION_INITIAL_STATUS_TIMEOUT_SECS (3) #define KINETIC_OPERATION_TIMEOUT_SECS (20) Loading
test/unit/test_kinetic_session.c +8 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,9 @@ #include <sys/time.h> static KineticConnection Connection; #if COUNTING_SEMAPHORE_ENABLED static KineticCountingSemaphore Semaphore; #endif static KineticSession Session; static KineticPDU Request, Response; static int OperationCompleteCallbackCount; Loading @@ -61,7 +63,9 @@ void setUp(void) Client.bus = &MessageBus; KineticAllocator_NewConnection_ExpectAndReturn(&MessageBus, &Session, &Connection); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore); #endif KineticStatus status = KineticSession_Create(&Session, &Client); Loading Loading @@ -105,16 +109,19 @@ void test_KineticSession_Create_should_allocate_and_destroy_KineticConnections(v KineticConnection connection; memset(&connection, 0, sizeof(connection)); connection.pSession = &session; // session.connection = &connection; KineticAllocator_NewConnection_ExpectAndReturn(&MessageBus, &session, &connection); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore); #endif KineticStatus status = KineticSession_Create(&session, &Client); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL_PTR(&connection, session.connection); TEST_ASSERT_FALSE(session.connection->connected); #if COUNTING_SEMAPHORE_ENABLED KineticCountingSemaphore_Destroy_Expect(&Semaphore); #endif KineticAllocator_FreeConnection_Expect(&connection); status = KineticSession_Destroy(&session); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); Loading