src/line_proto.h
author Tero Marttila <terom@fixme.fi>
Tue, 10 Mar 2009 03:38:20 +0200
changeset 32 ae66e9ae4afb
parent 28 9c1050bc8709
child 33 e5139b339b18
permissions -rw-r--r--
convert line_proto to use a line_proto_callbacks struct
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef LINE_PROTO_H
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define LINE_PROTO_H
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
32
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
     4
/**
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
     5
 * @file
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
     6
 *
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
 * Support for protocols that send/receive lines
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
#include "sock.h"
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
#include "error.h"
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
32
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    12
/**
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    13
 * The line_proto state handle
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
 */
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
struct line_proto;
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
32
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    17
/**
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    18
 * User callback list
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    19
 */
32
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    20
struct line_proto_callbacks {
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    21
    /** Handle received line */
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    22
    void (*on_line) (char *line, void *arg);
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    23
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    24
};
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    25
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    26
/**
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
 * Create a new line_proto off the the given sock_stream. The newly allocated line_proto will be returned via *lp_ptr.
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    28
 *
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    29
 * The incoming lines are buffered in a buffer of \a buf_size bytes. This imposes a maximum limit on the line length.
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    30
 *
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    31
 * @param lp_ptr a pointer to the new line_proto will be returned via this pointer
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    32
 * @param sock the sock_stream to use
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    33
 * @param buf_size the incoming/outgoing buffer size, should be enough to hold the biggest possible line
32
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    34
 * @param callbacks the callback struct to use
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    35
 * @param cb_arg the read_cb callback argument
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    36
 * @param err error information is returned via this pointer
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
 */
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    38
err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, size_t buf_size,
32
ae66e9ae4afb convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents: 28
diff changeset
    39
        const struct line_proto_callbacks *callbacks, void *cb_arg, struct error_info *err);
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    41
/**
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
    42
 * Runs the socket recv() into our internal buffer. If a full line was received, a pointer to our internal bufffer is
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
    43
 * returned via *line_ptr, and we return SUCCESS. If we don't yet have a full line, and receiving more would block,
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
    44
 * NULL is returned via *line_ptr instead. Otherwise, nonzero error return code.
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    45
 *
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    46
 * @param line_ptr a pointer to the received line is returned via this pointer
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
 */
19
8c80580ccde9 improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    48
err_t line_proto_recv (struct line_proto *lp, char **line_ptr);
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    50
/**
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    51
 * Write a single line to the sock_stream, buffering any incomplete fragment that remains unset. Returns zero if the
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    52
 * line was succesfully sent, >0 if it was only partially sent, or -err on errors.
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    53
 *
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    54
 * The given line should already include the terminating '\r\n' character sequence.
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    55
 *
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    56
 * @param line pointer to buffer containing \r\n\0 terminated line
12
4147fae232d9 update sock_stream_read/write semantics for EOF/EAGAIN, tentative event-based gnutls code
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    57
 */
19
8c80580ccde9 improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    58
int line_proto_send (struct line_proto *lp, const char *line);
8c80580ccde9 improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    59
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    60
/**
19
8c80580ccde9 improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    61
 * Flush out any buffered line fragment. Returns zero if the buffer was flushed empty, >0 if there's still fragments
8c80580ccde9 improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    62
 * remaining, or -err on errors.
8c80580ccde9 improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    63
 */
8c80580ccde9 improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    64
int line_proto_flush (struct line_proto *lp);
12
4147fae232d9 update sock_stream_read/write semantics for EOF/EAGAIN, tentative event-based gnutls code
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    65
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    66
/**
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
 * Get current error_info*
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
 */
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
const struct error_info* line_proto_error (struct line_proto *lp);
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    71
/**
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    72
 * Release any allocated buffers, and the underlying sock_stream.
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    73
 *
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    74
 * This does not close the connection cleanly, and is intended for use to abort after errors.
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    75
 */
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    76
void line_proto_release (struct line_proto *lp);
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    77
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
#endif /* LINE_PROTO_H */