FD_ISSET() code working on pc, but not on psp

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
cadaver
Posts: 21
Joined: Sun Aug 07, 2005 2:31 am

FD_ISSET() code working on pc, but not on psp

Post by cadaver »

Code: Select all


	bool getServerMessagesDgram()
	{

begin:
		read_fds = master;

		timeval tv;

		tv.tv_sec  = 0;
		tv.tv_usec = 0;

		if (select(FD_SETSIZE, &read_fds, NULL, NULL, &tv) == -1)
		{
			report_error("select failed.");
			return false;
		}
		
		if (FD_ISSET(fd_dgram_listen, &read_fds))
		{
			char buf[MESSAGE_LENGTH_SERVER];

			sockaddr_in remoteaddr;

			socklen_t addrlen;
			
			addrlen = sizeof remoteaddr;

			int nbytes = recvfrom(fd_dgram_listen, buf, MESSAGE_LENGTH_SERVER, 0, (sockaddr*)&remoteaddr, &addrlen);

			if (nbytes > 0)
			{

				// do something useful...

				goto begin; // read all from buffer...

			}
			
			return true;
		}
		return false;
	}

This code is working as it should on the pc. (there is only one socket fd in the master set, I'm listening to)

But on the psp, FD_ISSET is always true, so the function loops forever, and recvfrom forever recieves bytes of length "MESSAGE_LENGTH_SERVER".

Both sets were cleared with

FD_ZERO(&master);
FD_ZERO(&read_fds);

The master was set up with

FD_SET(fd_dgram_listen, &master);
cadaver
Posts: 21
Joined: Sun Aug 07, 2005 2:31 am

Post by cadaver »

Seems, select/FD_ISSET don't work with dgram sockets (psp)?
I've set the socket now to nonblock (fcntl(fd_dgram_listen, F_SETFL, O_NONBLOCK);) and I'm repeating recvfrom while nbytes > 0. Then it's ok.
Post Reply