author | Tero Marttila <terom@fixme.fi> |
Thu, 28 May 2009 01:17:36 +0300 | |
branch | new-lib-errors |
changeset 219 | cefec18b8268 |
parent 196 | src/transport.h@873796250c60 |
permissions | -rw-r--r-- |
219
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
1 |
#ifndef LIBQMSK_TRANSPORT_H |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
2 |
#define LIBQMSK_TRANSPORT_H |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
* @file |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
* |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
* Defines a intermediate-level (as opposed to high-level or low-level) API for connected streams of data, presumeably |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
* non-blocking ones. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
#include "error.h" |
219
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
11 |
#include <stddef.h> |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
/** |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
14 |
* Opaque transport state handle. |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
15 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
16 |
* Transports are reliable byte streams, connected with some endpoint over some medium. Common implementations are |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
17 |
* e.g. TCP, SSL or fifo transports (using the OS file/socket API). |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
18 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
19 |
* Transports can be connected or unconnected. For synchronous opens (e.g. fifo_open_read()), the transport returned |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
20 |
* will already be connected, meaning that the transport_callbacks::on_connect callback is unused. For async connects |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
21 |
* such as sock_tcp_connect()/sock_ssl_connect(), the transport returned is *not* connected, and you must wait for |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
22 |
* transport_callbacks::on_connect to be called before being able to send/recieve data on the transport. |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
23 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
24 |
* Once you have an opened transport, sending and receiving data is simple - just call transport_read()/transport_write(). |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
25 |
* These implement unbuffered I/O, so they may do partial reads/writes. In terms of the system read/write calls, the |
219
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
26 |
* main difference is in the error return codes. On EOF, instead of returning zero, they return ERR_TRANSPORT_EOF (or |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
27 |
* ERR_WRITE_EOF for transport_write, for whoever knows what that means...). This means that when the underlying |
165 | 28 |
* transport is unable to fufill the request due to lack of data/buffer space, these can return zero to signifiy |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
29 |
* something simliar to EAGAIN. |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
30 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
31 |
* The transport API also implements non-blocking/event-based operation (usually on top of libevent), although at a |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
32 |
* slightly different level than the normal select/poll API. Instead of the user asking the transport to notify for |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
33 |
* read/write after transport_read/transport_write return zero, the transport will take care of this itself. |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
34 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
35 |
* Specifically, the user can supply a mask of events they are currently interested in. By default, this should be the |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
36 |
* full TRANSPORT_READ | TRANSPORT_WRITE, as the transport will take care of managing events by itself. If you wish to |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
37 |
* e.g. throttle read/write, you may set a different event mask using transport_events(), which will prevent the |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
38 |
* relevant callback from being triggered. |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
39 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
40 |
* For reads, the transport maintains a persistent read event, and will always call on_read when data is available on |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
41 |
* the socket (i.e. normal select() semantics). If masked out using transport_events(), there should be no event |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
42 |
* activity on the transport (i.e. the fd read event is removed). |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
43 |
* |
165 | 44 |
* For writes, the transport maintains a write event that is disabled by default. If transport_write() returns zero, it will |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
45 |
* become enabled *once*, and consequently trigger transport_callbacks::on_write *once*, after which you must call |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
46 |
* transport_write() to possibly enable it again. If masked out using transport_events(), transport_write() will not |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
47 |
* enable the write event, and any pending write event is cancelled. If masked back in using transport_events(), the |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
48 |
* write event will *not* be registered, so if you have pending data, do a transport_write() after enabling |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
49 |
* TRANSPORT_WRITE. |
196
873796250c60
implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents:
165
diff
changeset
|
50 |
* |
873796250c60
implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents:
165
diff
changeset
|
51 |
* Note that transport_write() returning fewer bytes than given will *not* enable the write event! You must call |
873796250c60
implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents:
165
diff
changeset
|
52 |
* transport_write() until you have either written all of your data, or it returns zero! |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
struct transport; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
/** |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
57 |
* @see transport |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
typedef struct transport transport_t; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
/** |
219
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
62 |
* Errors |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
63 |
*/ |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
64 |
enum transport_error_code { |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
65 |
ERR_TRANSPORT_NONE, |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
66 |
ERR_TRANSPORT_EOF, ///< EOF |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
67 |
ERR_TRANSPORT_READABLE, ///< transport not readable |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
68 |
ERR_TRANSPORT_WRITEABLE, ///< transport not writeable |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
69 |
}; |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
70 |
|
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
71 |
const struct error_list transport_errors; |
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
72 |
|
cefec18b8268
some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents:
196
diff
changeset
|
73 |
/** |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
74 |
* User callbacks for transports |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
75 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
76 |
* @see transport |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
struct transport_callbacks { |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
* The transport is now connected |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
void (*on_connect) (transport_t *transport, void *arg); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
* Data is now available for reading from the transport |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
86 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
87 |
void (*on_read) (transport_t *transport, void *arg); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
88 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
89 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
* The transport has become writeable |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
void (*on_write) (transport_t *transport, void *arg); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
* An asynchronous error has occured. This is only called for errors that occur while being called directly from |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
* the underlying event loop, and never from inside an API function. |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
97 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
98 |
* You must call transport_destroy to release the transport. |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
99 |
*/ |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
100 |
void (*on_error) (transport_t *transport, const error_t *err, void *arg); |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
101 |
}; |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
102 |
|
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
103 |
/** |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
104 |
* Bitmask of available events |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
105 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
106 |
* @see transport |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
107 |
*/ |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
108 |
enum transport_event { |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
109 |
TRANSPORT_READ = 0x01, |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
110 |
TRANSPORT_WRITE = 0x02, |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
111 |
}; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
112 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
113 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
114 |
* User info required to build a transport |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
115 |
* |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
116 |
* @see transport |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
117 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
118 |
struct transport_info { |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
119 |
/** The callbacks table */ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
120 |
const struct transport_callbacks *cb_tbl; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
121 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
122 |
/** The callback context argument */ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
123 |
void *cb_arg; |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
124 |
|
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
125 |
/** Initial event mask using transport_event flags */ |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
126 |
short ev_mask; |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
127 |
}; |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
128 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
129 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
130 |
* Read a series of bytes from the transport into the given \a buf (up to \a len bytes). If succesfull, this returns |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
131 |
* the number of bytes read (which will be less than or equal to \a len). If the transport is nonblocking, and there is |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
132 |
* no data available, this returns zero, and need not be called again until transport_callbacks::on_read is invoked. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
133 |
* |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
134 |
* On errors, this returns the negative error code, and more info via \a err. Note that as opposed to read(2), EOF is |
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
135 |
* handled as an error, returning ERR_EOF. |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
136 |
* |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
137 |
* @param transport the transport state |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
138 |
* @param buf the buffer to read the bytes into |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
139 |
* @param len the number of bytes to read into the buffer |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
140 |
* @param err returned error info |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
141 |
* @return bytes read, zero if none available, -err_t |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
142 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
143 |
int transport_read (transport_t *transport, void *buf, size_t len, error_t *err); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
144 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
145 |
/** |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
146 |
* Write a series of bytes from the given \a buf (containing \a len bytes) to the transport. If succesfull, this |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
147 |
* returns the number of bytes written (which may be less than \a len). If the transport is nonblocking, and the |
196
873796250c60
implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents:
165
diff
changeset
|
148 |
* operation would have blocked, no data will be written, and zero is returned; in this case, the transport's write |
873796250c60
implement msg_proto and associated test, fix misc. other bugs (including changing error_info::code to a signed int\!)
Tero Marttila <terom@fixme.fi>
parents:
165
diff
changeset
|
149 |
* event is enabled (unless TRANSPORT_WRITE is masked out). |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
150 |
* |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
151 |
* On errors, this returns the negative error code, along with extended info via \a err. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
152 |
* |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
153 |
* @param transport the transport state |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
154 |
* @param buf the buffer to write the bytes from |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
155 |
* @param len number of bytes to write |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
156 |
* @param err returned error info |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
157 |
* @return bytes written, zero if would have blocked, -err_t |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
158 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
159 |
int transport_write (transport_t *transport, const void *buf, size_t len, error_t *err); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
160 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
161 |
/** |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
162 |
* Change the mask of enabled events. |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
163 |
*/ |
156
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
164 |
err_t transport_events (transport_t *transport, short mask); |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
165 |
|
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
166 |
/** |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
167 |
* Install a new set of callback handlers, replacing the old ones. |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
168 |
*/ |
6534a4ac957b
add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents:
155
diff
changeset
|
169 |
void transport_set_callbacks (transport_t *transport, const struct transport_callbacks *cb_tbl, void *cb_arg); |
155
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
170 |
|
c59d3eaff0fb
most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents:
154
diff
changeset
|
171 |
/** |
154
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
172 |
* Close and destroy the transport immediately, severing any established connection rudely. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
173 |
* |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
174 |
* This will release all resources associated with the transport, including the transport itself, which must not be |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
175 |
* used anymore. |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
176 |
*/ |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
177 |
void transport_destroy (transport_t *transport); |
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
178 |
|
f4472119de3b
initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
179 |
#endif |