src/transport.c
author Tero Marttila <terom@fixme.fi>
Wed, 20 May 2009 22:52:01 +0300
changeset 202 210c43e6c088
parent 183 7bfbe9070c50
permissions -rw-r--r--
slight tweaks to nexus_lua, use error_t and no need to pop the loaded chunk ourselv - lua_pcall will always do that
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#include "transport_internal.h"
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
     3
#include <assert.h>
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
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
     5
/**
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
     6
 * Our own object_type
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
     7
 */
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
     8
const struct object_type transport_type_type = {
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
     9
    .parent     = NULL,
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
};
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    11
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    12
/*
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    13
 * Internal API
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    14
 */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    15
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
    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
    // init object
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    18
    object_init(&transport->base_obj, &type->base_type);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    19
    
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
    // store
157
1e5674d0eec4 fixed fifo
Tero Marttila <terom@fixme.fi>
parents: 156
diff changeset
    21
    if (info)
1e5674d0eec4 fixed fifo
Tero Marttila <terom@fixme.fi>
parents: 156
diff changeset
    22
        transport->info = *info;
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
}
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
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
    26
{
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
    27
    // trip as a bug
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
    assert(object_check(&transport->base_obj, &type->base_type));
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
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
    30
    // ok, cast via void*
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
    return transport;
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
}
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    33
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    34
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
    35
{
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
    36
    const struct transport_type *type = object_type(&transport->base_obj, &transport_type_type);
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
    if (direct || !type->methods._connected) {
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    39
        // user callback
183
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    40
        if (err) {
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    41
            // connect failed
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    42
            transport->info.cb_tbl->on_error(transport, err, transport->info.cb_arg);
183
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    43
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    44
        } else {
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    45
            // update state
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    46
            transport->connected = true;
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    47
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    48
            // connect succesfull
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    49
            transport->info.cb_tbl->on_connect(transport, transport->info.cb_arg);
183
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    50
        }
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    51
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    52
    } else {
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    53
        // wrapper method
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
    54
        type->methods._connected(transport, err);
183
7bfbe9070c50 slight tweaks to ssl_client's handshake-done logic
Tero Marttila <terom@fixme.fi>
parents: 176
diff changeset
    55
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    56
    }
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    57
}
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    58
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    59
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
    60
{
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    61
    // on_ready
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    62
    if (what & TRANSPORT_READ && transport->info.cb_tbl->on_read)
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    63
        transport->info.cb_tbl->on_read(transport, transport->info.cb_arg);
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    64
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    65
    // on_write
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    66
    if (what & TRANSPORT_WRITE && transport->info.cb_tbl->on_write)
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    67
        transport->info.cb_tbl->on_write(transport, transport->info.cb_arg);
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    68
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    69
}
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    70
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    71
void transport_error (transport_t *transport, const error_t *err)
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    72
{
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    73
    // update state
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    74
    transport->connected = false;
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    75
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    76
    // invoke callback
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    77
    transport->info.cb_tbl->on_error(transport, err, transport->info.cb_arg);
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    78
}
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    79
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    80
/*
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    81
 * Public API
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    82
 */
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    83
int transport_read (transport_t *transport, void *buf, size_t len, error_t *err)
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    84
{
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
    85
    const struct transport_type *type = object_type(&transport->base_obj, &transport_type_type);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
    86
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    87
    // not readable
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
    88
    if (!type->methods.read)
159
d3e253d7281a implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents: 157
diff changeset
    89
        return SET_ERROR(err, -1);
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    90
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    91
    // proxy off to method handler
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
    92
    if (type->methods.read(transport, buf, &len, err))
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    93
        return -ERROR_CODE(err);
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    94
    
165
b3e95108c884 fix doc things
Tero Marttila <terom@fixme.fi>
parents: 159
diff changeset
    95
    // return updated 'bytes-read' len
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    96
    return len;
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
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    99
int transport_write (transport_t *transport, const void *buf, size_t len, error_t *err)
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   100
{
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
   101
    const struct transport_type *type = object_type(&transport->base_obj, &transport_type_type);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
   102
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   103
    // XXX: not writeable
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
   104
    if (!type->methods.write)
159
d3e253d7281a implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents: 157
diff changeset
   105
        return SET_ERROR(err, -1);
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   106
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   107
    // proxy off to method handler
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
   108
    if (type->methods.write(transport, buf, &len, err))
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   109
        return -ERROR_CODE(err);
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   110
165
b3e95108c884 fix doc things
Tero Marttila <terom@fixme.fi>
parents: 159
diff changeset
   111
    // return updated 'bytes-written' len
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   112
    return len;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   113
}
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   114
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   115
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
   116
{
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
   117
    const struct transport_type *type = object_type(&transport->base_obj, &transport_type_type);
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   118
    error_t err;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   119
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   120
    // notify 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
   121
    if (type->methods.events) {
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
   122
        if (type->methods.events(transport, mask, &err))
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   123
            goto error;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   124
    }
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   125
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   126
    // update the event mask
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   127
    transport->info.ev_mask = mask;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   128
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   129
    // ok
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   130
    return SUCCESS;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   131
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   132
error:
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   133
    return ERROR_CODE(&err);
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   134
}
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   135
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   136
void transport_set_callbacks (transport_t *transport, const struct transport_callbacks *cb_tbl, void *cb_arg)
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   137
{
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   138
    transport->info.cb_tbl = cb_tbl;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   139
    transport->info.cb_arg = cb_arg;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   140
}
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   141
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   142
void transport_destroy (transport_t *transport)
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   143
{
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
   144
    const struct transport_type *type = object_type(&transport->base_obj, &transport_type_type);
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
   145
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   146
    // destroy the transport-specific stuff
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
   147
    if (type->methods.deinit)
6750d50ee8cd modify transport to use the new object_* stuff, along with transport_fd and fifo
Tero Marttila <terom@fixme.fi>
parents: 165
diff changeset
   148
        type->methods.deinit(transport);
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   149
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   150
    // then the transport itself
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   151
    free(transport);
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