Skip to content

Commit

Permalink
Checkpoint - Client/Server ConfigSet
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfadden8 committed Nov 28, 2023
1 parent e3d4344 commit fae47b0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/axl.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ int AXL_Finalize (void)
axl_xfer_list->axl_kvtrees_count = 0;

if (axl_service_mode == AXLSVC_CLIENT) {
axlsvc_client_finalize();
axlsvc_client_AXL_Finalize();
}

}
Expand Down Expand Up @@ -497,6 +497,10 @@ static kvtree* AXL_Config_Set(const kvtree* config)
}
}

if (axl_service_mode == AXLSVC_CLIENT) {
axlsvc_client_AXL_Config_Set(config);
}

return retval;
}

Expand Down
15 changes: 12 additions & 3 deletions src/axl_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __AXLSVC_H__

#include <stddef.h>
#include "kvtree.h"

#if defined(__cplusplus)
extern "C" {
Expand All @@ -20,7 +21,7 @@ typedef enum {
extern alxsvc_RunMode axl_service_mode;

typedef enum {
AXLSVC_AXL_CONFIG = 0, /* payload is config ktree file path */
AXLSVC_AXL_CONFIG_SET = 0, /* payload is config kvtree hash buffer */
} axlsvc_request_t;

typedef struct {
Expand All @@ -38,9 +39,17 @@ typedef struct {
ssize_t payload_length; // Optional error/status string
} axlsvc_Response;


int axlsvc_client_init(char* host, unsigned short port);
void axlsvc_client_finalize();

/*
* function to perform client-side request to server for AXL_Finalize()
*/
void axlsvc_client_AXL_Finalize();

/*
* function to perform client-side request to server for AXL_Config_Set
*/
void axlsvc_client_AXL_Config_Set(const kvtree* config);

#if defined(__cplusplus)
extern "C" }
Expand Down
46 changes: 45 additions & 1 deletion src/axl_service_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "axl_internal.h"
#include "axl_service.h"
#include "kvtree.h"

/*
* Flag to state whether the AXL client/server mode of operation is enabled,
Expand Down Expand Up @@ -47,9 +48,52 @@ int axlsvc_client_init(char* host, unsigned short port)
return 1; // success
}

void axlsvc_client_finalize()
/*
* function to perform client-side request to server for AXL_Finalize()
*/
void axlsvc_client_AXL_Finalize()
{
if (axlsvc_socket >= 0)
close(axlsvc_socket);
}

/*
* function to perform client-side request to server for AXL_Config_Set
*/
void axlsvc_client_AXL_Config_Set(const kvtree* config)
{
ssize_t bytecount;
axlsvc_Request request;
axlsvc_Response response;

request.request = AXLSVC_AXL_CONFIG_SET;
request.payload_length = (ssize_t)kvtree_pack_size(config);

bytecount = axl_write_attempt("AXLSVC Client --> AXL_Config_Set_1",
axlsvc_socket, &request, sizeof(request));

if (bytecount != sizeof(request)) {
AXL_ABORT(-1, "Unexpected Write Response to server: Expected %d, Got %d",
sizeof(request), bytecount);
}

bytecount = kvtree_write_fd("AXLSVC Client --> AXL_Config_Set_2",
axlsvc_socket, config);

if (bytecount != request.payload_length) {
AXL_ABORT(-1, "Unexpected Write Response to server: Expected %d, Got %d",
request.payload_length, bytecount);
}

bytecount = axl_read("AXLSVC Client <-- Response",
axlsvc_socket, &response, sizeof(response));

if (bytecount != sizeof(response)) {
AXL_ABORT(-1, "Unexpected Write Response to server: Expected %d, Got %d",
sizeof(response), bytecount);
}

if (response.response != AXLSVC_SUCCESS) {
AXL_ABORT(-1, "Unexpected Response from server: %d", response.response);
}
}
19 changes: 16 additions & 3 deletions src/axl_service_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@

#include "axl_internal.h"
#include "axl_service.h"
#include "kvtree.h"

#define AXLSVC_MAX_CLIENTS 16
struct axl_connection_ctx {
int sd; /* Connection to our socket */
struct axl_transfer_array xfr; /* Pointer to client-specific xfer array */
} axl_connection_ctx_array[AXLSVC_MAX_CLIENTS];

static kvtree* service_request_AXL_Config_Set(int sd)
{
kvtree* config = kvtree_new();
kvtree* rval;
ssize_t bytecount;

bytecount = kvtree_read_fd("Service_AXL_Config_Set", sd, config);

return rval;
}

static ssize_t service_request_from_client(int sd)
{
ssize_t bytecount;
Expand All @@ -39,8 +51,8 @@ static ssize_t service_request_from_client(int sd)
}

switch (req.request) {
case AXLSVC_AXL_CONFIG:
AXL_DBG(1, "AXLSVC_AXL_CONFIG(kfile=%s", buffer);
case AXLSVC_AXL_CONFIG_SET:
AXL_DBG(1, "AXLSVC_AXL_CONFIG_SET(kfile=%s", buffer);
response.response = AXLSVC_SUCCESS;
response.payload_length = 0;
bytecount = axl_write_attempt("AXLSVC Response to Client", sd, &response, sizeof(response));
Expand Down Expand Up @@ -135,7 +147,8 @@ int axlsvc_server_run(int port)
AXL_DBG(2, "Closing server side socket(%d) to client", axl_connection_ctx_array[i].sd);
close(axl_connection_ctx_array[i].sd);
axl_connection_ctx_array[i].sd = 0;
/*TODO: Free up memory used for acx_kvtrees */
axl_free(&axl_xfer_list->axl_kvtrees);
axl_xfer_list->axl_kvtrees_count = 0;
}
}
}
Expand Down

0 comments on commit fae47b0

Please sign in to comment.