author | Tero Marttila <terom@fixme.fi> |
Thu, 28 May 2009 01:17:36 +0300 | |
branch | new-lib-errors |
changeset 219 | cefec18b8268 |
parent 217 | src/line_proto.h@7728d6ec3abf |
permissions | -rw-r--r-- |
219
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
217
diff
changeset
|
1 |
#ifndef LIBQMSK_LINE_PROTO_H |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
217
diff
changeset
|
2 |
#define LIBQMSK_LINE_PROTO_H |
8
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 |
*/ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
9 |
#include "transport.h" |
8
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 |
/** |
87 | 18 |
* User callbacks for event-based line_proto behaviour |
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); |
33
e5139b339b18
add line_proto_callbacks.on_error, although irc_conn doesn't pass it up
Tero Marttila <terom@fixme.fi>
parents:
32
diff
changeset
|
23 |
|
45
71e65564afd2
remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
24 |
/** Transport failed, the line_proto is corrupt, you should call line_proto_release next. */ |
217 | 25 |
void (*on_error) (const error_t *err, void *arg); |
32
ae66e9ae4afb
convert line_proto to use a line_proto_callbacks struct
Tero Marttila <terom@fixme.fi>
parents:
28
diff
changeset
|
26 |
}; |
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
|
27 |
|
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
|
28 |
/** |
8
be88e543c8ff
split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
* 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
|
30 |
* |
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
|
31 |
* 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
|
32 |
* |
157 | 33 |
* In case of errors, \a transport will be destroyed in any case. |
34 |
* |
|
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 lp_ptr a pointer to the new line_proto will be returned via this pointer |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
36 |
* @param transport the connected transport 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
|
37 |
* @param buf_size the incoming/outgoing buffer size, should be enough to hold the biggest possible line |
41
40f7aa051acb
add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
38 |
* @param callbacks the callbacks to use, a copy is stored |
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
|
39 |
* @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
|
40 |
* @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
|
41 |
*/ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
90
diff
changeset
|
42 |
err_t line_proto_create (struct line_proto **lp_ptr, transport_t *transport, size_t buf_size, |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
43 |
const struct line_proto_callbacks *callbacks, void *cb_arg, error_t *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
|
44 |
|
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 |
/** |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
46 |
* Runs transport_read() with our internal buffer. If a full line was received, a pointer to our internal bufffer is |
11
14e79683c48c
working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
47 |
* 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
|
48 |
* 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
|
49 |
* |
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 |
* @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
|
51 |
*/ |
19
8c80580ccde9
improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
52 |
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
|
53 |
|
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
|
54 |
/** |
90
9d489b1039b2
implement irc_queue, with some basic functionality tests
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
55 |
* Write a single line to the sock_stream, buffering any incomplete fragment that remains unsent. Returns zero if the |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
56 |
* 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
|
57 |
* |
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
58 |
* 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
|
59 |
* |
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 |
* @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
|
61 |
*/ |
19
8c80580ccde9
improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
62 |
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
|
63 |
|
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
|
64 |
/** |
19
8c80580ccde9
improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
65 |
* 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
|
66 |
* remaining, or -err on errors. |
160 | 67 |
* |
68 |
* It is a bug to call this if there is no data waiting to be sent. |
|
19
8c80580ccde9
improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
69 |
*/ |
8c80580ccde9
improve line_proto output buffering slightly
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
70 |
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
|
71 |
|
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
|
72 |
/** |
8
be88e543c8ff
split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
* 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
|
74 |
*/ |
217 | 75 |
const error_t* line_proto_error (struct line_proto *lp); |
8
be88e543c8ff
split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
|
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
|
77 |
/** |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
78 |
* Destroy any buffers and the underlying transport. |
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
|
79 |
* |
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
|
80 |
* 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
|
81 |
*/ |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
82 |
void line_proto_destroy (struct line_proto *lp); |
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
|
83 |
|
219
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
217
diff
changeset
|
84 |
#endif |