194 |
} |
} |
195 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
196 |
struct |
struct |
197 |
netconn *netconn_new(enum netconn_type t) |
netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto, |
198 |
|
void (*callback)(struct netconn *, enum netconn_evt, u16_t len)) |
199 |
{ |
{ |
200 |
struct netconn *conn; |
struct netconn *conn; |
201 |
struct api_msg *msg; |
struct api_msg *msg; |
218 |
conn->sem = SYS_SEM_NULL; |
conn->sem = SYS_SEM_NULL; |
219 |
conn->state = NETCONN_NONE; |
conn->state = NETCONN_NONE; |
220 |
conn->socket = 0; |
conn->socket = 0; |
221 |
conn->callback = 0; |
conn->callback = callback; |
222 |
conn->recv_avail = 0; |
conn->recv_avail = 0; |
223 |
|
|
224 |
if((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
if((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
227 |
} |
} |
228 |
|
|
229 |
msg->type = API_MSG_NEWCONN; |
msg->type = API_MSG_NEWCONN; |
230 |
|
msg->msg.msg.bc.port = proto; /* misusing the port field */ |
231 |
msg->msg.conn = conn; |
msg->msg.conn = conn; |
232 |
api_msg_post(msg); |
api_msg_post(msg); |
233 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
240 |
|
|
241 |
return conn; |
return conn; |
242 |
} |
} |
243 |
|
|
244 |
|
/*-----------------------------------------------------------------------------------*/ |
245 |
|
struct |
246 |
|
netconn *netconn_new(enum netconn_type t) |
247 |
|
{ |
248 |
|
return netconn_new_with_proto_and_callback(t,0,NULL); |
249 |
|
} |
250 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
251 |
struct |
struct |
252 |
netconn *netconn_new_with_callback(enum netconn_type t, |
netconn *netconn_new_with_callback(enum netconn_type t, |
253 |
void (*callback)(struct netconn *, enum netconn_evt, u16_t len)) |
void (*callback)(struct netconn *, enum netconn_evt, u16_t len)) |
254 |
{ |
{ |
255 |
struct netconn *conn; |
return netconn_new_with_proto_and_callback(t,0,callback); |
|
|
|
|
/* get a netconn and then initialize callback pointer and socket */ |
|
|
conn = netconn_new(t); |
|
|
if (conn) |
|
|
conn->callback = callback; |
|
|
return conn; |
|
256 |
} |
} |
257 |
|
|
258 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
321 |
u16_t *port) |
u16_t *port) |
322 |
{ |
{ |
323 |
switch (conn->type) { |
switch (conn->type) { |
324 |
|
case NETCONN_RAW: |
325 |
|
/* return an error as connecting is only a helper for upper layers */ |
326 |
|
return ERR_CONN; |
327 |
case NETCONN_UDPLITE: |
case NETCONN_UDPLITE: |
328 |
case NETCONN_UDPNOCHKSUM: |
case NETCONN_UDPNOCHKSUM: |
329 |
case NETCONN_UDP: |
case NETCONN_UDP: |
348 |
u16_t *port) |
u16_t *port) |
349 |
{ |
{ |
350 |
switch (conn->type) { |
switch (conn->type) { |
351 |
|
case NETCONN_RAW: |
352 |
|
*addr = &(conn->pcb.raw->local_ip); |
353 |
|
*port = conn->pcb.raw->protocol; |
354 |
|
break; |
355 |
case NETCONN_UDPLITE: |
case NETCONN_UDPLITE: |
356 |
case NETCONN_UDPNOCHKSUM: |
case NETCONN_UDPNOCHKSUM: |
357 |
case NETCONN_UDP: |
case NETCONN_UDP: |