1) How many times per 1 second do you call recv?
Calling it too much DDoSes the PSP's wifi from inside out - causing data to lag. This is not a problem if recv is blocking, but due to the MSG_DONTWAIT flag, it might be calling it constantly
Use a counter like so:
Code: Select all
unsigned int system_getTicks()
{
u64 ticks;
sceRtcGetCurrentTick(&ticks);
return ticks/1000;
}
unsigned int main(...)
{
unsigned int startTime=system_getTicks();
unsigned int calls=0;
while(1)
{
recv();
calls++;
unsigned int currentTime=system_getTicks();
if((startTime + 1000) < currentTime)
{
//~1 second has passed
printf("Recv called %d times in ~1 second\n", calls);
calls=0;
startTime=currentTime;
}
}
}
Please report the # of times per second at which recv is called when using the MSG_DONTWAIT flag
2) MSG_DONTWAIT - are you sure that's not causing the problem
E.g., it peeks at the buffer without clearing it
Replace MSG_DONTWAIT with 0 to test how it works without this flag, but this will make the socket a blocking socket
Please see #4 to learn how to do nonblocking using the poll method
3) numhold - what type is it? Make it signed int, and then instead of:
if (numhold!=-1 && numhold!=0)
Do:
if (numhold > 0)
Sony error codes go into the negatives, and they're not just -1
So if the error code was -13123123, it would have been causing your if to printf() the previous data
4) If MSG_DONTWAIT is the problem, and you want non-blocking sockets, do this:
Code: Select all
signed int net_sock=SOCKET_UNINITIALIZED;
//Function returns -1 when error, 0 when no data received, and >0 when data received
signed int net_recv(void *a_data, unsigned int a_size)
{
struct timeval timeVal;
signed int fdReadyTotal;
fd_set fdReadFlag;
//Initiate the block time
timeVal.tv_sec=0;
timeVal.tv_usec=1000; //Cannot be too low, or it'll DDoS the wlan from inside out
//This is how long the select function should wait to see if data was received before calling recv
//Reset the flag
FD_ZERO(&fdReadFlag);
FD_SET(net_sock, &fdReadFlag);
//Generate the data regarding which file descriptor is free
fdReadyTotal=select(FD_SETSIZE, &fdReadFlag, NULL, NULL, &timeVal);
if(fdReadyTotal < 0)
{
printf("NetRecv:Error - Select < 0\n");
return -1;
}
//Is the socket ready?
if((fdReadyTotal!=0) && FD_ISSET(net_sock, &fdReadFlag))
{
signed int recvRet=recv(net_sock, a_data, a_size, 0);
if(recvRet <= 0)
{
printf("NetRecv:Error - Recv <= 0\n");
return -1;
}
return recvRet;
}
return 0;
}
PC tutorials might say that using FD_SETSIZE is idiotic, and to use net_sock+1 instead. This is not the case on the PSP, so stick to using FD_SETSIZE since each stream PSP handler contains bit flags, therefore net_sock+1 wouldn't work due to these bit flags. Well it'd work but the range needing to be checked would be > than the value of FD_SETSIZE. The solution is to do: (net_sock & SOME_VALUE) +1, but I at the moment don't remember what SOME_VALUE is - nor do I feel that it is of great importance