2 #ifndef CISSERVERCOMM_H_ 3 #define CISSERVERCOMM_H_ 6 #include <DefaultComm.h> 7 #include <comm_header.h> 22 int new_server_address(
comm_t *comm) {
23 comm->
type = _default_comm;
24 return new_default_address(comm);
33 int init_server_comm(
comm_t *comm) {
36 if ((strlen(comm->
name) == 0) && (strlen(comm->
address) > 0)) {
37 comm->
type = _default_comm;
38 return init_default_comm(comm);
41 char *seri_in = (
char*)malloc(strlen(comm->
direction) + 1);
42 if (seri_in == NULL) {
43 cislog_error(
"init_server_comm: Failed to malloc seri_in.");
49 if (strlen(comm->
name) == 0) {
50 handle = new_comm_base(comm->
address,
"recv", _default_comm, (
void*)seri_in);
51 sprintf(handle->
name,
"server_request.%s", comm->
address);
53 handle = init_comm_base(comm->
name,
"recv", _default_comm, (
void*)seri_in);
55 ret = init_default_comm(handle);
60 comm->
handle = (
void*)handle;
61 if (_default_comm == ZMQ_COMM) {
68 cislog_error(
"init_server_comm: Failed to malloc info.");
72 comm->
info = (
void*)info;
82 int free_server_comm(
comm_t *x) {
85 free_default_comm(handle);
86 free_comm_base(handle);
90 if (x->
info != NULL) {
93 free_default_comm(*info);
94 free_comm_base(*info);
109 int server_comm_nmsg(
const comm_t x) {
111 int ret = default_comm_nmsg(*handle);
123 int server_comm_send(
const comm_t x,
const char *data,
const size_t len) {
124 cislog_debug(
"server_comm_send(%s): %d bytes", x.
name, len);
125 if (x.
info == NULL) {
126 cislog_error(
"server_comm_send(%s): no response comm registered", x.
name);
130 if (res_comm[0] == NULL) {
131 cislog_error(
"server_comm_send(%s): no response comm registered", x.
name);
134 int ret = default_comm_send((*res_comm)[0], data, len);
136 free_default_comm(res_comm[0]);
137 free_comm_base(res_comm[0]);
155 int server_comm_recv(
comm_t x,
char **data,
const size_t len,
const int allow_realloc) {
156 cislog_debug(
"server_comm_recv(%s)", x.
name);
158 cislog_error(
"server_comm_recv(%s): no request comm registered", x.
name);
162 int ret = default_comm_recv(*req_comm, data, len, allow_realloc);
174 cislog_error(
"server_comm_recv(%s): Error parsing header.", x.
name);
178 if (is_eof((*data) + head.
bodybeg)) {
184 cislog_error(
"server_comm_recv(%s): No response address in message.", x.
name);
188 char *seri_copy = (
char*)malloc(strlen((
char*)(x.
serializer->
info)) + 1);
189 if (seri_copy == NULL) {
190 cislog_error(
"server_comm_recv(%s): Failed to malloc seri_copy.");
199 newret = init_default_comm(res_comm[0]);
201 cislog_error(
"server_comm_recv(%s): Could not initialize response comm.", x.
name);
void * handle
Pointer to handle for comm.
Definition: CommBase.h:29
char response_address[COMMBUFFSIZ]
Response address.
Definition: comm_header.h:27
void * info
Pointer to any extra info comm requires.
Definition: CommBase.h:30
Communication structure.
Definition: CommBase.h:23
char address[COMM_ADDRESS_SIZE]
Comm address.
Definition: CommBase.h:26
void * info
Pointer to any extra info serializer requires.
Definition: SerializeBase.h:21
size_t bodybeg
Start of body in header.
Definition: comm_header.h:24
comm_type type
Comm type.
Definition: CommBase.h:24
int valid
1 if the header is valid, 0 otherwise.
Definition: comm_header.h:25
int always_send_header
1 if comm should always send a header.
Definition: CommBase.h:33
seri_t * serializer
Serializer for comm messages.
Definition: CommBase.h:31
char direction[COMM_DIR_SIZE]
send or recv for direction messages will go.
Definition: CommBase.h:27
char name[COMM_NAME_SIZE]
Comm name.
Definition: CommBase.h:25
int * sent_eof
Flag specifying if EOF has been sent.
Definition: CommBase.h:36
int * recv_eof
Flag specifying if EOF has been received.
Definition: CommBase.h:37
char id[COMMBUFFSIZ]
Unique ID associated with this message.
Definition: comm_header.h:26
Header information passed by comms for multipart messages.
Definition: comm_header.h:19