/[lwip]/lwip/src/api/api_lib.c
ViewVC logotype

Diff of /lwip/src/api/api_lib.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by kieranm, Tue Jun 10 10:45:29 2003 UTC revision 1.17 by marcbou, Fri Jun 27 20:46:11 2003 UTC
# Line 44  netbuf *netbuf_new(void) Line 44  netbuf *netbuf_new(void)
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;
# Line 62  netbuf_delete(struct netbuf *buf) Line 62  netbuf_delete(struct netbuf *buf)
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  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
# Line 107  netbuf_chain(struct netbuf *head, struct Line 107  netbuf_chain(struct netbuf *head, struct
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
# Line 198  netconn *netconn_new(enum netconn_type t Line 198  netconn *netconn_new(enum netconn_type 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    }    }
# Line 206  netconn *netconn_new(enum netconn_type t Line 206  netconn *netconn_new(enum netconn_type t
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;
# Line 243  netconn_delete(struct netconn *conn) Line 243  netconn_delete(struct netconn *conn)
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        
# Line 251  netconn_delete(struct netconn *conn) Line 251  netconn_delete(struct netconn *conn)
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) {
# Line 353  netconn_bind(struct netconn *conn, struc Line 353  netconn_bind(struct netconn *conn, struc
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;
# Line 362  netconn_bind(struct netconn *conn, struc Line 362  netconn_bind(struct netconn *conn, struc
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    
# Line 384  netconn_connect(struct netconn *conn, st Line 384  netconn_connect(struct netconn *conn, st
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;
# Line 393  netconn_connect(struct netconn *conn, st Line 393  netconn_connect(struct netconn *conn, st
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    
# Line 406  netconn_disconnect(struct netconn *conn) Line 406  netconn_disconnect(struct netconn *conn)
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  }  }
# Line 434  netconn_listen(struct netconn *conn) Line 434  netconn_listen(struct netconn *conn)
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  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
# Line 490  netconn_recv(struct netconn *conn) Line 490  netconn_recv(struct netconn *conn)
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;
# Line 514  netconn_recv(struct netconn *conn) Line 514  netconn_recv(struct netconn *conn)
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;
# Line 526  netconn_recv(struct netconn *conn) Line 526  netconn_recv(struct netconn *conn)
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      }      }
# Line 540  netconn_recv(struct netconn *conn) Line 540  netconn_recv(struct netconn *conn)
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;
# Line 571  netconn_send(struct netconn *conn, struc Line 571  netconn_send(struct netconn *conn, struc
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    
# Line 582  netconn_send(struct netconn *conn, struc Line 582  netconn_send(struct netconn *conn, struc
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  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
# Line 607  netconn_write(struct netconn *conn, void Line 607  netconn_write(struct netconn *conn, void
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;
# Line 652  netconn_write(struct netconn *conn, void Line 652  netconn_write(struct netconn *conn, void
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);
# Line 670  netconn_close(struct netconn *conn) Line 670  netconn_close(struct netconn *conn)
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    
# Line 686  netconn_close(struct netconn *conn) Line 686  netconn_close(struct netconn *conn)
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  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26