I am trying to get the select() function to work so it will check if any packages has arrived so that I know when to activate recvfrom() function. As it is now recvfrom() blocks the process for 60 sec and this will not work for my application.
setsockopt() is a function I am trying to use to put the system in a nonblocking mode, but I am not sure if I have made the right commands for it. Does it look correct?
select() should be active 5k ms to check if there are any messages, but sel0 is always zero! Have I mixed up any commands or misunderstood the usage of the function?
I would be grateful for any help in this matter!
// The family
addrServer. sa_family = AF_INET;
// The Server port:
addrServer. sa_data[0] = Port[0];
addrServer. sa_data[1] = Port[1];
// The Server IP address:
addrServer. sa_data[2] = IP_Server[0];
addrServer. sa_data[3] = IP_Server[1];
addrServer. sa_data[4] = IP_Server[2];
addrServer. sa_data[5] = IP_Server[3];
iReturnSOCKETServer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
struct timeval timeout;
timeout. tv_sec = 0;
timeout. tv_usec = 5000;
fd_set fdSet;
FD_ZERO(&fdSet);
FD_SET(iReturnSOCKETServer, &fdSet);
memset (&addrServer.sa_data [2], 0, 4);
iReturnBINDServer = bind(iReturnSOCKETServer, &addrServer, sizeof (sockaddr ));
int nonBlocking = SOCK_ON;
setsockopt(iReturnSOCKETServer, SOL_SOCKET, SOCKOPT_NONBLOCK, &nonBlocking, sizeof (nonBlocking));
sel0 = select(iReturnSOCKETServer+1, &fdSet, NULL, NULL, &timeout); // Always zero
UARTprintf ("Select: %i\n" , sel0);
sel1 = listen(iReturnSOCKETServer, 0); // Always zero
UARTprintf ("listen iReturnSOCKETServer: %i\n" , sel1);
if (!FD_ISSET(iReturnSOCKETServer,&fdSet))
{
UARTprintf ("FD is not set!\n" ); // This is always printed!
}
iReturnREQUESTServer = recvfrom(iReturnSOCKETServer, ucRx_Buffer, CC3000_APP_BUFFER_SIZE, 0, &addrServer, &tRxPacketLength);
UARTprintf ("Command: %c\n" ,ucRx_Buffer[0]);