Changeset View
Changeset View
Standalone View
Standalone View
lib/libnetgraph/msg.c
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
NgSendMsg(int cs, const char *path, | NgSendMsg(int cs, const char *path, | ||||
int cookie, int cmd, const void *args, size_t arglen) | int cookie, int cmd, const void *args, size_t arglen) | ||||
{ | { | ||||
struct ng_mesg msg; | struct ng_mesg msg; | ||||
/* Prepare message header */ | /* Prepare message header */ | ||||
memset(&msg, 0, sizeof(msg)); | memset(&msg, 0, sizeof(msg)); | ||||
msg.header.version = NG_VERSION; | msg.header.version = NGM_VERSION; | ||||
msg.header.typecookie = cookie; | msg.header.typecookie = cookie; | ||||
msg.header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; | msg.header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; | ||||
msg.header.flags = NGF_ORIG; | |||||
donner: Do not set any flags. It's already zeroed space. | |||||
msg.header.cmd = cmd; | msg.header.cmd = cmd; | ||||
snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); | snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); | ||||
/* Deliver message */ | /* Deliver message */ | ||||
if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0) | if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0) | ||||
return (-1); | return (-1); | ||||
return (msg.header.token); | return (msg.header.token); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | NgSendAsciiMsg(int cs, const char *path, const char *fmt, ...) | ||||
/* Get reply */ | /* Get reply */ | ||||
if (NgAllocRecvMsg(cs, &reply, NULL) < 0) | if (NgAllocRecvMsg(cs, &reply, NULL) < 0) | ||||
return (-1); | return (-1); | ||||
/* Now send binary version */ | /* Now send binary version */ | ||||
binary = (struct ng_mesg *)reply->data; | binary = (struct ng_mesg *)reply->data; | ||||
binary->header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; | binary->header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; | ||||
binary->header.version = NG_VERSION; | binary->header.version = NGM_VERSION; | ||||
if (NgDeliverMsg(cs, | if (NgDeliverMsg(cs, | ||||
path, binary, binary->data, binary->header.arglen) < 0) { | path, binary, binary->data, binary->header.arglen) < 0) { | ||||
free(reply); | free(reply); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
token = binary->header.token; | token = binary->header.token; | ||||
free(reply); | free(reply); | ||||
return (token); | return (token); | ||||
} | } | ||||
/* | /* | ||||
* Send a message that is a reply to a previously received message. | * Send a message that is a reply to a previously received message. | ||||
* Returns -1 and sets errno on error, otherwise returns zero. | * Returns -1 and sets errno on error, otherwise returns zero. | ||||
*/ | */ | ||||
int | int | ||||
NgSendReplyMsg(int cs, const char *path, | NgSendReplyMsg(int cs, const char *path, | ||||
const struct ng_mesg *msg, const void *args, size_t arglen) | const struct ng_mesg *msg, const void *args, size_t arglen) | ||||
{ | { | ||||
struct ng_mesg rep; | struct ng_mesg rep; | ||||
/* Prepare message header */ | /* Prepare message header */ | ||||
rep = *msg; | rep = *msg; | ||||
rep.header.flags = NGF_RESP; | rep.header.flags |= NGF_RESP; | ||||
Done Inline ActionsThis overwrites other flags. donner: This overwrites other flags. | |||||
/* Deliver message */ | /* Deliver message */ | ||||
return (NgDeliverMsg(cs, path, &rep, args, arglen)); | return (NgDeliverMsg(cs, path, &rep, args, arglen)); | ||||
} | } | ||||
/* | /* | ||||
* Send a message to a node using control socket node "cs". | * Send a message to a node using control socket node "cs". | ||||
* Returns -1 if error and sets errno appropriately, otherwise zero. | * Returns -1 if error and sets errno appropriately, otherwise zero. | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |
Do not set any flags. It's already zeroed space.