equal
deleted
inserted
replaced
17 transport->info = *info; |
17 transport->info = *info; |
18 } |
18 } |
19 |
19 |
20 void* transport_check (transport_t *transport, const struct transport_type *type) |
20 void* transport_check (transport_t *transport, const struct transport_type *type) |
21 { |
21 { |
|
22 const struct transport_type *tp_type; |
|
23 |
22 // sanity check |
24 // sanity check |
23 assert(type && transport->type == type); |
25 assert(type); |
24 |
26 |
|
27 // look for a matching type in the transport's type list |
|
28 for (tp_type = transport->type; tp_type; tp_type = tp_type->parent) |
|
29 if (tp_type == type) |
|
30 break; |
|
31 |
|
32 // make sure we found one |
|
33 assert(tp_type); |
|
34 |
25 // ok |
35 // ok |
26 return transport; |
36 return transport; |
27 } |
37 } |
28 |
38 |
29 void transport_connected (transport_t *transport, const error_t *err, bool direct) |
39 void transport_connected (transport_t *transport, const error_t *err, bool direct) |
72 */ |
82 */ |
73 int transport_read (transport_t *transport, void *buf, size_t len, error_t *err) |
83 int transport_read (transport_t *transport, void *buf, size_t len, error_t *err) |
74 { |
84 { |
75 // not readable |
85 // not readable |
76 if (!transport->type->methods.read) |
86 if (!transport->type->methods.read) |
77 return -1; |
87 return SET_ERROR(err, -1); |
78 |
88 |
79 // proxy off to method handler |
89 // proxy off to method handler |
80 if (transport->type->methods.read(transport, buf, &len, err)) |
90 if (transport->type->methods.read(transport, buf, &len, err)) |
81 return -ERROR_CODE(err); |
91 return -ERROR_CODE(err); |
82 |
92 |
86 |
96 |
87 int transport_write (transport_t *transport, const void *buf, size_t len, error_t *err) |
97 int transport_write (transport_t *transport, const void *buf, size_t len, error_t *err) |
88 { |
98 { |
89 // XXX: not writeable |
99 // XXX: not writeable |
90 if (!transport->type->methods.write) |
100 if (!transport->type->methods.write) |
91 return -1; |
101 return SET_ERROR(err, -1); |
92 |
102 |
93 // proxy off to method handler |
103 // proxy off to method handler |
94 if (transport->type->methods.write(transport, buf, &len, err)) |
104 if (transport->type->methods.write(transport, buf, &len, err)) |
95 return -ERROR_CODE(err); |
105 return -ERROR_CODE(err); |
96 |
106 |