tests/netgraph: Allow receiving answers to messages
Add msg_handler in order to receive messages from netgraph nodes to be tested. Reviewed by: kp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30657
This commit is contained in:
parent
f102b61d0e
commit
09307dbfb8
@ -34,7 +34,6 @@
|
||||
#include <atf-c.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/select.h>
|
||||
@ -59,9 +58,10 @@ struct data_handler {
|
||||
SLIST_ENTRY(data_handler) next;
|
||||
};
|
||||
static SLIST_HEAD(, data_handler) data_head = SLIST_HEAD_INITIALIZER(data_head);
|
||||
static ng_msg_handler_t msg_handler = NULL;
|
||||
|
||||
static void handle_data(void *ctx);
|
||||
static void handle_msg(void);
|
||||
static void handle_msg(void *ctx);
|
||||
|
||||
void
|
||||
ng_connect(char const *path1, char const *hook1,
|
||||
@ -143,14 +143,21 @@ ng_send_data(char const *hook,
|
||||
CHECK(, -1 != NgSendData(ds, hook, data, len));
|
||||
}
|
||||
|
||||
void
|
||||
ng_register_msg(ng_msg_handler_t proc) {
|
||||
msg_handler = proc;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_msg(void) {
|
||||
handle_msg(void *ctx) {
|
||||
struct ng_mesg *m;
|
||||
char path[NG_PATHSIZ];
|
||||
|
||||
ATF_REQUIRE(-1 != NgAllocRecvMsg(cs, &m, path));
|
||||
|
||||
printf("Got message from %s\n", path);
|
||||
if(msg_handler != NULL)
|
||||
(*msg_handler)(path, m, ctx);
|
||||
|
||||
free(m);
|
||||
}
|
||||
|
||||
@ -191,7 +198,7 @@ retry:
|
||||
return 0;
|
||||
default: /* something to do */
|
||||
if (FD_ISSET(cs, &fds))
|
||||
handle_msg();
|
||||
handle_msg(context);
|
||||
if (FD_ISSET(ds, &fds))
|
||||
handle_data(context);
|
||||
return 1;
|
||||
|
@ -46,6 +46,8 @@ typedef void (*ng_data_handler_t)(void *, size_t, void *ctx);
|
||||
void ng_register_data(char const *hook, ng_data_handler_t proc);
|
||||
void ng_send_data(char const *hook, void const *, size_t);
|
||||
|
||||
typedef void (*ng_msg_handler_t)(char const *, struct ng_mesg *, void *);
|
||||
void ng_register_msg(ng_msg_handler_t proc);
|
||||
int ng_send_msg(char const *path, char const *msg);
|
||||
|
||||
int ng_handle_event (unsigned int ms, void *ctx);
|
||||
|
Loading…
x
Reference in New Issue
Block a user