WIZnet Developer Forum

Socket.c bugs

I found two issues so far with socket.c source code

my file version is: <2014/05/01> V1.0.3. Refer to M20140501

sock_io_mode issue: I was expecting that this flag be cleaned when you close the socket.

The other issue is related with recv
In block io mode, it doesn’t return until data reception is completed - data is filled as len in socket buffer.

but what is implemented is that it will return as soon as it get any data:
if(recvsize != 0) break;
I think this code need review.

Hi, kammutierspule!

Thank your advice and interesting.

We will check it ASSP.

Hi, kammutierspule.

First issue are correct. The closesocket() should be added to “sock_io_mode &= ~(1<<sn)”. It will be updated ASSP.

In Second issue,
The recv() function in block mode, will returned as soon as get any data, do not wait until data will be received as ‘len’.

If you need the recv() function that wait until should be received as 'len,
I recommend as below code.

while(1)
{
...
...
  if(len >= getSn_RX_RSR(sn))  // len can't exceed the socket RX buffer max size.
  {
       recv(sn, buf, len); // don't care socket io mode.
  } 
...
...
}

Thank you.

I was looking for BSD recv function and It looks that your implementation is correct:

linux.die.net/man/2/recv
"The receive calls normally return any data available, up to the requested amount, rather than waiting for receipt of the full amount requested."

So the issue is in the wiznet socket.h documentation:

[quote]
It waits for data as much as the application wants to receive.

In block io mode, it doesn’t return until data reception is completed - data is filled as len in socket buffer.[/quote]

So, it no correct to say “data is filled as len in socket buffer”

Hi,

I’m so sorry about my poor eglish skill.

Generously your understanding ^^;

Thank you.

And I believe there is one more thing to correct in socket.c, function sendto().
Bellow, I believe should be taddr, not addr.
Am I right?


//M20140501 : For avoiding fatal error on memory align mismatched
//if(((uint32_t)addr) == 0) return SOCKERR_IPINVALID;
{
uint32_t taddr;
taddr = ((uint32_t)addr[0]) & 0x000000FF;
taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF);
taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF);
taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF);
}
//
if(((uint32_t)[color=#FF0000]addr[/color]) == 0) return SOCKERR_IPINVALID;


Hi,
You’re right!!!
‘addr’ should be ‘taddr’… (My mistake T.T;)

I will update ioLibrary_BSD ASSP.

Thank you again!!!

Wouldn’t it be better if this ioLibrary_BSD was in a public repository (github wiznet account?) so we all can use the appropriated tools and platform for bug reporting, version control… etc?!

Hi,
It will be considered!!!
Thank you.

I’ve just checked the current version (1.0.3) of code for socket.c at https://github.com/Wiznet/W5500_EVB or http://wizwiki.net/wiki/doku.php?id=products:w5500:driver and the fixes don’t appear to have made it to this driver yet. When will this driver be updated at github?

Hi, fherbert

We are modifying code about your point and other points.
So, we will update next version ASAP!

Plz, wait a while kindly~:D

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.