lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: [lwip] problems with tcp_segs


From: Andrea Olivotto
Subject: [lwip-users] Re: [lwip] problems with tcp_segs
Date: Wed, 08 Jan 2003 23:56:01 -0000

06/05/02 21.03.23, James Roth <address@hidden> wrote:

>    What platform are you using?  Most of my problems where a result of 
>some time related bugs in my code, not lwip.  It turns out that 
>imprecise timing code in sys_arch can result it lots of oddball 
>problems.  To be specific, the pthread_condtimedwait on my system had an 
>early timeout bug.  This resulted in some timeout math going negative.

I'm using an 8051 plus Keil compiler, single thread enviroment.
I admit that using that platfor there are some porting problem, so I don't 
exclude the case one or more 
porting bugs.

This is some lines from my lwipopts.h:

#define MEM_SIZE                6000
#define MEMP_NUM_PBUF           16
#define MEMP_NUM_UDP_PCB        2
#define MEMP_NUM_TCP_PCB        10
#define MEMP_NUM_TCP_PCB_LISTEN 10
#define MEMP_NUM_TCP_SEG        48


This is my main loop:

  while(TRUE)
  {
      SHELL_Manager();

      if (bTCPTimerCoarse == TRUE)
      {
          tcp_slowtmr();
          bTCPTimerCoarse = FALSE;
      }
      else
      {
          if (bTCPTimerFine == TRUE)
          {
              tcp_fasttmr();
              bTCPTimerFine = FALSE;
          }
          else
          {
              if (bARPTimer == TRUE)
              {
                arp_tmr();
                bARPTimer = FALSE;
              }
          }
      }

      while (ethernetif_service())
      {
          ethernetif_input(ETHif);
      }

      LED_DEBUG_4 = ~LED_DEBUG_4;

      APPDEAMON();
  }
}


This is the tcpecho application:


void
tcpecho_init(void)
{
  struct tcp_pcb *pcb;

  DEBUGF(TCPECHO_DEBUG, ("tcpecho init\n"));

  pcb = tcp_new();
  tcp_bind(pcb, IP_ADDR_ANY, TCPECHO_PORT);
  pcb = tcp_listen(pcb);

  tcp_accept(pcb, &tcpecho_accept);
  tcp_poll(pcb, NULL, 0);
  tcp_arg(pcb, NULL);
  tcp_sent(pcb, NULL);
  tcp_err(pcb, NULL);
  tcp_recv(pcb, NULL);

  tcpecho_pcb = NULL;

  uiBufferIn = 0;
  uiBufferOut = 0;
  uiBufferCount = 0;
}

err_t
tcpecho_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
  DEBUGF(TUNSER_DEBUG, ("tcpecho accepf\n"));

  if (tcpecho_pcb == NULL)
  {
    tcp_err(pcb, &tcpecho_errf);
    tcp_recv(pcb, &tcpecho_recv);

    tcp_accept(pcb, NULL);

    tcpecho_pcb = pcb;

    return ERR_OK;
  }
  else
  {
    DEBUGF(TCPECHO_DEBUG, ("tcpecho already on\n"));

    return ERR_RST;
  }
}

err_t
tcpecho_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
  struct pbuf *q;
  BYTE XDATA *puPointer;
  UINT IDATA len, i;

  tcp_recved(pcb, p->tot_len);

  if ((p != NULL) && (err == ERR_OK))
  {

#ifdef TCPECHO_STATS
    stats.tcpecho.recv += p->tot_len;
#endif

    for(q = p; q != NULL; q = q->next)
    {
      puPointer = (BYTE XDATA *)q->payload;
      len = q->len;

      for(i=0; i<len; i++)
      {
        if (uiBufferCount<TCPECHO_LOCALBUFLEN)
        {
          puBuffer[uiBufferIn] = *puPointer++;
          uiBufferCount++;
          uiBufferIn++;
          if (uiBufferIn == TCPECHO_LOCALBUFLEN)
          {
            uiBufferIn = 0;
          }
        }
        else
        {
#ifdef TCPECHO_STATS
          stats.tcpecho.ovlerr++;
#endif
        }
      }
    }
  }
  else
  {
    tcp_close(pcb);
    tcpecho_pcb = NULL;
    uiBufferIn = 0;
    uiBufferOut = 0;
    uiBufferCount = 0;
  }

  pbuf_free(p);

  return ERR_OK;
}

void
tcpecho_errf(void *arg, err_t err)
{
  tcpecho_pcb = NULL;

  uiBufferIn = 0;
  uiBufferOut = 0;
  uiBufferCount = 0;
}

void
tcpecho_deamon(void)
{
  UINT IDATA len;
  UINT IDATA buf;
  UINT IDATA i;
  UINT IDATA j;
  err_t err;
  static BYTE XDATA puTxBuffer[1024];


  if (tcpecho_pcb != NULL)
  {
    if ((len = uiBufferCount) > 0)
    {
      buf = tcp_sndbuf(tcpecho_pcb);
      i = MIN(buf,len);
      if (i>0)
      {
        for(j=0; j<i; j++)
        {
          puTxBuffer[j] = puBuffer[uiBufferOut];
          uiBufferCount--;
          uiBufferOut++;
          if (uiBufferOut == TCPECHO_LOCALBUFLEN)
              uiBufferOut = 0;
        }
        err = tcp_write(tcpecho_pcb, puBuffer, i, 1);

#ifdef TCPECHO_STATS
        if (err == ERR_OK)
          stats.tcpecho.xmit += i;
        else
          stats.tcpecho.tcperr++;
#endif
      }
    }
  }
}



I suspect there is some unordered memp deallocation when tcp retransmission 
occur.
Thanks to anyone can help me.


Andrea







[This message was sent through the lwip discussion list.]




reply via email to

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