src/nexus.c
changeset 13 ca16f3a8f3b7
parent 12 4147fae232d9
child 14 3a70e5901f17
equal deleted inserted replaced
12:4147fae232d9 13:ca16f3a8f3b7
    11 
    11 
    12 #include "sock.h"
    12 #include "sock.h"
    13 #include "line_proto.h"
    13 #include "line_proto.h"
    14 
    14 
    15 #define CONNECT_HOST "localhost"
    15 #define CONNECT_HOST "localhost"
    16 #define CONNECT_SERV "5001"
    16 #define CONNECT_SERV "5002"
    17 #define LINE_LENGTH 512
    17 #define LINE_LENGTH 512
    18 
    18 
    19 void on_line (const char *line, void *arg) {
    19 void on_line (const char *line, void *arg) {
    20     printf("<<< %s\n", line);
    20     printf("<<< %s\n", line);
    21 }
    21 }
    36 
    36 
    37     // over-simplified connect
    37     // over-simplified connect
    38     if (sock_tcp_connect(&sock, CONNECT_HOST, CONNECT_SERV, &_err))
    38     if (sock_tcp_connect(&sock, CONNECT_HOST, CONNECT_SERV, &_err))
    39         errx(1, "sock_gnutls_connect: %s", error_msg(&_err));
    39         errx(1, "sock_gnutls_connect: %s", error_msg(&_err));
    40 
    40 
    41     // line protocol
    41     // line protocol, with safety margin for buffer
    42     if (line_proto_create(&lp, sock, LINE_LENGTH, on_line, NULL, &_err))
    42     if (line_proto_create(&lp, sock, LINE_LENGTH * 2, on_line, NULL, &_err))
    43         errx(1, "line_proto_create: %s", error_msg(&_err));
    43         errx(1, "line_proto_create: %s", error_msg(&_err));
    44 
    44 
    45     // run event loop
    45     // run event loop
    46     if (event_base_dispatch(ev_base))
    46     if (event_base_dispatch(ev_base))
    47         errx(1, "event_base_dispatch");
    47         errx(1, "event_base_dispatch");