lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] tcpecho & udpecho thread trouble


From: Wizard Kevid
Subject: [lwip-users] tcpecho & udpecho thread trouble
Date: Fri, 26 May 2006 16:04:35 +0800

Hello lwip-users,
 
Now I'm porting LwIP (1.1.1) to uC/OS (2.76) platform.
My trouble is that tcpecho thread can not work when udpecho thread is running too(udpecho thread can work).
Only start tcpecho thread is ok.
 
My source code is as below:
 
1. LwIP initialization task:
#ifdef STATS
 stats_init();
#endif
 
// system init
 sys_init();
 mem_init();
 memp_init();
 pbuf_init();
 
// tcp/ip init
 netif_init();
 sem = sys_sem_new(0);
 tcpip_init(tcpip_init_done, &sem);
 sys_sem_wait(sem);
 sys_sem_free(sem);
 
// add ne2k if
 IP4_ADDR(&ipaddr, 192,168,18,104);
 IP4_ADDR(&netmask, 255,255,255,0);
 IP4_ADDR(&gw, 192,168,18,2);
 
 netif_add(&ne2k_if, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);
 netif_set_default(&ne2k_if);
 netif_set_up(&ne2k_if);
 
 tcpecho_init();
 udpecho_init();

2. TCP echo task:
static void
tcpecho_thread(void *arg)
{
  struct netconn *conn, *newconn;
  err_t err;
 
  /* SOCKET: Create a new connection identifier (i.e. a socket). */
  conn = netconn_new(NETCONN_TCP);
 
  /* BIND: Bind connection to the desired port number 7. */
  netconn_bind(conn, NULL, 7);
 
  /* LISTEN: Tell the connection to go into listening mode. */
  netconn_listen(conn);
 
  /* Enter the main connection request processing loop */
  while(1) {
 
    /* ACCEPT: Block here until a connection request is received */
    /* Any connection request will be handled using a new temporary socket */
    /* Grab new connection. */
    newconn = netconn_accept(conn);
 
    /* Process the buffers that are received over the new connection. */
    if(newconn != NULL) {
      struct netbuf *buf;
      void *data;
      u16_t len;
     
      /* RECEIVE: Enter a while loop that processes any received buffers */
      while((buf = netconn_recv(newconn)) != NULL)
      {
         do {
         /* Retrieve the data and data_length from the received data buffer */
         netbuf_data(buf, &data, &len);
         /* SEND: Echo the data buffer back to the sender */
         err = netconn_write(newconn, data, len, NETCONN_COPY);
         if(err != ERR_OK) {
         /*   printf("tcpecho: netconn_write: error \"%s\"\n", lwip_strerr(err));*/
              }
         } while(netbuf_next(buf) >= 0);
         netbuf_delete(buf);
      } /* end while */
      /*printf("Got EOF, looping\n");*/
      /* Close connection and discard connection identifier. */
      netconn_delete(newconn);
    }
  }
}

3. UDP echo task:
static void
udpecho_thread(void *arg)
{
 struct netconn *conn;
 struct netbuf *buf;
 struct ip_addr *server_addr;
 u16_t server_port;
 
 /* create a new connection */
 conn = netconn_new(NETCONN_UDP);
 
 /* BIND: Bind connection to the desired port number 2006. */
 netconn_bind(conn, NULL, 2006);
 
 while(1)
 {
  /* RECEIVE: Enter a while loop that processes any received buffers */
  buf = netconn_recv(conn);
  server_addr = netbuf_fromaddr(buf);
  server_port = netbuf_fromport(buf);
  /* connect the connection to the remote host */
  netconn_connect(conn, server_addr, server_port);
  /* send the data */
  netconn_send(conn, buf);
  /* deallocate netbuf */
  netbuf_delete(buf);
 }
 /* deallocate connection */
 netconn_delete(conn);
}

Did you meet the same trouble as me?
Who can help me out?
 
Sincerely,

Wizard Kevid
address@hidden
2006-05-26




reply via email to

[Prev in Thread] Current Thread [Next in Thread]