44 |
{ |
{ |
45 |
struct netbuf *buf; |
struct netbuf *buf; |
46 |
|
|
47 |
buf = memp_mallocp(MEMP_NETBUF); |
buf = memp_malloc(MEMP_NETBUF); |
48 |
if (buf != NULL) { |
if (buf != NULL) { |
49 |
buf->p = NULL; |
buf->p = NULL; |
50 |
buf->ptr = NULL; |
buf->ptr = NULL; |
62 |
pbuf_free(buf->p); |
pbuf_free(buf->p); |
63 |
buf->p = buf->ptr = NULL; |
buf->p = buf->ptr = NULL; |
64 |
} |
} |
65 |
memp_freep(MEMP_NETBUF, buf); |
memp_free(MEMP_NETBUF, buf); |
66 |
} |
} |
67 |
} |
} |
68 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
107 |
{ |
{ |
108 |
pbuf_chain(head->p, tail->p); |
pbuf_chain(head->p, tail->p); |
109 |
head->ptr = head->p; |
head->ptr = head->p; |
110 |
memp_freep(MEMP_NETBUF, tail); |
memp_free(MEMP_NETBUF, tail); |
111 |
} |
} |
112 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
113 |
u16_t |
u16_t |
198 |
{ |
{ |
199 |
struct netconn *conn; |
struct netconn *conn; |
200 |
|
|
201 |
conn = memp_mallocp(MEMP_NETCONN); |
conn = memp_malloc(MEMP_NETCONN); |
202 |
if (conn == NULL) { |
if (conn == NULL) { |
203 |
return NULL; |
return NULL; |
204 |
} |
} |
206 |
conn->pcb.tcp = NULL; |
conn->pcb.tcp = NULL; |
207 |
|
|
208 |
if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) { |
if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) { |
209 |
memp_freep(MEMP_NETCONN, conn); |
memp_free(MEMP_NETCONN, conn); |
210 |
return NULL; |
return NULL; |
211 |
} |
} |
212 |
conn->recvmbox = SYS_MBOX_NULL; |
conn->recvmbox = SYS_MBOX_NULL; |
243 |
return ERR_OK; |
return ERR_OK; |
244 |
} |
} |
245 |
|
|
246 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
247 |
return ERR_MEM; |
return ERR_MEM; |
248 |
} |
} |
249 |
|
|
251 |
msg->msg.conn = conn; |
msg->msg.conn = conn; |
252 |
api_msg_post(msg); |
api_msg_post(msg); |
253 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
254 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
255 |
|
|
256 |
/* Drain the recvmbox. */ |
/* Drain the recvmbox. */ |
257 |
if (conn->recvmbox != SYS_MBOX_NULL) { |
if (conn->recvmbox != SYS_MBOX_NULL) { |
353 |
} |
} |
354 |
} |
} |
355 |
|
|
356 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
357 |
return (conn->err = ERR_MEM); |
return (conn->err = ERR_MEM); |
358 |
} |
} |
359 |
msg->type = API_MSG_BIND; |
msg->type = API_MSG_BIND; |
362 |
msg->msg.msg.bc.port = port; |
msg->msg.msg.bc.port = port; |
363 |
api_msg_post(msg); |
api_msg_post(msg); |
364 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
365 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
366 |
return conn->err; |
return conn->err; |
367 |
} |
} |
368 |
|
|
384 |
} |
} |
385 |
} |
} |
386 |
|
|
387 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
388 |
return ERR_MEM; |
return ERR_MEM; |
389 |
} |
} |
390 |
msg->type = API_MSG_CONNECT; |
msg->type = API_MSG_CONNECT; |
393 |
msg->msg.msg.bc.port = port; |
msg->msg.msg.bc.port = port; |
394 |
api_msg_post(msg); |
api_msg_post(msg); |
395 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
396 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
397 |
return conn->err; |
return conn->err; |
398 |
} |
} |
399 |
|
|
406 |
return ERR_VAL; |
return ERR_VAL; |
407 |
} |
} |
408 |
|
|
409 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
410 |
return ERR_MEM; |
return ERR_MEM; |
411 |
} |
} |
412 |
msg->type = API_MSG_DISCONNECT; |
msg->type = API_MSG_DISCONNECT; |
413 |
msg->msg.conn = conn; |
msg->msg.conn = conn; |
414 |
api_msg_post(msg); |
api_msg_post(msg); |
415 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
416 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
417 |
return conn->err; |
return conn->err; |
418 |
|
|
419 |
} |
} |
434 |
} |
} |
435 |
} |
} |
436 |
|
|
437 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
438 |
return (conn->err = ERR_MEM); |
return (conn->err = ERR_MEM); |
439 |
} |
} |
440 |
msg->type = API_MSG_LISTEN; |
msg->type = API_MSG_LISTEN; |
441 |
msg->msg.conn = conn; |
msg->msg.conn = conn; |
442 |
api_msg_post(msg); |
api_msg_post(msg); |
443 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
444 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
445 |
return conn->err; |
return conn->err; |
446 |
} |
} |
447 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
490 |
} |
} |
491 |
|
|
492 |
|
|
493 |
buf = memp_mallocp(MEMP_NETBUF); |
buf = memp_malloc(MEMP_NETBUF); |
494 |
|
|
495 |
if (buf == NULL) { |
if (buf == NULL) { |
496 |
conn->err = ERR_MEM; |
conn->err = ERR_MEM; |
514 |
/* If we are closed, we indicate that we no longer wish to receive |
/* If we are closed, we indicate that we no longer wish to receive |
515 |
data by setting conn->recvmbox to SYS_MBOX_NULL. */ |
data by setting conn->recvmbox to SYS_MBOX_NULL. */ |
516 |
if (p == NULL) { |
if (p == NULL) { |
517 |
memp_freep(MEMP_NETBUF, buf); |
memp_free(MEMP_NETBUF, buf); |
518 |
sys_mbox_free(conn->recvmbox); |
sys_mbox_free(conn->recvmbox); |
519 |
conn->recvmbox = SYS_MBOX_NULL; |
conn->recvmbox = SYS_MBOX_NULL; |
520 |
return NULL; |
return NULL; |
526 |
buf->fromaddr = NULL; |
buf->fromaddr = NULL; |
527 |
|
|
528 |
/* Let the stack know that we have taken the data. */ |
/* Let the stack know that we have taken the data. */ |
529 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
530 |
conn->err = ERR_MEM; |
conn->err = ERR_MEM; |
531 |
return buf; |
return buf; |
532 |
} |
} |
540 |
api_msg_post(msg); |
api_msg_post(msg); |
541 |
|
|
542 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
543 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
544 |
} else { |
} else { |
545 |
sys_mbox_fetch(conn->recvmbox, (void **)&buf); |
sys_mbox_fetch(conn->recvmbox, (void **)&buf); |
546 |
conn->recv_avail -= buf->p->tot_len; |
conn->recv_avail -= buf->p->tot_len; |
571 |
return conn->err; |
return conn->err; |
572 |
} |
} |
573 |
|
|
574 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
575 |
return (conn->err = ERR_MEM); |
return (conn->err = ERR_MEM); |
576 |
} |
} |
577 |
|
|
582 |
api_msg_post(msg); |
api_msg_post(msg); |
583 |
|
|
584 |
sys_mbox_fetch(conn->mbox, NULL); |
sys_mbox_fetch(conn->mbox, NULL); |
585 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
586 |
return conn->err; |
return conn->err; |
587 |
} |
} |
588 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
607 |
} |
} |
608 |
} |
} |
609 |
|
|
610 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
611 |
return (conn->err = ERR_MEM); |
return (conn->err = ERR_MEM); |
612 |
} |
} |
613 |
msg->type = API_MSG_WRITE; |
msg->type = API_MSG_WRITE; |
652 |
} |
} |
653 |
} |
} |
654 |
ret: |
ret: |
655 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
656 |
conn->state = NETCONN_NONE; |
conn->state = NETCONN_NONE; |
657 |
if (conn->sem != SYS_SEM_NULL) { |
if (conn->sem != SYS_SEM_NULL) { |
658 |
sys_sem_free(conn->sem); |
sys_sem_free(conn->sem); |
670 |
if (conn == NULL) { |
if (conn == NULL) { |
671 |
return ERR_VAL; |
return ERR_VAL; |
672 |
} |
} |
673 |
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { |
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { |
674 |
return (conn->err = ERR_MEM); |
return (conn->err = ERR_MEM); |
675 |
} |
} |
676 |
|
|
686 |
goto again; |
goto again; |
687 |
} |
} |
688 |
conn->state = NETCONN_NONE; |
conn->state = NETCONN_NONE; |
689 |
memp_freep(MEMP_API_MSG, msg); |
memp_free(MEMP_API_MSG, msg); |
690 |
return conn->err; |
return conn->err; |
691 |
} |
} |
692 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |