lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] about TCP Send function problem


From: xcb
Subject: [lwip-users] about TCP Send function problem
Date: Thu, 28 Jul 2005 11:18:19 +0800

lwip-users      i use lwip 1.0+ucos, and Create a client TCP socket to connect 
server run in window system,send and recv data.I found a problem about send 
function, when client send more data(10 packets) to server at one time ,it 
sometimes happen that send() funtion will wait very long time to return,even 
not return,i trace the code execute,found this phenomenon:

tcp send() 
->netconn_write()->do_write()->tcp_write()->tcp_enqueue()->tcp_output();

my opt.h about SND_QUEUELEN define that
/* TCP Maximum segment size. */
#ifndef TCP_MSS
#define TCP_MSS                         1280 /* A *very* conservative default. 
*/
#endif

/* TCP sender buffer space (bytes). */
#ifndef TCP_SND_BUF
#define TCP_SND_BUF                     2560 
#endif

/* TCP sender buffer space (pbufs). This must be at least = 2 *
   TCP_SND_BUF/TCP_MSS for things to work. */
#ifndef TCP_SND_QUEUELEN
#define TCP_SND_QUEUELEN                5 * TCP_SND_BUF/TCP_MSS
#endif

TCP_SND_QUEUELEN = 5*2 = 10;

client send more data to server at one time, 
tcp_enqueue() will often return ERR_MEM;
        queuelen = pcb->snd_queuelen;
  if (queuelen >= TCP_SND_QUEUELEN) {
    LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_enqueue: too long queue %u (max 
%u)\n", queuelen, TCP_SND_QUEUELEN));
    goto memerr;
  }

and then netconn_write() function will wait (conn->err==OK) ,sometime it will 
wait long time,even not return (conn->err==OK),so netconn_write() will not 
return,it have add a count to break the while() ,can i solve the problem???
 while (conn->err == ERR_OK && size > 0) {
    msg->msg.msg.w.dataptr = dataptr;
    msg->msg.msg.w.copy = copy;
    
    if (conn->type == NETCONN_TCP) {
      if (tcp_sndbuf(conn->pcb.tcp) == 0) {
  sys_sem_wait(conn->sem);
  if (conn->err != ERR_OK) {
    goto ret;
  }
      }
      if (size > tcp_sndbuf(conn->pcb.tcp)) {
  /* We cannot send more than one send buffer's worth of data at a
     time. */
  len = tcp_sndbuf(conn->pcb.tcp);
      } else {
  len = size;
      }
    } else {
      len = size;
    }
    
    LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_write: writing %d bytes (%d)\n", len, 
copy));
    msg->msg.msg.w.len = len;
    api_msg_post(msg);
    sys_mbox_fetch(conn->mbox, NULL);    
    if (conn->err == ERR_OK) {
      dataptr = (void *)((char *)dataptr + len);
      size -= len;
    } else if (conn->err == ERR_MEM) {
      conn->err = ERR_OK;
      sys_sem_wait(conn->sem);
          nErrCnt++;                            /////////////////////////////i 
add this count to break the while();
          if(nErrCnt>5) 
                  goto ret;
    } else {
      goto ret;
    }
  }

help me to solve this problem.thank you.










reply via email to

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