Commit e9cddf41 authored by Greg Williams's avatar Greg Williams
Browse files

Updated kinetic_socket and kinetic_pdu to return KineticStatus instead of bool...

Updated kinetic_socket and kinetic_pdu to return KineticStatus instead of bool for read and write operations, and updated usages.
Updated kinetic_socket to take a seperate length parameter for read operations so as to not override the meaning of the .bytesUsed attribute of ByteBuffer instances.
parent b61dd61e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -153,6 +153,9 @@ typedef enum {
    KINETIC_STATUS_VERSION_FAILURE,     // Basically a VERSION_MISMATCH error for a PUT
    KINETIC_STATUS_DATA_ERROR,          // Device reported data error, no space or HMAC failure
    KINETIC_STATUS_BUFFER_OVERRUN,      // One or more of byte buffers did not fit all data
    KINETIC_STATUS_MEMORY_ERROR,        // Failed allocating/deallocating memory
    KINETIC_STATUS_SOCKET_TIMEOUT,      // A timeout occurred while waiting for a socket operation
    KINETIC_STATUS_SOCKET_ERROR,        // An I/O error occurred during a socket operation
    KINETIC_STATUS_COUNT                // Number of status codes in KineticStatusDescriptor
} KineticStatus;
extern const char* KineticStatusDescriptor[];
+6 −6
Original line number Diff line number Diff line
@@ -13,8 +13,8 @@
 * `NULL`-terminated.
 */
typedef struct _ByteArray {
    size_t  len;    /**< Number of bytes in the `data` field. */
    uint8_t* data;  /**< Pointer to an allocated array of data bytes. */
    const size_t  len;    /**< Number of bytes in the `data` field. */
    uint8_t* const data;  /**< Pointer to an allocated array of data bytes. */
} ByteArray;

/** @brief Convenience macro to represent an empty array with no data */
@@ -22,8 +22,8 @@ typedef struct _ByteArray {

ByteArray ByteArray_Create(void* data, size_t len);
ByteArray ByteArray_CreateWithCString(char* str);
void ByteArray_FillWithDummyData(ByteArray array);
ByteArray ByteArray_GetSlice(ByteArray array, size_t start, size_t len);
void ByteArray_FillWithDummyData(const ByteArray array);
ByteArray ByteArray_GetSlice(const ByteArray array, size_t start, size_t len);

/**
 * @brief Structure for an embedded ByteArray as a buffer
@@ -32,7 +32,7 @@ ByteArray ByteArray_GetSlice(ByteArray array, size_t start, size_t len);
 * byte is consumed, but shall not exceed the `array` length
 */
typedef struct {
    ByteArray   array;     /**< ByteArray holding allocated array w/length = allocated size */
    const ByteArray array;     /**< ByteArray holding allocated array w/length = allocated size */
    size_t          bytesUsed; /**< Reflects the number of bytes used from the `array` */
} ByteBuffer;

+11 −36
Original line number Diff line number Diff line
@@ -58,20 +58,22 @@ static KineticStatus KineticClient_ExecuteOperation(KineticOperation* operation)
    LOGF("Executing operation: 0x%llX", operation);
    if (operation->request->entry.value.array.data != NULL
      && operation->request->entry.value.array.len > 0) {
        KineticLogger_LogByteArray("  Sending PDU w/metadata:",
        KineticLogger_LogByteArray("  Sending PDU w/value:",
            operation->request->entry.value.array);
    }
    else {
        LOG("  Sending PDU w/o metadata");
        LOG("  Sending PDU w/o value");
    }

    // Send the request
    if (KineticPDU_Send(operation->request)) {
    status = KineticPDU_Send(operation->request);
    if (status == KINETIC_STATUS_SUCCESS) {
        // Associate response with same exchange as request
        operation->response->connection = operation->request->connection;

        // Receive the response
        if (KineticPDU_Receive(operation->response)) {
        status = KineticPDU_Receive(operation->response);
        if (status == KINETIC_STATUS_SUCCESS) {
            status = KineticOperation_GetStatus(operation);
        }
    }
@@ -191,8 +193,8 @@ KineticStatus KineticClient_Put(KineticSessionHandle handle,
    if (status == KINETIC_STATUS_SUCCESS) {
        // Propagate newVersion to dbVersion in metadata, if newVersion specified
        if (entry->newVersion.array.data != NULL && entry->newVersion.array.len > 0) {
            entry->dbVersion.array = entry->newVersion.array;
            entry->newVersion.array = BYTE_ARRAY_NONE;
            entry->dbVersion = entry->newVersion;
            entry->newVersion = BYTE_BUFFER_NONE;
        }
    }

@@ -224,38 +226,11 @@ KineticStatus KineticClient_Get(KineticSessionHandle handle,
    // Update the entry upon success
    // entry->value.array.len = 0;
    if (status == KINETIC_STATUS_SUCCESS) {
        KineticProto_KeyValue* keyValue =
            KineticPDU_GetKeyValue(operation.response);
        KineticProto_KeyValue* keyValue = KineticPDU_GetKeyValue(operation.response);
        if (keyValue != NULL) {
            
            if (!Copy_KineticProto_KeyValue_to_KineticEntry(
                keyValue, entry))
            {
                return KINETIC_STATUS_BUFFER_OVERRUN;
            }

            // if (entry->key.data != NULL)
            // {
            //     memcpy(entry->key.data, keyValue->key.data, keyValue->key.len);
            //     entry->key.len = keyValue->key.len;
            // }
            // entry->key =
            //     operation.response->proto->command->body->keyValue->key;

            // if (entry->dbVersion.array.data != NULL) {
            //     Copy_ProtobufCBinaryData_to_ByteBuffer(
            //         entry->dbVersion, keyValue->dbVersion);
            // }

            // entry->tag =
            //     operation.response->proto->command->body->keyValue->tag;
            // entry->dbVersion =
            //     operation.response->proto->command->body->keyValue->dbVersion;
            // entry->newVersion =
            //     operation.response->proto->command->body->keyValue->newVersion;
            // entry->algorithm =
            //     operation.response->proto->command->body->keyValue->algorithm;

            if (!Copy_KineticProto_KeyValue_to_KineticEntry(keyValue, entry)) {
                status = KINETIC_STATUS_BUFFER_OVERRUN;
            }
        }
    }

+6 −0
Original line number Diff line number Diff line
@@ -417,3 +417,9 @@ void KineticLogger_LogByteArray(const char* title, ByteArray bytes)
        LOGF("  %s : %s", hex, ascii);
    }
}

void KineticLogger_LogByteBuffer(const char* title, ByteBuffer buffer)
{
    ByteArray array = {.data = buffer.array.data, .len = buffer.bytesUsed};
    KineticLogger_LogByteArray(title, array);
}
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ void KineticLogger_LogHeader(const KineticPDUHeader* header);
void KineticLogger_LogProtobuf(const KineticProto* proto);
void KineticLogger_LogStatus(KineticProto_Status* status);
void KineticLogger_LogByteArray(const char* title, ByteArray bytes);
void KineticLogger_LogByteBuffer(const char* title, ByteBuffer buffer);

#define LOG(message) KineticLogger_Log(message)
#define LOGF(message, ...) KineticLogger_LogPrintf(message, __VA_ARGS__)
Loading