2 #include <DefaultComm.h> 3 #include <comm_header.h> 6 #ifndef CISSERVERCOMM_H_ 7 #define CISSERVERCOMM_H_ 18 int new_server_address(
comm_t *comm) {
19 comm->
type = _default_comm;
20 return new_default_address(comm);
29 int init_server_comm(
comm_t *comm) {
32 if ((strlen(comm->
name) == 0) && (strlen(comm->
address) > 0)) {
33 comm->
type = _default_comm;
34 return init_default_comm(comm);
37 char *seri_in = (
char*)malloc(strlen(comm->
direction) + 1);
38 if (seri_in == NULL) {
39 cislog_error(
"init_server_comm: Failed to malloc seri_in.");
45 if (strlen(comm->
name) == 0) {
46 handle = new_comm_base(comm->
address,
"recv", _default_comm, (
void*)seri_in);
47 sprintf(handle->
name,
"server_request.%s", comm->
address);
49 handle = init_comm_base(comm->
name,
"recv", _default_comm, (
void*)seri_in);
51 ret = init_default_comm(handle);
56 comm->
handle = (
void*)handle;
60 cislog_error(
"init_server_comm: Failed to malloc info.");
64 comm->
info = (
void*)info;
74 int free_server_comm(
comm_t *x) {
77 free_default_comm(handle);
78 free_comm_base(handle);
82 if (x->
info != NULL) {
85 free_default_comm(*info);
86 free_comm_base(*info);
101 int server_comm_nmsg(
const comm_t x) {
103 int ret = default_comm_nmsg(*handle);
115 int server_comm_send(
const comm_t x,
const char *data,
const size_t len) {
116 cislog_debug(
"server_comm_send(%s): %d bytes", x.
name, len);
117 if (x.
info == NULL) {
118 cislog_error(
"server_comm_send(%s): no response comm registered", x.
name);
122 if (res_comm[0] == NULL) {
123 cislog_error(
"server_comm_send(%s): no response comm registered", x.
name);
126 int ret = default_comm_send((*res_comm)[0], data, len);
128 free_default_comm(res_comm[0]);
129 free_comm_base(res_comm[0]);
147 int server_comm_recv(
comm_t x,
char **data,
const size_t len,
const int allow_realloc) {
148 cislog_debug(
"server_comm_recv(%s)", x.
name);
150 cislog_error(
"server_comm_recv(%s): no request comm registered", x.
name);
154 int ret = default_comm_recv(*req_comm, data, len, allow_realloc);
166 cislog_error(
"server_comm_recv(%s): Error parsing header.", x.
name);
171 cislog_error(
"server_comm_recv(%s): No response address in message.", x.
name);
175 char *seri_copy = (
char*)malloc(strlen((
char*)(x.
serializer->
info)) + 1);
176 if (seri_copy == NULL) {
177 cislog_error(
"server_comm_recv(%s): Failed to malloc seri_copy.");
186 newret = init_default_comm(res_comm[0]);
188 cislog_error(
"server_comm_recv(%s): Could not initialize response comm.", x.
name);
void * handle
Pointer to handle for comm.
Definition: CommBase.h:25
char response_address[COMMBUFFSIZ]
Response address.
Definition: comm_header.h:23
void * info
Pointer to any extra info comm requires.
Definition: CommBase.h:26
Communication structure.
Definition: CommBase.h:19
char address[COMM_ADDRESS_SIZE]
Comm address.
Definition: CommBase.h:22
void * info
Pointer to any extra info serializer requires.
Definition: SerializeBase.h:17
comm_type type
Comm type.
Definition: CommBase.h:20
int valid
1 if the header is valid, 0 otherwise.
Definition: comm_header.h:21
int always_send_header
1 if comm should always send a header.
Definition: CommBase.h:29
seri_t * serializer
Serializer for comm messages.
Definition: CommBase.h:27
char direction[COMM_DIR_SIZE]
send or recv for direction messages will go.
Definition: CommBase.h:23
char name[COMM_NAME_SIZE]
Comm name.
Definition: CommBase.h:21
int * sent_eof
Flag specifying if EOF has been sent.
Definition: CommBase.h:32
int * recv_eof
Flag specifying if EOF has been received.
Definition: CommBase.h:33
char id[COMMBUFFSIZ]
Unique ID associated with this message.
Definition: comm_header.h:22
Header information passed by comms for multipart messages.
Definition: comm_header.h:15