src/transport.c
author Tero Marttila <terom@fixme.fi>
Thu, 07 May 2009 02:17:29 +0300
changeset 178 3d357d055d67
parent 176 6750d50ee8cd
child 183 7bfbe9070c50
permissions -rw-r--r--
implement tcp_server, along with new error codes
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
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    38
    // 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
    39
    transport->connected = true;
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    40
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
    41
    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
    42
        // user callback
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    43
        if (err)
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    44
            // 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
    45
            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
    46
        else
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    47
            // 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
    48
            transport->info.cb_tbl->on_connect(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
    49
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    50
    } else {
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    51
        // 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
    52
        type->methods._connected(transport, 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
    53
    }
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    54
}
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    55
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    56
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
    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
    // 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
    59
    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
    60
        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
    61
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    62
    // 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
    63
    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
    64
        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
    65
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    66
}
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    67
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    68
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
    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
    // 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
    71
    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
    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
    // 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
    74
    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
    75
}
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    76
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    77
/*
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    78
 * Public API
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
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
    81
{
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
    82
    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
    83
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    84
    // 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
    85
    if (!type->methods.read)
159
d3e253d7281a implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents: 157
diff changeset
    86
        return SET_ERROR(err, -1);
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    87
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    88
    // 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
    89
    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
    90
        return -ERROR_CODE(err);
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    91
    
165
b3e95108c884 fix doc things
Tero Marttila <terom@fixme.fi>
parents: 159
diff changeset
    92
    // return updated 'bytes-read' len
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    93
    return len;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    94
}
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    95
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
    96
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
    97
{
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
    98
    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
    99
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   100
    // 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
   101
    if (!type->methods.write)
159
d3e253d7281a implement heirarchial type-checking for transport_check
Tero Marttila <terom@fixme.fi>
parents: 157
diff changeset
   102
        return SET_ERROR(err, -1);
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   103
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   104
    // 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
   105
    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
   106
        return -ERROR_CODE(err);
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   107
165
b3e95108c884 fix doc things
Tero Marttila <terom@fixme.fi>
parents: 159
diff changeset
   108
    // return updated 'bytes-written' len
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   109
    return len;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   110
}
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   111
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   112
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
   113
{
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
   114
    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
   115
    error_t err;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   116
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   117
    // 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
   118
    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
   119
        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
   120
            goto error;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   121
    }
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   122
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   123
    // update the event mask
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   124
    transport->info.ev_mask = mask;
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
    // ok
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   127
    return SUCCESS;
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
error:
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   130
    return ERROR_CODE(&err);
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
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   133
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
   134
{
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   135
    transport->info.cb_tbl = cb_tbl;
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   136
    transport->info.cb_arg = 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
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   139
void transport_destroy (transport_t *transport)
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   140
{
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
   141
    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
   142
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   143
    // 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
   144
    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
   145
        type->methods.deinit(transport);
156
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   146
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   147
    // then the transport itself
6534a4ac957b add transport/sock/line_proto/etc code compiles
Tero Marttila <terom@fixme.fi>
parents: 155
diff changeset
   148
    free(transport);
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