|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2009-12-28 19:47:58
|
显示全部楼层
整个代码就不放上来了,因为是公司的产品,里面已经添加了很多的驱动和应用,避免纠纷
如果对lwip和UCOSII的移植什么想共同研究的话,可以加我GTALK,yuqinjuve@gmail.com(或者直接发邮件也可)
可以把移植部分的代码及个人的理解分享。
其实我也是个菜鸟。
select的应用,我的应用是注释掉的那段,因为要测试移植的稳定性,所以我先注释掉测试了
int ret;
int sockFd = -1;
int connectFd = -1;
volatile int maxFd;
int opt;
uint32 len;
int tcpPort = 7777;
int recvNum;
int sendNum;
struct sockaddr_in svrAddr,cltAddr;
fd_set rfds;
fd_set wfds;
struct timeval timeOut;
parg = parg;
timeOut.tv_sec = 5;
timeOut.tv_usec = 0;
svrAddr.sin_family = AF_INET;
svrAddr.sin_port = htons(tcpPort);
svrAddr.sin_addr.s_addr = htons(INADDR_ANY);
while (1)
{
sockFd = socket( AF_INET, SOCK_STREAM, 0 );
if ( sockFd < 0 )
{
continue;
}
ret = bind( sockFd, (struct sockaddr *)&svrAddr, sizeof(svrAddr) );
if ( ret < 0 )
{
lwip_close(sockFd);
sockFd = -1;
continue;
}
ret = listen( sockFd, 1 );
if ( ret < 0 )
{
lwip_close(sockFd);
continue;
}
len = sizeof(cltAddr);
connectFd = accept( sockFd, (struct sockaddr *)&cltAddr, &len );
if ( -1 != connectFd )
{
opt = 1;
send( connectFd, "Start TCP Server\r", 17, 0 );
}
maxFd = connectFd;
while (-1 != connectFd)
{
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_SET( connectFd, &rfds );
FD_SET( connectFd, &wfds );
//maxFd = connectFd;
recvNum = recv( connectFd, tcpBuf, 20, 0 );
if ( recvNum <= 0 )
{
lwip_close(connectFd);
connectFd = -1;
break;
}
sendNum = send( connectFd, tcpBuf, 20, 0 );
OSTimeDly(100);
/*ret = lwip_select( connectFd+1, &rfds, NULL, NULL, &timeOut );
if ( ret < 0 )
{
lwip_close(connectFd);
connectFd = -1;
break;
}
else if ( 0 == ret )
{
continue;
}
else
{
if ( FD_ISSET( connectFd, &rfds ) )
{
recvNum = recv( connectFd, tcpBuf, 20, 0 );
if ( recvNum <= 0 )
{
lwip_close(connectFd);
connectFd = -1;
break;
}
}
}*/
}
lwip_close(sockFd);
sockFd = -1;
}
} |
|