src/lib/transport_internal.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 May 2009 01:17:36 +0300
branchnew-lib-errors
changeset 219 cefec18b8268
parent 183 src/transport_internal.h@7bfbe9070c50
permissions -rw-r--r--
some of the lib/transport stuff compiles
219
cefec18b8268 some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents: 183
diff changeset
     1
#ifndef LIBQMSK_TRANSPORT_INTERNAL_H
cefec18b8268 some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents: 183
diff changeset
     2
#define LIBQMSK_TRANSPORT_INTERNAL_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
 * The internal interface for transport implementations.
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */ 
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
#include "transport.h"
176
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    10
#include "object.h"
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    12
#include <stdbool.h>
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    13
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
/**
176
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    15
 * The object_type for a transport_type
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
 */
176
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    17
extern const struct object_type transport_type_type;
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
/**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
 * The definition of a transport type
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
struct transport_type {
176
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    23
    struct object_type base_type;
159
d3e253d7281a implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents: 157
diff changeset
    24
176
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    25
    /**
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    26
     * Method table for implementation stuff.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    27
     *
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    28
     * Note that it is the transport's resposibility to implement the behaviour described in transport.h
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    29
     */
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    30
    struct transport_methods {
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    31
        /** For transport_read() */
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    32
        err_t (*read) (transport_t *transport, void *buf, size_t *len, error_t *err);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    33
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    34
        /** For transport_write() */
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    35
        err_t (*write) (transport_t *transport, const void *buf, size_t *len, error_t *err);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    36
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    37
        /**
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    38
         * The mask of event flags will be set to the given mask if this method is succesfull.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    39
         *
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    40
         * The old mask is still available in transport::info::ev_mask.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    41
         */
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    42
        err_t (*events) (transport_t *transport, short mask, error_t *err);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    43
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    44
        /** 
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    45
         * Release the transport's internal state, but not the transport itself.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    46
         *
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    47
         * In other words, this should release everything inside the transport_t, but not free() the transport_t itself.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    48
         */
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    49
        void (*deinit) (transport_t *transport);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    50
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    51
        /**
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    52
         * Used by layered transports to handle transport_connected.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    53
         *
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    54
         * If this is NULL, transport_connected will call the user callback directly, otherwise, it will proxy through this.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    55
         *
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    56
         * The \a err param follows the same rules as for transport_connected() - NULL for success, error info otherwise.
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    57
         *
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    58
         * @param transport the transport state
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    59
         * @param err error info if the connect failed
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    60
         */
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    61
        void (*_connected) (transport_t *transport, const error_t *err);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    62
    } methods;
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
};
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
/**
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
 * The base transport type
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
 */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
struct transport {
176
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    69
    struct object base_obj;
154
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
    /** User info */
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
    struct transport_info info;
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    73
    
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    74
    /** Are we connected? */
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    75
    bool connected;
154
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
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
 * Bind the given transport to the given type with the given user info.
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
 *
157
1e5674d0eec4 fixed fifo
Tero Marttila <terom@fixme.fi>
parents: 156
diff changeset
    81
 * \a info may be given as NULL to not have any callbacks, but this will crash if any transport_* is called before
1e5674d0eec4 fixed fifo
Tero Marttila <terom@fixme.fi>
parents: 156
diff changeset
    82
 * transport_set_callbacks().
1e5674d0eec4 fixed fifo
Tero Marttila <terom@fixme.fi>
parents: 156
diff changeset
    83
 *
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    84
 * It is a bug to call this with a transport that is already bound.
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    85
 */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    86
void transport_init (transport_t *transport, const struct transport_type *type, const struct transport_info *info);
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    87
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
 * Check the type of the transport, and return the transport as a void* suitable for casting to the appropriate struct
159
d3e253d7281a implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents: 157
diff changeset
    90
 * for the type, or any of its children.
154
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
 * It is a bug to call this with a transport of a different type.
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
void* transport_check (transport_t *transport, const struct transport_type *type);
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    96
/**
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    97
 * Mark the transport as connected, calling transport_methods::_connected if it exists and \a direct is not given,
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    98
 * transport_callbacks::on_connected/transport_callbacks::on_error otherwise.
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    99
 *
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   100
 * If the connect succeeded, \a err should be given as NULL. If the connect failed, \a err should contain the error
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   101
 * info.
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
 * If called from the transport_methods::_connected method, pass in direct to avoid recursion.
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   104
 *
183
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
   105
 * This sets the transport::connected flag before calling transport_callbacks::on_connected (i.e. directly) without any
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
   106
 * error set.
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
 *
165
b3e95108c884 fix doc things
Tero Marttila <terom@fixme.fi>
parents: 159
diff changeset
   108
 * XXX: implement proper layering of types by taking a transport_type arg and chaining down from there.
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   109
 *
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   110
 * @param transport the transport state
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   111
 * @param err NULL for success, otherwise connect error code
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   112
 * @param direct call the user callback directly, ignoring any method
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   113
 */
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   114
void transport_connected (transport_t *transport, const error_t *err, bool direct);
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   115
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   116
/**
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   117
 * Invoke the user callbacks based on the given TRANSPORT_* flags
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   118
 */
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   119
void transport_invoke (transport_t *transport, short what);
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   120
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   121
/**
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   122
 * Mark the transport as failed, calling transport_methods::on_error with the given error code.
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   123
 */
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
   124
void transport_error (transport_t *transport, const error_t *err);
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
219
cefec18b8268 some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents: 183
diff changeset
   126
#endif