Discussion:
[lwip-users] a beginners questions about lwip, sockets and threads
a***@nibe.se
2011-05-24 13:14:42 UTC
Permalink
Hi,

I've just started porting lwip to our platform and I have run in to some
slight problems and I hope this is the right mailing list for these kind
of questions (if it isn't please redirect me to a more suitable place)

I've gotten the porting layer in place and the my lwip_init() has stopped
complaining about my timeouts. The next step as I figure is to test the
socket-API using the loopback interface.

My questions are:
1. Can I use threads? One to receive and one to transmit data and then
check if the data arrives correctly?
2. Should I use TCP or UDP-sockets (SOCK_STREAM/SOCK_DGRAM)
3. Are the unit tests for porting or for the developers of the stack?
(I've looked for info on this but I haven't found an answer yet)
4. I'm currently running 1.3.2 is there any reason to upgrade to 1.4.0
besides the new number?

I've already tried to start thread-to-thread-communication with sockets
but I'm quite inexperienced when it comes to working with sockets so I
might have done some trivial mistake. My init sequence and socket-code can
be found here: http://pastebin.com/ScSZ7fYK if anyone has a slow afternoon
and feel like nitpicking =)

Thanks in advance.

Best regards
/Åke Forslund

-----------------------------
Åke Forslund
0433-273296
NIBE AB
Box 14
S-285 21 Markaryd
Tel +46-(0)433-273296
Kieran Mansley
2011-05-24 13:30:26 UTC
Permalink
Post by a***@nibe.se
1. Can I use threads? One to receive and one to transmit data and then
check if the data arrives correctly?
You can, but I would do it all in one thread, and use poll() to
determine when each socket needs attention (either sending or
receiving).
Post by a***@nibe.se
2. Should I use TCP or UDP-sockets (SOCK_STREAM/SOCK_DGRAM)
Either.
Post by a***@nibe.se
3. Are the unit tests for porting or for the developers of the stack?
(I've looked for info on this but I haven't found an answer yet)
Not really, no.
Post by a***@nibe.se
4. I'm currently running 1.3.2 is there any reason to upgrade to 1.4.0
besides the new number?
Yes: (i) you're likely to get much better support from the developers if
you're using 1.4.0; (ii) lots of bug fixes; (iii) improved performance;
(iv) etc!

Kieran
g***@gmx.de
2011-05-24 17:08:57 UTC
Permalink
Post by Kieran Mansley
Post by a***@nibe.se
1. Can I use threads? One to receive and one to transmit data and then
check if the data arrives correctly?
You can, but I would do it all in one thread, and use poll() to
determine when each socket needs attention (either sending or
receiving).
Actually, there's one limitation here I have to point out for completeness:

You may *not* share one sockets between multiple threads. So while you
are allowed to receive on socket A in one thread and send on socket B in
another thread, you may *not* receive on socket A in one thread an send
on the same socket A in any other thread!


Simon
a***@nibe.se
2011-05-25 07:15:04 UTC
Permalink
Right, so I guess the best idea is to keep the sockets local and per
thread. In my final application I will have a single thread communicating
with the outside world over tcp/ip so this won't be a problem. Out of
curiosity, can sockets usually (in other implementations) be shared
between threads?

/Åke

-----------------------------
Åke Forslund
0433-273296
NIBE AB
Box 14
S-285 21 Markaryd
Tel +46-(0)433-273296




From:
"***@gmx.de" <***@gmx.de>
To:
Mailing list for lwIP users <lwip-***@nongnu.org>
Date:
2011-05-24 19:09
Subject:
Re: [lwip-users] a beginners questions about lwip, sockets and
threads
Post by Kieran Mansley
Post by a***@nibe.se
1. Can I use threads? One to receive and one to transmit data and then
check if the data arrives correctly?
You can, but I would do it all in one thread, and use poll() to
determine when each socket needs attention (either sending or
receiving).
Actually, there's one limitation here I have to point out for
completeness:

You may *not* share one sockets between multiple threads. So while you
are allowed to receive on socket A in one thread and send on socket B in
another thread, you may *not* receive on socket A in one thread an send
on the same socket A in any other thread!


Simon
g***@gmx.de
2011-05-25 15:24:27 UTC
Permalink
Out of curiosity, can sockets usually (in other implementations) be
shared between threads?
I don't think there's a standard documenting this somewhere, but I think
at least linux and windows do support this.

Simon
Martin Velek
2011-05-26 07:04:43 UTC
Permalink
Check this site.

http://lwip.wikia.com/wiki/LwIP_and_multithreading

Martin
Post by a***@nibe.se
Right, so I guess the best idea is to keep the sockets local and per
thread. In my final application I will have a single thread communicating
with the outside world over tcp/ip so this won't be a problem. Out of
curiosity, can sockets usually (in other implementations) be shared between
threads?
/Åke
-----------------------------
Åke Forslund
0433-273296
NIBE AB
Box 14
S-285 21 Markaryd
Tel +46-(0)433-273296
Date: 2011-05-24 19:09 Subject: Re: [lwip-users] a beginners questions
------------------------------
Post by Kieran Mansley
Post by a***@nibe.se
1. Can I use threads? One to receive and one to transmit data and then
check if the data arrives correctly?
You can, but I would do it all in one thread, and use poll() to
determine when each socket needs attention (either sending or
receiving).
You may *not* share one sockets between multiple threads. So while you
are allowed to receive on socket A in one thread and send on socket B in
another thread, you may *not* receive on socket A in one thread an send
on the same socket A in any other thread!
Simon
_______________________________________________
lwip-users mailing list
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
https://lists.nongnu.org/mailman/listinfo/lwip-users
a***@nibe.se
2011-05-25 07:07:08 UTC
Permalink
Thanks,

the reasons for upgrading were pretty convincing and the upgrade was
pretty smooth I must say. Even if the documentation don't seem to be quite
up to date. I'll see if I can find time to update the wiki tonight.

For now I'll try to get a socket example working in cygwin and then see if
I can get the same code to execute under lwip.

/Åke

-----------------------------
Åke Forslund
0433-273296
NIBE AB
Box 14
S-285 21 Markaryd
Tel +46-(0)433-273296




From:
Kieran Mansley <***@recoil.org>
To:
Mailing list for lwIP users <lwip-***@nongnu.org>
Date:
2011-05-24 15:30
Subject:
Re: [lwip-users] a beginners questions about lwip, sockets and threads
Post by a***@nibe.se
1. Can I use threads? One to receive and one to transmit data and then
check if the data arrives correctly?
You can, but I would do it all in one thread, and use poll() to
determine when each socket needs attention (either sending or
receiving).
Post by a***@nibe.se
2. Should I use TCP or UDP-sockets (SOCK_STREAM/SOCK_DGRAM)
Either.
Post by a***@nibe.se
3. Are the unit tests for porting or for the developers of the stack?
(I've looked for info on this but I haven't found an answer yet)
Not really, no.
Post by a***@nibe.se
4. I'm currently running 1.3.2 is there any reason to upgrade to 1.4.0
besides the new number?
Yes: (i) you're likely to get much better support from the developers if
you're using 1.4.0; (ii) lots of bug fixes; (iii) improved performance;
(iv) etc!

Kieran
Luca Ottaviano
2011-05-24 13:36:06 UTC
Permalink
Hi Åke,
Post by a***@nibe.se
1. Can I use threads? One to receive and one to transmit data and then
check if the data arrives correctly?
Yes, you can. I only have experience with sockets API (which in my
opinion is simpler to use), but that has never been a problem.
Post by a***@nibe.se
2. Should I use TCP or UDP-sockets (SOCK_STREAM/SOCK_DGRAM)
That depends on your application. Bear in mind that both types use
netconn connections below, so you need to configure a number of netconn
equal or more than the number of TCP + UDP sockets that you plan to use.
Post by a***@nibe.se
4. I'm currently running 1.3.2 is there any reason to upgrade to 1.4.0
besides the new number?
With 1.4.0 you get many new features and the OS layer is much simpler to
implement.
Post by a***@nibe.se
I've already tried to start thread-to-thread-communication with
sockets but I'm quite inexperienced when it comes to working with
sockets so I might have done some trivial mistake. My init sequence
and socket-code can be found here: http://pastebin.com/ScSZ7fYKif
anyone has a slow afternoon and feel like nitpicking =)
If you use the sockets API, you can develop and debug your threads as
different processes on PC. Porting to lwip is just a matter of adding
lwip_ prefix to posix calls.
I suggest that you start coding one process and use netcat (or
equivalent) on the other end.

Cheers,
--
Luca Ottaviano - ***@develer.com
Develer S.r.l. - http://www.develer.com/
.hardware .software .innovation
Tel.: +39 055 3986627 - ext.: 218
Loading...