This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Detect whether the socket connection is closed

Other Parts Discussed in Thread: CC3100

In my application the cc3100 is a client and it connects to a remote server. I could use the sl_recv to identify whether the connection is still alive by checking the return code. I use a non blocking function in a Non-OS application

SL_EA_AGAIN(-11) if it's alive
0 in case of disconnect

I hope to call 'slrecv' before every socket operation. However if I call this function while some data is available, the data will be pushed out of the buffer and discarded. How can I overcome this?

Also, I tried an alternate method by using 'sl_select' 

int wificlass::socket_available()
{
	INT16           Status = 0;	
	SlFdSet_t ReadFds;
	SlTimeval_t timeout;
	timeout.tv_sec=1;
	timeout.tv_usec=0;
	SL_FD_ZERO(&ReadFds);
	SL_FD_SET(SockID, &ReadFds);	
	Status=sl_Select(SockID+1, &ReadFds, NULL,NULL, &timeout);
	if(Status==1)
	if (FD_ISSET(SockID, &ReadFds))
	printf("set\n");
	return Status;
}

The status value returned from the function is 0,when there is no data.


But it returns 1 when data is available and if the connection is closed.


Is there something which I am missing here?