src/transport.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 May 2009 23:57:48 +0300
branchnew-lib-errors
changeset 217 7728d6ec3abf
parent 196 873796250c60
permissions -rw-r--r--
nexus.c compiles
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef TRANSPORT_H
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define TRANSPORT_H
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"
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
/**
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    13
 * Opaque transport state handle.
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    14
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    15
 * 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
    16
 * 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
    17
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    18
 * 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
    19
 * 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
    20
 * 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
    21
 * 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
    22
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    23
 * 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
    24
 * These implement unbuffered I/O, so they may do partial reads/writes. In terms of the system read/write calls, the
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    25
 * main difference is in the error return codes. On EOF, instead of returning zero, they return ERR_EOF (or
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    26
 * ERR_WRITE_EOF for transport_write, for whoever knows what that means...). This means that when the underlying
165
b3e95108c884 fix doc things
Tero Marttila <terom@fixme.fi>
parents: 156
diff changeset
    27
 * 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
    28
 * something simliar to EAGAIN.
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    29
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    30
 * 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
    31
 * 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
    32
 * 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
    33
 * 
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    34
 * 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
    35
 * 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
    36
 * 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
    37
 * relevant callback from being triggered.
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    38
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    39
 * 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
    40
 * 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
    41
 * 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
    42
 *
165
b3e95108c884 fix doc things
Tero Marttila <terom@fixme.fi>
parents: 156
diff changeset
    43
 * 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
    44
 * 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
    45
 * 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
    46
 * 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
    47
 * 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
    48
 * 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
    49
 *
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
 * 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
    51
 * 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
    52
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
struct transport;
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
/**
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    56
 * @see transport
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
typedef struct transport transport_t;
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
/**
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    61
 * User callbacks for transports
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    62
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    63
 * @see transport
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
struct transport_callbacks {
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
    /**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
     * The transport is now connected
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
     */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
    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
    70
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    71
    /**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
     * 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
    73
     */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
    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
    75
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
    /**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
     * The transport has become writeable
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
     */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
    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
    80
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
     * 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
    83
     * 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
    84
     *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    85
     * 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
    86
     */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    87
    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
    88
};
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    89
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    90
/**
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    91
 * Bitmask of available events
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    92
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    93
 * @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
    94
 */
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    95
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
    96
    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
    97
    TRANSPORT_WRITE = 0x02,
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
};
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
/**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   101
 * 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
   102
 *
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   103
 * @see transport
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   104
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   105
struct transport_info {
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   106
    /** The callbacks table */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   107
    const struct transport_callbacks *cb_tbl;
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   108
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   109
    /** The callback context argument */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
    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
   111
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   112
    /** 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
   113
    short ev_mask;
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
};
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
/**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
 * 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
   118
 * 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
   119
 * 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
   120
 *
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   121
 * 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
   122
 * 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
   123
 *
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   124
 * @param transport the transport state
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
 * @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
   126
 * @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
   127
 * @param err returned error info
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
 * @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
   129
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
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
   131
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   132
/**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   133
 * 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
   134
 * 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
   135
 * 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
   136
 * 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
   137
 *
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
 * 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
   139
 *
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   140
 * @param transport the transport state
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   141
 * @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
   142
 * @param len number of bytes to write
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   143
 * @param err returned error info
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   144
 * @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
   145
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   146
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
   147
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   148
/**
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   149
 * 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
   150
 */
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   151
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
   152
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   153
/**
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   154
 * 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
   155
 */
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   156
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
   157
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   158
/**
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
 * 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
   160
 *
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   161
 * 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
   162
 * used anymore.
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   163
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   164
void transport_destroy (transport_t *transport);
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   165
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   166
#endif