Pocket PC Networking >> Select socket call having problems?

by S3J1bmFsIERvc2hp » Mon, 11 Apr 2005 08:29:02 GMT

Hello,

I am using evc++ 4.0, PPC - Dell Axim X30, Windows CE.Net 4.2.
I am trying the following select() function call and it fails with a error
10014. It succeeds most of the times but fails some times. Has anyone come
across this...any help will be highly appreciated.

FD_ZERO(read_fds);
FD_ZERO(write_fds);

//Following function initializes FDS within read_fds and write_fds-
depending on certain conditions
LOCK(&channels_lock);
max_fd = mark_fds(ive, read_fds, write_fds);
UNLOCK(&channels_lock);

memset(&timeout, 0, sizeof(timeout));
timeout.tv_sec = 10;
timeout.tv_usec = 0;

ret = select(max_fd + 1, read_fds, write_fds, NULL, &timeout);

if (ret == SOCKET_ERROR) {
int sockErr = WSAGetLastError();
NCP_DEBUG0("select failed. Error %d", sockErr); //prints error as
10014
return -1;
}

Krunal


Similar Threads

1. Unreliable: Networkstream.DataAvailable, Socket.Available, Socket.Poll, Socket.Select

2. Having problem calling NetUserSetInfo with level 1005.

3. select() not return socket error after pocket pc unplugged from cr

Hi, select() method is supposed to return the current socket state, so that 
the app can find out whether a socket connection is still valid. However, 
when testing on pocket pc with activeSync connection, after a socket is 
connected, even if unplugging the device from cradle, the following calling 
of selec() method will not get an exception for this socket. Instead, 
select() still 
returns that the socket is still writable.

The following is the code snippet for the test, first calling 
OnBnClickedConnect(), then unplug the device from the cradle, and then 
calling OnBnClickedSelect() method.

-----------------------------------------------------------------------

SOCKET s;

void OnBnClickedConnect()

{

s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

char chost[1024];

wcstombs(chost,_T("ServerName"),1024);

struct hostent *pHostInfo; 

pHostInfo = gethostbyname( chost );

int nHostAddress;

memcpy(&nHostAddress,pHostInfo->h_addr,pHostInfo->h_length);

struct sockaddr_in Address; 

Address.sin_addr.s_addr = nHostAddress;

Address.sin_port = htons(80);  //port number

Address.sin_family = AF_INET;

int i =connect(s,(struct sockaddr*)&Address,sizeof(Address));

if (i!=0)

MessageBox(NULL, _T("connect error"), MB_OK);

}

 

void CtestDlg::OnBnClickedSelect()

{

int nRecvRetVal = 0;

struct timeval tv = {0};

fd_set rs;

fd_set ex;

fd_set wr;

tv.tv_sec = 0;

tv.tv_usec = 100000; 

FD_ZERO(&rs);

FD_ZERO(&ex);

FD_ZERO(&wr);

FD_SET(s, &rs);

FD_SET(s, &ex);

FD_SET(s, &wr);

nRecvRetVal = select(1, &rs, &wr, &ex, &tv);

if(nRecvRetVal == SOCKET_ERROR)

{

MessageBox(NULL, _T("return error"), MB_OK);

}

if (FD_ISSET(s, &ex))

{

MessageBox(NULL, _T("exception happen"), MB_OK);

}

if (FD_ISSET(s, &wr))

{

MessageBox(NULL, _T("write ready"), MB_OK);

}

if(FD_ISSET(s, &rs))

{

MessageBox(NULL, _T("read available \n"), MB_OK); 

}

}

Thanks for any suggestion.

Jonathan

  Was this post helpful to you?         
 
  Why should I rate a post? 
 
 
 
Expand AllCollapse All 

4. select() not return socket error after pocket pc unplugged fro - Pocketpc Developer

5. select function call from winsock library

Hi ,
I am having problem with the select function call from winsock library. I 
have given 10 milli seconds so that the select loop should return after 
10msec, but it is always taking more than 10msec. If I run the following 
lines in a loop most of the time it times out after 11 milli sec or 12 milli 
sec or later, very few times may be 2 out of 10 times it times out exactly 
after 10msec. On an average it times out after 10.886mecs. Any reason why it 
is showing this behaviour or is there any other way to finetune it. I have 
seen this behaviour in both Windows-XP and Windows-2000.

timeBeginPeriod(1);
 //timeEndPeriod(1);

 fd = socket(AF_INET,SOCK_DGRAM,0);
    
 long int diff =0, before = 0, after = 0;
 timeval t;
 int result=-1;
 int test = 1;

 long duration = 0x0;
    timeb timeStart, timeEnd;
 float average = 0;
    
    //while (1)
 for (int i=0; i<loops; i++)
 {
  diff = 0;
        fds = 0;
  result=-1;
  t.tv_sec = 0;
  
  t.tv_usec = interval;
 
  FD_ZERO(&excp);
  FD_SET(fd,&excp);
  fds++;
  ftime(&timeStart);
  before = timeGetTime();
  result = select(fds,0x0,0x0,&excp,&t);
 
  result=0;
  after = timeGetTime();
  diff = after - before;
  ftime(&timeEnd);
  average += diff;
  average /= 2;
  if ( result == -1 )
   cout << WSAGetLastError() << endl;
  else if (result == 0 && flag) 
  {
   printf("ftime Timeout occured : %d\n", timeEnd.time - timeStart.time); 
   printf("ftime Timeout occured : %d\n", timeEnd.millitm - 
timeStart.millitm); 
   printf("MultiMedia Timeout occured : %d\n", diff);
  }
 }
 printf("average MultiMedia Timeout occured : %f\n", average);

I have attached the complete code for your reference.

Regards,
Sarbeswar

6. Regarding behaviour of select() call

7. select called from different threads

Hi, suppose I have 2 posix threads, both calling select() on the same
descriptor, thread A for read & except and B for write & except,
is this allowed? Or should only one select() be made at a time for each file
descriptor?



8. select-like implementation for kernel sockets