update sock_stream_read/write semantics for EOF/EAGAIN, tentative event-based gnutls code
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <event.h>
#include <assert.h>
#include <err.h>
#include <event2/event.h>
#include "sock.h"
#include "line_proto.h"
#define CONNECT_HOST "localhost"
#define CONNECT_SERV "5001"
#define LINE_LENGTH 512
void on_line (const char *line, void *arg) {
printf("<<< %s\n", line);
}
int main (int argc, char **argv) {
struct event_base *ev_base;
struct sock_stream *sock;
struct line_proto *lp;
struct error_info _err;
// initialize libevent
if ((ev_base = event_base_new()) == NULL)
err(1, "event_base_new");
// initialize sock module
if (sock_init(ev_base, &_err))
errx(1, "sock_init: %s", error_msg(&_err));
// over-simplified connect
if (sock_tcp_connect(&sock, CONNECT_HOST, CONNECT_SERV, &_err))
errx(1, "sock_gnutls_connect: %s", error_msg(&_err));
// line protocol
if (line_proto_create(&lp, sock, LINE_LENGTH, on_line, NULL, &_err))
errx(1, "line_proto_create: %s", error_msg(&_err));
// run event loop
if (event_base_dispatch(ev_base))
errx(1, "event_base_dispatch");
// ok, no cleanup
return 0;
}