调用ndk_1_94_1\packages\ti\ndk\inc\socket.h中的fdselect函数,函数原型如下:
Int fdSelect( int width, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout );这个fdselect用在判断socket是否准备好的函数里,函数原型如下:
//sock是否准备好
//nRW:0为可读、1为可写
#define SOCKET_ERROR
-1
int commSockIsReady(SOCKET sock, UINT32 nTimeOut, UINT8 nRW)//这里nRW为0
{
int res;
fd_set fds;
int nStatus;
struct sockaddr_in destAddr;
struct timeval timeout;
timeout.tv_sec = nTimeOut/1000;
timeout.tv_usec = (nTimeOut%1000)*1000;
//timeout = {1, 0};
FD_ZERO(&fds);
FD_SET(sock, &fds);
if(nRW == 1)
nStatus = fdSelect(0, NULL, &fds, NULL, &timeout);
else if(nRW == 0)
nStatus = fdSelect(0, &fds, NULL, NULL, &timeout); //
else
assert(FALSE);
if(SOCKET_ERROR == nStatus)
{
res = fdError();
return SOCKET_ERROR;
}
if(0 == nStatus)
{
res = fdError();
return -2;
}
return 0;
}
IGMPTestGroup(BytePtrToUINT32(pIP), 0); //CCS3.3使用的NDK组播函数
IGMPJoinHostGroup(BytePtrToUINT32(pIP), 0); //CCS3.1使用的NDK组播函数
遇到的问题是fdSelect的返回值是0,导致commSockIsReady()返回值不正常 |