Welcome! Log In Create A New Profile

Advanced

net_recvfrom: is it working? [SOLVED]

Posted by Izhido 
net_recvfrom: is it working? [SOLVED]
April 06, 2009 04:52PM
Hi!

I've posted this question in countless places... it feels like I'm spamming every forum I've been into. Apologies for that.. it's just that I would like to find *that* person... the one that could answer this question.

< context >

Days ago, I found out that net_recv, net_recvfrom, and net_sendto were returning -22 as error code. I, at first, assumed it was -EINVAL, and that it was obviously my own fault for specifying incorrect parameters... the thing is, hours & hours of checking the code, and looking at examples, they did tell me my parameters were right... until I found this one page: http://simonkagstrom.livejournal.com/40567.html , explaining that 8+ KB data buffers with these functions *will* fail. A quick check on SVN for IPC_ENOMEM revealed what was happening: the functions were returning -ENOMEM, not -EINVAL, though they share the same value (22).

Cool! Thinking all of my problems were finally solved, I tried using net_recv on this app I'm working on, just to test the waters. And it worked! Well, almost. Of course, since net_recv does not return the sender's address, the rest of the code will invariably reject all packets sent. No problem! We'll start using net_recvfrom() (as it was supposed to be). Even better, since net_recv(...) is basically net_recvfrom(..., NULL, 0) (as SVN can confirm), everything should work OK, right?

Well, guess what? :(

</ context >

For reasons I simply can't understand, net_recvfrom() will hang the application, when net_recv() works OK, using the *same* parameters in both cases (save for the last two, of course).

Anyone in here has run into this problem? Any idea why does this happen?

EDIT: Just looked at the app the page above was referring to. Checking this: http://frodo-wii.googlecode.com/svn/trunk/Src/NetworkWii.h , it told me what I feared most: even the guy who discovered the 8KB limitation in network is using net_recv instead of net_recvfrom :(

- Izhido



Edited 2 time(s). Last edit at 04/08/2009 05:27PM by Izhido.
Re: net_recvfrom: is it working?
April 06, 2009 05:56PM
Your socket is probably blocking and WILL hang the app if no data is received. Yes there's a limit on receiving data, I use about 2K as my buffer.

As for what function to use. net_recv is for TCP and net_recvfrom is primarily for UDP.

Yes Simon's code is pretty nifty but you probably need to start with a simpler example. There's a simple web server example under the gamecube examples. You can use if for Wii if you change the rules to wii_rules in the make.
Re: net_recvfrom: is it working?
April 06, 2009 08:45PM
Oh, that.

Let me assure you, net_poll() is being called before the call to net_recv()/net_recvfrom(). Even then, when net_poll() reports valid data, net_recv() reads & returns it, while net_recvfrom() hangs forever. Odd, huh?

Could it be that there's a bug in the way net_recvfrom() works when the two last parameters are not NULL / 0 ?

- Izhido
Re: net_recvfrom: is it working?
April 06, 2009 09:04PM
I think the last 2 params of net_recvfrom() can't be NULL, that's needed for the socket. Here's a small snippet from my network code (for the receive ops).


s32             connection_socket; //client
struct          sockaddr_in client;

int client_recv(char* buffer,int len)
    {
        if (!client_connected) return 0;

        u32 clen = sizeof(client);
        return c_protocol == TCP ?   net_recv(connection_socket, buffer, len, 0) :
                                     net_recvfrom(connection_socket, buffer, len, 0,(struct sockaddr*)&client,&clen);

    }

Re: net_recvfrom: is it working? [SOLVED]
April 08, 2009 05:25PM
scanff: Dude, thank you so much! You solved it!

Turns out I *never* specified a valid value for the last parameter in the net_recvfrom() call (&clen, in your snippet). Somehow, I was expecting it to return something, instead of both requiring a valid value THEN returning something :)

Anyway, with that change, net_recvfrom now works as expected. Many thanks for your help!

- Izhido
Re: net_recvfrom: is it working? [SOLVED]
April 09, 2009 02:50PM
I know this is already solved, but I just wanted to make one clarification: net_recv or net_recvfrom doesn't really matter. This is the implementation of net_recv in libogc:

s32 net_recv(s32 s, void *mem, s32 len, u32 flags)
{
    return net_recvfrom(s, mem, len, flags, NULL, NULL);        
}

I use net_recv since I don't care about the source of the message.
Sorry, only registered users may post in this forum.

Click here to login