src/nexus.c
author Tero Marttila <terom@fixme.fi>
Sun, 22 Feb 2009 08:21:22 +0200
changeset 8 be88e543c8ff
parent 7 844f014409ff
child 9 4c4c906cc649
permissions -rw-r--r--
split off line_proto, and make sock_stream_error return a const error_info

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <event.h>
#include <assert.h>

#include <err.h>

#include "sock.h"
#include "line_proto.h"

#define CONNECT_HOST "irc.fixme.fi"
#define CONNECT_SERV "6697"
#define LINE_LENGTH 512

int main (int argc, char **argv) {
    struct sock_stream *sock;
    struct line_proto *lp;
    char line_buf[LINE_LENGTH + 1];
    struct error_info err;

    // initialize
    if (sock_init(&err))
        errx(1, "sock_init: %s", error_msg(&err));

    // over-simplified connect
    if (sock_gnutls_connect(&sock, CONNECT_HOST, CONNECT_SERV, &err))
        errx(1, "sock_gnutls_connect: %s", error_msg(&err));

    // line protocol
    if (line_proto_create(&lp, sock, &err))
        errx(1, "line_proto_create: %s", error_msg(&err));

    // read lines and dump them out
    do {
        // recv
        if (line_proto_read(lp, line_buf, sizeof(line_buf)))
            errx(1, "line_proto_read: %s", error_msg(line_proto_error(lp)));

        // printf
        printf("<<< %s\n", line_buf);

    } while (1);
    
    // ok
    return 0;
}