Files
adsb-tools/adsbus/flow.c

42 lines
839 B
C
Raw Normal View History

2016-02-29 20:49:36 -08:00
#include <unistd.h>
#include "buf.h"
#include "socket.h"
2016-02-29 20:49:36 -08:00
#include "flow.h"
void flow_socket_ready(int fd, struct flow *flow) {
socket_ready(fd);
if (flow->socket_ready) {
flow->socket_ready(fd);
}
}
2016-02-29 20:49:36 -08:00
bool flow_hello(int fd, struct flow *flow, void *passthrough) {
if (!flow->get_hello) {
return true;
}
struct buf buf = BUF_INIT, *buf_ptr = &buf;
flow->get_hello(&buf_ptr, passthrough);
if (!buf_ptr->length) {
return true;
}
return (write(fd, buf_at(buf_ptr, 0), buf_ptr->length) == (ssize_t) buf_ptr->length);
}
2016-03-02 19:16:23 -08:00
bool flow_new(int fd, struct flow *flow, void *passthrough) {
if (!flow_hello(fd, flow, passthrough)) {
return false;
}
flow->new(fd, passthrough, NULL);
return true;
}
void flow_ref_inc(struct flow *flow) {
(*flow->ref_count)++;
}
void flow_ref_dec(struct flow *flow) {
(*flow->ref_count)--;
}