新手上路
- 积分
- 31
- 金钱
- 31
- 注册时间
- 2015-1-14
- 在线时间
- 7 小时
|
30金钱
大佬们,小弟最近用ucos ii + lwip做tcp server。现在只是做一个简单的回传实验,一共创建两个任务,一个收一个发的,收的任务收到数据之后拷贝到发送buffer,给发的任务发一个信号量,但是一直卡死在netconn_accept里面。err一直是-3,也就是连接超时,调试软件那边连接的时候也显示1035 未知错误,有大佬遇到过这种情况么,小弟lwip新手,刚开始接触这个。下面是我的代码:
[mw_shl_code=c,false]void taskTcpServerRecv(void *data)
{
err_t err;
OS_CPU_SR cpu_sr;
uint32_t dataCount = 0;
newTcpServerDataReceivedSem = OSSemCreate(0);
OSEventNameSet(newTcpServerDataReceivedSem,"TcpServerDataReady",(INT8U *)&err);
struct netbuf *recvBuff;
tcpServerConn = netconn_new(NETCONN_TCP);
if(tcpServerConn)
{
err = netconn_bind(tcpServerConn,IP_ADDR_ANY,8088);
err = netconn_listen(tcpServerConn);
tcpServerConn->recv_timeout = 500;
for(;;)
{
err = netconn_accept(tcpServerConn,&newTcpServerConn);
if(err == ERR_OK)
{
newTcpServerConn->recv_timeout = 10;
for(;;)
{
err = netconn_recv(newTcpServerConn,&recvBuff);
if((err == ERR_OK) && (recvBuff != NULL))
{
OS_ENTER_CRITICAL();
memset(TCPServerBuff.rxBuffer,0,TCPServerBuff.rxBufferSize);
for(struct pbuf *q = recvBuff->p;q != NULL;q = q->next)
{
if(q->len > (TCPServerBuff.rxBufferSize - dataCount))
memcpy(TCPServerBuff.rxBuffer + dataCount,q->payload,(TCPServerBuff.rxBufferSize - dataCount));
else
memcpy(TCPServerBuff.rxBuffer + dataCount,q->payload,q->len);
dataCount += q->len;
if(dataCount > TCPServerBuff.rxBufferSize)
break;
}
OS_EXIT_CRITICAL();
TCPServerBuff.rxCount = dataCount;
dataCount=0;
netbuf_delete(recvBuff);
OSSemPost(newTcpServerDataReceivedSem);
}
else if(err == ERR_CLSD)
{
netconn_close(newTcpServerConn);
netconn_delete(newTcpServerConn);
break;
}
OSTimeDlyHMSM (0,0,0,10);
}
}
GPIOE->ODR ^= GPIO_Pin_15;
OSTimeDlyHMSM (0,0,0,500);
}
}
else
{
for(;;)
{
OSTimeDlyHMSM (0,0,0,10);
}
}
}
void taskTcpServerSend(void *data)
{
INT8U err;
for(;;)
{
OSSemPend(newTcpServerDataReceivedSem,0,&err);
memcpy((uint8_t *)TCPServerBuff.txBuffer,(uint8_t *)(TCPServerBuff.rxBuffer),TCPServerBuff.rxCount);
err = netconn_write(newTcpServerConn,(uint8_t *)TCPServerBuff.txBuffer,TCPServerBuff.rxCount, NETCONN_COPY);
TCPServerBuff.rxCount = 0;
OSTimeDlyHMSM (0,0,0,10);
}
}[/mw_shl_code]
|
-
-
调试软件截图
|