Skip to content

Commit fae47b0

Browse files
committed
Checkpoint - Client/Server ConfigSet
1 parent e3d4344 commit fae47b0

File tree

4 files changed

+78
-8
lines changed

4 files changed

+78
-8
lines changed

src/axl.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ int AXL_Finalize (void)
331331
axl_xfer_list->axl_kvtrees_count = 0;
332332

333333
if (axl_service_mode == AXLSVC_CLIENT) {
334-
axlsvc_client_finalize();
334+
axlsvc_client_AXL_Finalize();
335335
}
336336

337337
}
@@ -497,6 +497,10 @@ static kvtree* AXL_Config_Set(const kvtree* config)
497497
}
498498
}
499499

500+
if (axl_service_mode == AXLSVC_CLIENT) {
501+
axlsvc_client_AXL_Config_Set(config);
502+
}
503+
500504
return retval;
501505
}
502506

src/axl_service.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __AXLSVC_H__
33

44
#include <stddef.h>
5+
#include "kvtree.h"
56

67
#if defined(__cplusplus)
78
extern "C" {
@@ -20,7 +21,7 @@ typedef enum {
2021
extern alxsvc_RunMode axl_service_mode;
2122

2223
typedef enum {
23-
AXLSVC_AXL_CONFIG = 0, /* payload is config ktree file path */
24+
AXLSVC_AXL_CONFIG_SET = 0, /* payload is config kvtree hash buffer */
2425
} axlsvc_request_t;
2526

2627
typedef struct {
@@ -38,9 +39,17 @@ typedef struct {
3839
ssize_t payload_length; // Optional error/status string
3940
} axlsvc_Response;
4041

41-
4242
int axlsvc_client_init(char* host, unsigned short port);
43-
void axlsvc_client_finalize();
43+
44+
/*
45+
* function to perform client-side request to server for AXL_Finalize()
46+
*/
47+
void axlsvc_client_AXL_Finalize();
48+
49+
/*
50+
* function to perform client-side request to server for AXL_Config_Set
51+
*/
52+
void axlsvc_client_AXL_Config_Set(const kvtree* config);
4453

4554
#if defined(__cplusplus)
4655
extern "C" }

src/axl_service_client.c

+45-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "axl_internal.h"
1111
#include "axl_service.h"
12+
#include "kvtree.h"
1213

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

50-
void axlsvc_client_finalize()
51+
/*
52+
* function to perform client-side request to server for AXL_Finalize()
53+
*/
54+
void axlsvc_client_AXL_Finalize()
5155
{
5256
if (axlsvc_socket >= 0)
5357
close(axlsvc_socket);
5458
}
5559

60+
/*
61+
* function to perform client-side request to server for AXL_Config_Set
62+
*/
63+
void axlsvc_client_AXL_Config_Set(const kvtree* config)
64+
{
65+
ssize_t bytecount;
66+
axlsvc_Request request;
67+
axlsvc_Response response;
68+
69+
request.request = AXLSVC_AXL_CONFIG_SET;
70+
request.payload_length = (ssize_t)kvtree_pack_size(config);
71+
72+
bytecount = axl_write_attempt("AXLSVC Client --> AXL_Config_Set_1",
73+
axlsvc_socket, &request, sizeof(request));
74+
75+
if (bytecount != sizeof(request)) {
76+
AXL_ABORT(-1, "Unexpected Write Response to server: Expected %d, Got %d",
77+
sizeof(request), bytecount);
78+
}
79+
80+
bytecount = kvtree_write_fd("AXLSVC Client --> AXL_Config_Set_2",
81+
axlsvc_socket, config);
82+
83+
if (bytecount != request.payload_length) {
84+
AXL_ABORT(-1, "Unexpected Write Response to server: Expected %d, Got %d",
85+
request.payload_length, bytecount);
86+
}
87+
88+
bytecount = axl_read("AXLSVC Client <-- Response",
89+
axlsvc_socket, &response, sizeof(response));
90+
91+
if (bytecount != sizeof(response)) {
92+
AXL_ABORT(-1, "Unexpected Write Response to server: Expected %d, Got %d",
93+
sizeof(response), bytecount);
94+
}
95+
96+
if (response.response != AXLSVC_SUCCESS) {
97+
AXL_ABORT(-1, "Unexpected Response from server: %d", response.response);
98+
}
99+
}

src/axl_service_server.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@
99

1010
#include "axl_internal.h"
1111
#include "axl_service.h"
12+
#include "kvtree.h"
1213

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

20+
static kvtree* service_request_AXL_Config_Set(int sd)
21+
{
22+
kvtree* config = kvtree_new();
23+
kvtree* rval;
24+
ssize_t bytecount;
25+
26+
bytecount = kvtree_read_fd("Service_AXL_Config_Set", sd, config);
27+
28+
return rval;
29+
}
30+
1931
static ssize_t service_request_from_client(int sd)
2032
{
2133
ssize_t bytecount;
@@ -39,8 +51,8 @@ static ssize_t service_request_from_client(int sd)
3951
}
4052

4153
switch (req.request) {
42-
case AXLSVC_AXL_CONFIG:
43-
AXL_DBG(1, "AXLSVC_AXL_CONFIG(kfile=%s", buffer);
54+
case AXLSVC_AXL_CONFIG_SET:
55+
AXL_DBG(1, "AXLSVC_AXL_CONFIG_SET(kfile=%s", buffer);
4456
response.response = AXLSVC_SUCCESS;
4557
response.payload_length = 0;
4658
bytecount = axl_write_attempt("AXLSVC Response to Client", sd, &response, sizeof(response));
@@ -135,7 +147,8 @@ int axlsvc_server_run(int port)
135147
AXL_DBG(2, "Closing server side socket(%d) to client", axl_connection_ctx_array[i].sd);
136148
close(axl_connection_ctx_array[i].sd);
137149
axl_connection_ctx_array[i].sd = 0;
138-
/*TODO: Free up memory used for acx_kvtrees */
150+
axl_free(&axl_xfer_list->axl_kvtrees);
151+
axl_xfer_list->axl_kvtrees_count = 0;
139152
}
140153
}
141154
}

0 commit comments

Comments
 (0)