src/line_proto.h
author Tero Marttila <terom@fixme.fi>
Sun, 22 Feb 2009 10:16:28 +0200
changeset 10 9fe218576d13
parent 8 be88e543c8ff
child 11 14e79683c48c
permissions -rw-r--r--
fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
#ifndef LINE_PROTO_H
#define LINE_PROTO_H

/*
 * Support for protocols that send/receive lines
 */
#include "sock.h"
#include "error.h"

/*
 * The state handle
 */
struct line_proto;

/*
 * The callback for receiving lines
 */
typedef void (*line_proto_read_cb)(struct line_proto *lp, const char *line, void *arg);

/*
 * Create a new line_proto off the the given sock_stream. The newly allocated line_proto will be returned via *lp_ptr.
 *
 * The incoming lines are buffered in a buffer of \a buf_size bytes. This imposes a maximum limit on the line length.
 *
 * The given callback function/argument will be used to provide event-based recv support.
 */
err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, size_t buf_size,
        line_proto_read_cb cb_func, void *cb_arg, struct error_info *err);

/*
 * Receive one line into the given buffer. The line will be terminated with '\r\n', and said terminator will be
 * NUL'd out, so the buffer is safe for use as a C-string after succesfull return.
 *
 * Note: currently this uses the buffer to store intermediate state, so always pass the same buffer (for now).
 */
err_t line_proto_read (struct line_proto *lp, const char **line_ptr);

/*
 * Get current error_info*
 */
const struct error_info* line_proto_error (struct line_proto *lp);

#endif /* LINE_PROTO_H */