Stub connection handler
This commit is contained in:
parent
63ee4ecea3
commit
e37e81599b
65
relay.c
65
relay.c
|
@ -23,23 +23,52 @@ typedef unsigned char u_char;
|
||||||
#include "relay.h"
|
#include "relay.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
void start_relay(struct sockaddr_in const *peername, int fd) {
|
struct boot_args {
|
||||||
/*
|
struct sockaddr_in peername;
|
||||||
connstate_t *conn = calloc(1, sizeof(connstate_t));
|
int fd;
|
||||||
conn->peername = *peername;
|
};
|
||||||
conn->fd = fd;
|
|
||||||
conn->amqp_conn = amqp_new_connection();
|
|
||||||
amqp_set_sockfd(conn->amqp_conn, fd);
|
|
||||||
conn->io = bufferevent_new(fd,
|
|
||||||
(evbuffercb) read_callback,
|
|
||||||
NULL,
|
|
||||||
(everrorcb) error_callback,
|
|
||||||
conn);
|
|
||||||
bufferevent_settimeout(conn->io, PROTOCOL_HEADER_TIMEOUT, 0);
|
|
||||||
bufferevent_enable(conn->io, EV_READ | EV_WRITE);
|
|
||||||
conn->state = CONNECTION_STATE_INITIAL;
|
|
||||||
conn->vhost = NULL;
|
|
||||||
*/
|
|
||||||
|
|
||||||
info("Accepted connection from %s on fd %d\n", endpoint_name(peername), fd);
|
static void relay_main(struct boot_args *args) {
|
||||||
|
IOHandle *h = new_iohandle(args->fd);
|
||||||
|
|
||||||
|
{
|
||||||
|
char name[256];
|
||||||
|
endpoint_name(&args->peername, (cmsg_bytes_t) { .bytes = name, .len = sizeof(name) });
|
||||||
|
info("Accepted connection from %s on fd %d\n", name, args->fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(args);
|
||||||
|
|
||||||
|
iohandle_settimeout(h, 3, 0);
|
||||||
|
while (1) {
|
||||||
|
cmsg_bytes_t buf = iohandle_readwait(h, 1);
|
||||||
|
if (buf.len == 0) {
|
||||||
|
switch (h->error_kind) {
|
||||||
|
case EVBUFFER_TIMEOUT:
|
||||||
|
info("Timeout\n");
|
||||||
|
iohandle_clear_error(h);
|
||||||
|
iohandle_write(h, cmsg_cstring_bytes("Timed out\n"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
info("Error! 0x%04X\n", h->error_kind);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
info("Read %d: %.*s\n", buf.len, buf.len, buf.bytes);
|
||||||
|
iohandle_drain(h, buf.len);
|
||||||
|
}
|
||||||
|
iohandle_write(h, cmsg_cstring_bytes("OK, proceed\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
ICHECK(iohandle_flush(h), "iohandle_flush");
|
||||||
|
ICHECK(close(h->fd), "close");
|
||||||
|
delete_iohandle(h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void start_relay(struct sockaddr_in const *peername, int fd) {
|
||||||
|
struct boot_args *args = malloc(sizeof(*args));
|
||||||
|
args->peername = *peername;
|
||||||
|
args->fd = fd;
|
||||||
|
spawn((process_main_t) relay_main, args);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue