summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2014-11-30 21:45:00 +0100
committerAlfred E. Heggestad <aeh@db.org>2014-11-30 21:45:00 +0100
commit77ed30535fa53075fcc46239d35000825fcbd623 (patch)
treee1d186f171eda516e578df7f851437054afa3df3 /modules
parent847c497d84366caaae4e575a7cb700a5f092279d (diff)
cons: add output handler
Diffstat (limited to 'modules')
-rw-r--r--modules/cons/cons.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/modules/cons/cons.c b/modules/cons/cons.c
index 91c86c6..d5e78ca 100644
--- a/modules/cons/cons.c
+++ b/modules/cons/cons.c
@@ -37,6 +37,7 @@ struct ui_st {
struct udp_sock *us;
struct tcp_sock *ts;
struct tcp_conn *tc;
+ struct sa udp_peer;
};
@@ -55,6 +56,8 @@ static void udp_recv(const struct sa *src, struct mbuf *mb, void *arg)
struct mbuf *mbr = mbuf_alloc(64);
struct re_printf pf;
+ st->udp_peer = *src;
+
pf.vph = print_handler;
pf.arg = mbr;
@@ -67,8 +70,10 @@ static void udp_recv(const struct sa *src, struct mbuf *mb, void *arg)
ui_input_key(ch, &pf);
}
- mbr->pos = 0;
- (void)udp_send(st->us, src, mbr);
+ if (mbr->end > 0) {
+ mbr->pos = 0;
+ (void)udp_send(st->us, src, mbr);
+ }
mem_deref(mbr);
}
@@ -177,8 +182,39 @@ static int cons_alloc(struct ui_st **stp, const struct sa *laddr)
}
+static int output_handler(const char *str)
+{
+ struct mbuf *mb;
+ int err = 0;
+
+ if (!str)
+ return EINVAL;
+
+ mb = mbuf_alloc(256);
+ if (!mb)
+ return ENOMEM;
+
+ mbuf_write_str(mb, str);
+
+ if (sa_isset(&cons->udp_peer, SA_ALL)) {
+ mb->pos = 0;
+ err |= udp_send(cons->us, &cons->udp_peer, mb);
+ }
+
+ if (cons->tc) {
+ mb->pos = 0;
+ err |= tcp_send(cons->tc, mb);
+ }
+
+ mem_deref(mb);
+
+ return err;
+}
+
+
static struct ui ui_cons = {
.name = "cons",
+ .outputh = output_handler
};