lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Is the pbuf_alloc usage correctly?


From: bingsen xie
Subject: [lwip-users] Is the pbuf_alloc usage correctly?
Date: Mon, 14 Jun 2004 22:17:32 +0800 (CST)

hello,every one!

I have use the lwip-0.7.1 with UCOS.I write an application with the UDP RAW API.

The program is list following. But my program cann't run stablly.
It seems that the pbuf_alloc cann't correcttly return.
Do you have the relative experience?Can you tell me?

//*******************************************************
//get a pbuf struct pointer matching with the size of data to be sent.
//and fill the pbuf with data
//************************

int prepare_pbuf(struct pbuf* psendata)
{
 struct pbuf* q;
 int nRet;
 char* ptr;
 char* data;
 
 long i;
 static char   data_buffer[UDP_SEND_PACKAGE_SIZE];
 nRet=0;

//Read my target send data
 nRet=ReadFromCache(data_buffer,UDP_SEND_PACKAGE_SIZE);
 
 if(nRet<=0) return -1; 
 
#ifdef __DEBUG 
 printf("the nRet is %d",nRet);
#endif __DEBUG

 psendata=pbuf_alloc(PBUF_ROM,nRet,PBUF_POOL);
 if(psendata==NULL) return -1;
 data=""> for(q = psendata; q != NULL; q = q->next)
 {      
  ptr=q->payload;
  for(i = 0; i <q->len;i++)
  {   
   *ptr++=*data++;   
  }    
 }
 return 0; 
}

//*******************************
//release the pbuf pointer
//*******************************
void release_pbuf(struct pbuf* pdata)
{
 pbuf_free(pdata);
}
//******************************
//send a lot of data to remote
//********************************
void voice_udp_sendout()
{
 struct udp_pcb * upcb_client;
 err_t err_code;
 char* ptr;  
 struct pbuf* psendata=NULL;
 IP4_ADDR(&g_udp_remote_ip,192,168,1,100);
 g_udp_remote_port=7;
 
 upcb_client=udp_new();
 if(upcb_client==NULL)
 {
  printf("client cann't create upcb\n");
  return ;
 }
 
 printf("good\n");
 g_udp_client_stop=0;


 if(udp_connect(upcb_client,&g_udp_remote_ip,g_udp_remote_port)!=ERR_OK) 
 {
  printf("cann't connect to remote server\n"); 
  return ;
 }  

 while(1)
 {      
  //sys_sem_wait(g_sem_getvoice);
  OSTimeDlyHMSM(0,0,0,5);
  
  printf("3\n");
  if(prepare_pbuf(psendata)!=0)
  {

// after some times successfully it will alway run into here!
//I think it is because I use pbuf_alloc error.But I don't know whu my
//usage about pbuf_alloc is error


   //printf("Cann't Get Data for Sending!\n");
   continue;
  }
  printf("4\n");
  
  
  err_code=udp_send(upcb_client,psendata);
  if(err_code==ERR_MEM)
    printf("Mem Error\n");
  else if(err_code==ERR_USE)
   printf("Error used\n");
  else printf("Send OK");
  
  release_pbuf(psendata);
  if(g_udp_client_stop==1)
  {
   udp_remove(upcb_client);
   OSTaskDel(OS_PRIO_SELF);
  }
 }
 
}

int voice_udp_client_init()
{   
 sys_thread_new(voice_udp_sendout, NULL,2);  
 return 0;
}



Do You Yahoo!?
嫌邮箱太小?雅虎电邮自助扩容!
reply via email to

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