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

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

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

revision 1.10 by jani, Fri Feb 21 16:43:46 2003 UTC revision 1.11 by jani, Fri Mar 21 10:48:21 2003 UTC
# Line 37  Line 37 
37  #include "lwip/sys.h"  #include "lwip/sys.h"
38  #include "lwip/tcpip.h"  #include "lwip/tcpip.h"
39    
 /*-----------------------------------------------------------------------------------*/  
 static err_t  
 recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)  
 {  
   struct netconn *conn;  
   u16_t len;  
     
   conn = arg;  
   
   if(conn == NULL) {  
     pbuf_free(p);  
     return ERR_VAL;  
   }  
   
   if(conn->recvmbox != SYS_MBOX_NULL) {  
             
     conn->err = err;  
     if (p != NULL) {  
         len = p->tot_len;  
         conn->recv_avail += len;  
     }  
     else  
         len = 0;  
     /* Register event with callback */  
     if (conn->callback)  
         (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, len);  
     sys_mbox_post(conn->recvmbox, p);  
   }    
   return ERR_OK;  
 }  
 /*-----------------------------------------------------------------------------------*/  
40  #if LWIP_UDP  #if LWIP_UDP
41  static void  static void
42  recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,  recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
# Line 102  recv_udp(void *arg, struct udp_pcb *pcb, Line 71  recv_udp(void *arg, struct udp_pcb *pcb,
71    }    }
72  }  }
73  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
74    #if LWIP_TCP
75    /*-----------------------------------------------------------------------------------*/
76    static err_t
77    recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
78    {
79      struct netconn *conn;
80      u16_t len;
81      
82      conn = arg;
83    
84      if(conn == NULL) {
85        pbuf_free(p);
86        return ERR_VAL;
87      }
88    
89      if(conn->recvmbox != SYS_MBOX_NULL) {
90              
91        conn->err = err;
92        if (p != NULL) {
93            len = p->tot_len;
94            conn->recv_avail += len;
95        }
96        else
97            len = 0;
98        /* Register event with callback */
99        if (conn->callback)
100            (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, len);
101        sys_mbox_post(conn->recvmbox, p);
102      }  
103      return ERR_OK;
104    }
105    
106  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
107  static err_t  static err_t
108  poll_tcp(void *arg, struct tcp_pcb *pcb)  poll_tcp(void *arg, struct tcp_pcb *pcb)
# Line 232  accept_function(void *arg, struct tcp_pc Line 233  accept_function(void *arg, struct tcp_pc
233    sys_mbox_post(mbox, newconn);    sys_mbox_post(mbox, newconn);
234    return ERR_OK;    return ERR_OK;
235  }  }
236    #endif /* LWIP_TCP */
237  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
238  static void  static void
239  do_newconn(struct api_msg_msg *msg)  do_newconn(struct api_msg_msg *msg)
# Line 253  do_delconn(struct api_msg_msg *msg) Line 255  do_delconn(struct api_msg_msg *msg)
255        udp_remove(msg->conn->pcb.udp);        udp_remove(msg->conn->pcb.udp);
256        break;        break;
257  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
258    #if LWIP_TCP      
259      case NETCONN_TCP:      case NETCONN_TCP:
260        if(msg->conn->pcb.tcp->state == LISTEN) {        if(msg->conn->pcb.tcp->state == LISTEN) {
261          tcp_accept(msg->conn->pcb.tcp, NULL);            tcp_accept(msg->conn->pcb.tcp, NULL);  
# Line 267  do_delconn(struct api_msg_msg *msg) Line 270  do_delconn(struct api_msg_msg *msg)
270            tcp_abort(msg->conn->pcb.tcp);            tcp_abort(msg->conn->pcb.tcp);
271          }          }
272        }        }
273    #endif
274        default:  
275      break;      break;
276      }      }
277    }    }
# Line 303  do_bind(struct api_msg_msg *msg) Line 308  do_bind(struct api_msg_msg *msg)
308        udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);        udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
309        break;        break;
310  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
311    #if LWIP_TCP      
312      case NETCONN_TCP:      case NETCONN_TCP:
313        msg->conn->pcb.tcp = tcp_new();        msg->conn->pcb.tcp = tcp_new();
314        setup_tcp(msg->conn);        setup_tcp(msg->conn);
315        break;  #endif /* LWIP_TCP */
316        default:  
317        break;
318      }      }
319    }    }
320    switch(msg->conn->type) {    switch(msg->conn->type) {
# Line 319  do_bind(struct api_msg_msg *msg) Line 327  do_bind(struct api_msg_msg *msg)
327      msg->conn->err = udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);      msg->conn->err = udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
328      break;      break;
329  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
330    #if LWIP_TCP
331    case NETCONN_TCP:    case NETCONN_TCP:
332      msg->conn->err = tcp_bind(msg->conn->pcb.tcp,      msg->conn->err = tcp_bind(msg->conn->pcb.tcp,
333                                msg->msg.bc.ipaddr, msg->msg.bc.port);                                msg->msg.bc.ipaddr, msg->msg.bc.port);
334    #endif /* LWIP_TCP */
335      default:
336      break;      break;
337    }    }
338    sys_mbox_post(msg->conn->mbox, NULL);    sys_mbox_post(msg->conn->mbox, NULL);
339  }  }
340    #if LWIP_TCP
341  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
342  static err_t  static err_t
343  do_connected(void *arg, struct tcp_pcb *pcb, err_t err)  do_connected(void *arg, struct tcp_pcb *pcb, err_t err)
# Line 339  do_connected(void *arg, struct tcp_pcb * Line 351  do_connected(void *arg, struct tcp_pcb *
351    }    }
352        
353    conn->err = err;    conn->err = err;
   
354    if(conn->type == NETCONN_TCP && err == ERR_OK) {    if(conn->type == NETCONN_TCP && err == ERR_OK) {
355      setup_tcp(conn);      setup_tcp(conn);
356    }        }    
     
357    sys_mbox_post(conn->mbox, NULL);    sys_mbox_post(conn->mbox, NULL);
358    return ERR_OK;    return ERR_OK;
359  }  }
360    #endif  
361  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
362  static void  static void
363  do_connect(struct api_msg_msg *msg)  do_connect(struct api_msg_msg *msg)
# Line 384  do_connect(struct api_msg_msg *msg) Line 395  do_connect(struct api_msg_msg *msg)
395        udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);        udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
396        break;        break;
397  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
398    #if LWIP_TCP      
399      case NETCONN_TCP:      case NETCONN_TCP:
400        msg->conn->pcb.tcp = tcp_new();              msg->conn->pcb.tcp = tcp_new();      
401        if(msg->conn->pcb.tcp == NULL) {        if(msg->conn->pcb.tcp == NULL) {
# Line 391  do_connect(struct api_msg_msg *msg) Line 403  do_connect(struct api_msg_msg *msg)
403          sys_mbox_post(msg->conn->mbox, NULL);          sys_mbox_post(msg->conn->mbox, NULL);
404          return;          return;
405        }        }
406    #endif
407        default:
408        break;        break;
409      }      }
410    }    }
# Line 405  do_connect(struct api_msg_msg *msg) Line 419  do_connect(struct api_msg_msg *msg)
419      sys_mbox_post(msg->conn->mbox, NULL);      sys_mbox_post(msg->conn->mbox, NULL);
420      break;      break;
421  #endif  #endif
422    #if LWIP_TCP      
423    case NETCONN_TCP:    case NETCONN_TCP:
424      /*    tcp_arg(msg->conn->pcb.tcp, msg->conn);*/      /*    tcp_arg(msg->conn->pcb.tcp, msg->conn);*/
425      setup_tcp(msg->conn);      setup_tcp(msg->conn);
426      tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port,      tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port,
427                  do_connected);                  do_connected);
428      /*tcp_output(msg->conn->pcb.tcp);*/      /*tcp_output(msg->conn->pcb.tcp);*/
429    #endif
430      default:
431      break;      break;
432    }    }
433  }  }
# Line 450  do_listen(struct api_msg_msg *msg) Line 467  do_listen(struct api_msg_msg *msg)
467        DEBUGF(API_MSG_DEBUG, ("api_msg: listen UDP: cannot listen for UDP.\n"));        DEBUGF(API_MSG_DEBUG, ("api_msg: listen UDP: cannot listen for UDP.\n"));
468        break;        break;
469  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
470    #if LWIP_TCP      
471      case NETCONN_TCP:      case NETCONN_TCP:
472        msg->conn->pcb.tcp = tcp_listen(msg->conn->pcb.tcp);        msg->conn->pcb.tcp = tcp_listen(msg->conn->pcb.tcp);
473        if(msg->conn->pcb.tcp == NULL) {        if(msg->conn->pcb.tcp == NULL) {
# Line 465  do_listen(struct api_msg_msg *msg) Line 483  do_listen(struct api_msg_msg *msg)
483          tcp_arg(msg->conn->pcb.tcp, msg->conn);          tcp_arg(msg->conn->pcb.tcp, msg->conn);
484          tcp_accept(msg->conn->pcb.tcp, accept_function);          tcp_accept(msg->conn->pcb.tcp, accept_function);
485        }        }
486    #endif
487        default:
488        break;        break;
489      }      }
490    }    }
# Line 515  do_send(struct api_msg_msg *msg) Line 535  do_send(struct api_msg_msg *msg)
535  static void  static void
536  do_recv(struct api_msg_msg *msg)  do_recv(struct api_msg_msg *msg)
537  {  {
538    #if LWIP_TCP
539    if(msg->conn->pcb.tcp != NULL) {    if(msg->conn->pcb.tcp != NULL) {
540      if(msg->conn->type == NETCONN_TCP) {      if(msg->conn->type == NETCONN_TCP) {
541        tcp_recved(msg->conn->pcb.tcp, msg->msg.len);        tcp_recved(msg->conn->pcb.tcp, msg->msg.len);
542      }      }
543    }    }
544    #endif  
545    sys_mbox_post(msg->conn->mbox, NULL);    sys_mbox_post(msg->conn->mbox, NULL);
546  }  }
547  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
548  static void  static void
549  do_write(struct api_msg_msg *msg)  do_write(struct api_msg_msg *msg)
550  {  {
551    #if LWIP_TCP    
552    err_t err;    err_t err;
553    #endif  
554    if(msg->conn->pcb.tcp != NULL) {    if(msg->conn->pcb.tcp != NULL) {
555      switch(msg->conn->type) {      switch(msg->conn->type) {
556  #if LWIP_UDP  #if LWIP_UDP
# Line 538  do_write(struct api_msg_msg *msg) Line 562  do_write(struct api_msg_msg *msg)
562        msg->conn->err = ERR_VAL;        msg->conn->err = ERR_VAL;
563        break;        break;
564  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
565    #if LWIP_TCP
566      case NETCONN_TCP:            case NETCONN_TCP:      
567        err = tcp_write(msg->conn->pcb.tcp, msg->msg.w.dataptr,        err = tcp_write(msg->conn->pcb.tcp, msg->msg.w.dataptr,
568                        msg->msg.w.len, msg->msg.w.copy);                        msg->msg.w.len, msg->msg.w.copy);
# Line 555  do_write(struct api_msg_msg *msg) Line 580  do_write(struct api_msg_msg *msg)
580                if (tcp_sndbuf(msg->conn->pcb.tcp) <= TCP_SNDLOWAT)                if (tcp_sndbuf(msg->conn->pcb.tcp) <= TCP_SNDLOWAT)
581                    (*msg->conn->callback)(msg->conn, NETCONN_EVT_SENDMINUS, msg->msg.w.len);                    (*msg->conn->callback)(msg->conn, NETCONN_EVT_SENDMINUS, msg->msg.w.len);
582            }            }
583    #endif
584        default:
585        break;        break;
586      }      }
587    }    }
# Line 578  do_close(struct api_msg_msg *msg) Line 605  do_close(struct api_msg_msg *msg)
605      case NETCONN_UDP:      case NETCONN_UDP:
606        break;        break;
607  #endif /* LWIP_UDP */  #endif /* LWIP_UDP */
608    #if LWIP_TCP
609      case NETCONN_TCP:      case NETCONN_TCP:
610        if(msg->conn->pcb.tcp->state == LISTEN) {        if(msg->conn->pcb.tcp->state == LISTEN) {
611          err = tcp_close(msg->conn->pcb.tcp);          err = tcp_close(msg->conn->pcb.tcp);
612        }        }
613        msg->conn->err = err;              msg->conn->err = err;      
614    #endif
615        default:      
616        break;        break;
617      }      }
618    }    }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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