Re: [lwip-users] lwIP delays outgoing TCP packets by up to 500ms

2016-07-13 Thread Pîrvu Mihai
Again, it's probably not be the wrong approach, it's just what I've been
told on this thread:

https://lists.gnu.org/archive/html/lwip-users/2016-06/msg00055.html

Since it worked for me at that moment, I just let it like that, and reading
the responses here confirms that it's the correct approach if you don't
want to wait for the delay.

Mihai

On Wed, Jul 13, 2016 at 5:59 PM, Jakub Schmidtke  wrote:

> I think you might have missed reading the documentation: tcp_write enqueue
>> data, tcp_outout tries to send it. You always have to call both.
>>
>> I actually found the recommended call flow on wiki (Here:
> http://lwip.wikia.com/wiki/Raw/TCP ) after Mihai mentioned using
> tcp_output().
> And yes, I haven't fully read the docs/wiki yet, since I am trying to fix
> existing code written by someone else - who must have missed that...
>
> However, Mihai mentions that calling tcp_output() might be the wrong
> approach... Is it really?
>
> Thanks!
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] lwIP delays outgoing TCP packets by up to 500ms

2016-07-13 Thread Pîrvu Mihai
I've worked around this disabling Nagle Algorithm for each pcb and also
calling tcp_output after every write. But somebody told me it was the wrong
approach doing so, but it works for me so I don't know what to say.

Mihai

On Wed, Jul 13, 2016 at 3:20 AM, Jakub Schmidtke  wrote:

> Hi,
>
> I am using lwip with NO_SYS=1, and I have noticed
> that outgoing TCP packets are very delayed.
>
> It looks like between writing a packet (using tcp_write),
> and the time it actually written to the interface it takes usually about
> 200ms.
>
> I examined the code, and it looks like lwip only writes regular packets
> every 500ms.
>
> Basically tcp_write only adds segments to a list, and they are only
> actually sent inside tcp_slowtmr.
> Which, by default, is only called once every two calls to tcp_tmr().
> Which gets called every 250ms, so the data being written with tcp_write
> will be sent out up to 500ms later.
>
> This is a really, really long time!
>
> Am I missing something?
>
>
> Thanks!
>
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] TCP Raw API questions about efficiency and threads

2016-06-20 Thread Pîrvu Mihai
Hello guys, I'm posting here to tell you that the problem was much simpler
than I thought. Once I disabled Nage's Algorithm for all the PCBs and
called tcp_output after every write, the speed increased dramatically
(similar to my netconn UDP implementation).

I guess those are enabled by default for good reasons, but in my case it
was adding a way too big of a delay.

Mihai

On Wed, Jun 8, 2016 at 3:43 PM, Sergio R. Caprile 
wrote:

> > Regarding of you saying stuff about examples online, I can't find any
> > more "complex" example out there. All the examples have a really
> > simple design, client sends message, receives message back and then
> > the connection is closed. Is there any examples out there where
> > connections are persistent and messages can come at any given time ?
>
> Sure, just don't close the connection... ;^)
> You get something at the recv callback, you send something back. Does it
> fit in the TCP buffer ? Then you send it. Are there any bytes left to send
> ? Yes, then you will send them _at the *sent* callback, not the poll
> callback. The poll callback is mostly for housekeeping and attending
> periodic tasks. The sent callback is fired when the other end acknowledged
> and there is room to send more data (that is why you couldn't send, because
> there was no room, so you have to wait for room, not for time, for room,
> and that happens when sent data can be discarded because the other end
> signals it has been received, and then the stack is sure it won't have to
> resend it, so it can free RAM. When you have to wait for time, because a
> close fails or something, then you'll use the poll callback.
>
> I do believe the http server is more than pretty complex, and the smtp
> server is complex enough. Those are great examples and I've learned all I
> needed to learn just by watching closely at them.
> Start with the echo example, move perhaps to the netio example, and then
> go to smtp and then http.
>
> There is also the wiki, which explains in detail all you need to know
> about the function calls. http://lwip.wikia.com/wiki/Raw/native_API
>
>
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] TCP Raw API questions about efficiency and threads

2016-06-07 Thread Pîrvu Mihai
 return
> ERR_OK
>
> - also in recv callback, i save the pbuf in my client arg and process it
> in poll
>
> - in accept callback, i set up the arg to my internal struct, and a poll
> function with argument 1 (as far as I understand that means polling every
> 500ms, can i change this? seems too slow for what I try to achieve)
>
> - In poll callback, I process the packet(s) because there can be multiple
> packets arriving in my pbuf (packets that are concatenated together). I
> read all the data (pbuf->tot_len) in a separate buffer then loop the buffer
> for each individual inner packet. For each packet, I check the destination,
> if it's broadcast, I send it to all my active clients (note: that all
> connections are active until they disconnect from client-side, that means I
> don't have any keep-alive verification, if I get in recv callback with pbuf
> == NULL => client disconnected, otherwise I consider it active right now).
> If it's a unicast message, I send it just to the respective peer. I do my
> checking by MAC address (clients will send their MAC as the first message
> when they connect to server). I call tcp_write in order to send my messages
> (I saw something about tcp_output when I use tcp_write from outside recv
> callback, I'm not using that now).
>
>
>
> After I've done this (before I processed the packet in recv callback, not
> poll callback), my ping between clients is even worse (700ms~) and only one
> client receives ICMP replies (so no concurrency).
>
>
>
> I feel like I'm doing lots of stuff wrong, like copying the data from pbuf
> to my static buffer, then calling tcp_write with flag TCP_WRITE_FLAG_COPY
> seems like overkill when copying data.
>
>
>
> Regarding of you saying stuff about examples online, I can't find any more
> "complex" example out there. All the examples have a really simple design,
> client sends message, receives message back and then the connection is
> closed. Is there any examples out there where connections are persistent
> and messages can come at any given time ?
>
>
>
> Mihai
>
>
>
> On Fri, Jun 3, 2016 at 10:21 AM, Noam Weissman <n...@silrd.com> wrote:
>
>
>
> In order to use RAW API efficiently you can use the poll call back to send
> more data. What do I
>
> mean by that ?
>
> Lets assume you got some request for data and you are handling it inside
> the recv function.
>
> If you send back all the data you are busy inside that recv instant and
> blocking other parallel
>
> connections. One way to avoid this is to start sending (a portion) and get
> out of the recv. The rest of the send will be handled inside the poll
> function. the poll function is called periodically as long as the
>
> current connection is a live... house keeping.
>
>
>
> Once you no longer need that connection can gracefully close it from
> inside the poll function.
>
>
>
> Another way to use the poll call back is to put some data in a queue (from
> main thread) while from
>
> inside the poll call back (TCP own thread) read that data and send it to
> the open connection.
>
>
>
> BR,
>
> Noam.
>
>
>
>
>
>
>
>
>
>
>
>
> --
>
> *From:* lwip-users <lwip-users-bounces+noam=silrd@nongnu.org> on
> behalf of Pîrvu Mihai <mihaicristianpi...@gmail.com>
> *Sent:* Friday, June 3, 2016 12:15 AM
> *To:* Mailing list for lwIP users
> *Subject:* [lwip-users] TCP Raw API questions about efficiency and threads
>
>
>
> Hello guys, I've just ported my application to tcp raw API and I was
> wondering a few things.
>
>
>
> I've noticed that the performance is a bit too bad (300-500 ms for pings,
> between local clients) and I was wondering if I'm doing some things wrong.
>
>
>
> Firstly,  I'm doing all my packet processing + sending of replies in
> tcp_recv callback. Is this normal, or shall I save the data somehow and
> process it later. My idea is that this blocks the main thread and the next
> packets are delayed. But I don't know this for sure.
>
>
>
> I don't understand how I can use multiple threads using this API. It's
> callback based, so where do I create the threads? Let's say I want to
> process the entire callback saved using tcp_recv on a separate thread. Is
> that possible or do I have to create a new thread inside the callback?
>
>
>
> The application I'm using is a vpn server that has to inspect the packets
> (so I do that in tcp_recv), see where to forward one packet (from a list of
> connected clients to the server) and send that data to the client. I saw
> that each tcp_pcb has a unique memory address (obv.), so I save that in an
> array and if the client IP/MAC is the same as on in the array, I send my
> data to that pcb from the array. I can also send broadcasts (if mac is
> FF:FF:FF:FF:FF:FF). This is the "processing" that is done.
>
>
>
> One bad thing is that I copy the entire pbuf into a local buffer and free
> it (I saw that there's some idea to save it for later use, would love to
> see some examples on that).
>
>
>
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] TCP Raw API questions about efficiency and threads

2016-06-07 Thread Pîrvu Mihai
Alright, I've modified my code a little. What I've done is pretty much this:

- from recv callback, I just call tcp_recved on pbuf->tot_len and return
ERR_OK
- also in recv callback, i save the pbuf in my client arg and process it in
poll
- in accept callback, i set up the arg to my internal struct, and a poll
function with argument 1 (as far as I understand that means polling every
500ms, can i change this? seems too slow for what I try to achieve)
- In poll callback, I process the packet(s) because there can be multiple
packets arriving in my pbuf (packets that are concatenated together). I
read all the data (pbuf->tot_len) in a separate buffer then loop the buffer
for each individual inner packet. For each packet, I check the destination,
if it's broadcast, I send it to all my active clients (note: that all
connections are active until they disconnect from client-side, that means I
don't have any keep-alive verification, if I get in recv callback with pbuf
== NULL => client disconnected, otherwise I consider it active right now).
If it's a unicast message, I send it just to the respective peer. I do my
checking by MAC address (clients will send their MAC as the first message
when they connect to server). I call tcp_write in order to send my messages
(I saw something about tcp_output when I use tcp_write from outside recv
callback, I'm not using that now).

After I've done this (before I processed the packet in recv callback, not
poll callback), my ping between clients is even worse (700ms~) and only one
client receives ICMP replies (so no concurrency).

I feel like I'm doing lots of stuff wrong, like copying the data from pbuf
to my static buffer, then calling tcp_write with flag TCP_WRITE_FLAG_COPY
seems like overkill when copying data.

Regarding of you saying stuff about examples online, I can't find any more
"complex" example out there. All the examples have a really simple design,
client sends message, receives message back and then the connection is
closed. Is there any examples out there where connections are persistent
and messages can come at any given time ?

Mihai

On Fri, Jun 3, 2016 at 10:21 AM, Noam Weissman <n...@silrd.com> wrote:

>
> In order to use RAW API efficiently you can use the poll call back to send
> more data. What do I
>
> mean by that ?
>
> Lets assume you got some request for data and you are handling it inside
> the recv function.
>
> If you send back all the data you are busy inside that recv instant and
> blocking other parallel
>
> connections. One way to avoid this is to start sending (a portion) and get
> out of the recv. The rest of the send will be handled inside the poll
> function. the poll function is called periodically as long as the
>
> current connection is a live... house keeping.
>
>
> Once you no longer need that connection can gracefully close it from
> inside the poll function.
>
>
> Another way to use the poll call back is to put some data in a queue (from
> main thread) while from
>
> inside the poll call back (TCP own thread) read that data and send it to
> the open connection.
>


> BR,
>
> Noam.
>
>
>
>
>
>
>
> --
> *From:* lwip-users <lwip-users-bounces+noam=silrd@nongnu.org> on
> behalf of Pîrvu Mihai <mihaicristianpi...@gmail.com>
> *Sent:* Friday, June 3, 2016 12:15 AM
> *To:* Mailing list for lwIP users
> *Subject:* [lwip-users] TCP Raw API questions about efficiency and threads
>
> Hello guys, I've just ported my application to tcp raw API and I was
> wondering a few things.
>
> I've noticed that the performance is a bit too bad (300-500 ms for pings,
> between local clients) and I was wondering if I'm doing some things wrong.
>
> Firstly,  I'm doing all my packet processing + sending of replies in
> tcp_recv callback. Is this normal, or shall I save the data somehow and
> process it later. My idea is that this blocks the main thread and the next
> packets are delayed. But I don't know this for sure.
>
> I don't understand how I can use multiple threads using this API. It's
> callback based, so where do I create the threads? Let's say I want to
> process the entire callback saved using tcp_recv on a separate thread. Is
> that possible or do I have to create a new thread inside the callback?
>
> The application I'm using is a vpn server that has to inspect the packets
> (so I do that in tcp_recv), see where to forward one packet (from a list of
> connected clients to the server) and send that data to the client. I saw
> that each tcp_pcb has a unique memory address (obv.), so I save that in an
> array and if the client IP/MAC is the same as on in the array, I send my
> data to that pcb from the array. I can also send broadcasts (if

[lwip-users] TCP Raw API questions about efficiency and threads

2016-06-02 Thread Pîrvu Mihai
Hello guys, I've just ported my application to tcp raw API and I was
wondering a few things.

I've noticed that the performance is a bit too bad (300-500 ms for pings,
between local clients) and I was wondering if I'm doing some things wrong.

Firstly,  I'm doing all my packet processing + sending of replies in
tcp_recv callback. Is this normal, or shall I save the data somehow and
process it later. My idea is that this blocks the main thread and the next
packets are delayed. But I don't know this for sure.

I don't understand how I can use multiple threads using this API. It's
callback based, so where do I create the threads? Let's say I want to
process the entire callback saved using tcp_recv on a separate thread. Is
that possible or do I have to create a new thread inside the callback?

The application I'm using is a vpn server that has to inspect the packets
(so I do that in tcp_recv), see where to forward one packet (from a list of
connected clients to the server) and send that data to the client. I saw
that each tcp_pcb has a unique memory address (obv.), so I save that in an
array and if the client IP/MAC is the same as on in the array, I send my
data to that pcb from the array. I can also send broadcasts (if mac is
FF:FF:FF:FF:FF:FF). This is the "processing" that is done.

One bad thing is that I copy the entire pbuf into a local buffer and free
it (I saw that there's some idea to save it for later use, would love to
see some examples on that).
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Multi threaded TCP model

2016-03-19 Thread Pîrvu Mihai
The port I'm using is using 1.3.2 version, so I doubt there's this option
from the unreleased branch. I'll try to follow how select is implemented
and see if there's a non-blocking way to check if a packet has arived on a
socket/session so I don't block the thread indefinitely.

On Fri, Mar 18, 2016 at 8:56 PM, goldsi...@gmx.de <goldsi...@gmx.de> wrote:

> Pîrvu Mihai wrote:
>
>> I've read that different threads cannot call the same socket/netconn
>> session at the same time, so I guess this is where my problem lays.
>>
>
> You can use the fairly new option LWIP_NETCONN_FULLDUPLEX set to 1, which
> in combination with thread-local semaphores
> (LWIP_NETCONN_SEM_PER_THREAD==1) to write from one thread while writing
> from a 2nd thread. Thread-local semaphores might not be easy to implement,
> though, depending on your port.
>
> Simon
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Multi threaded TCP model

2016-03-19 Thread Pîrvu Mihai
Well, I'm developing an application for Xen's MiniOS which is quite a large
project (kind of) and while making a fork of it and trying to port to 1.4.1
sounds tempting, it'd require me to dig some code (but would help me remove
the damned #ifdefs becuase I'm using on Linux 1.4.1).

I'm not using select becuase I wanted to make a netconn implementation
first and then when it works, to reimplement using raw api thinking it's a
1:1 port between the two.

On Fri, Mar 18, 2016 at 9:47 PM, goldsi...@gmx.de <goldsi...@gmx.de> wrote:

> Pîrvu Mihai wrote:
>
>> The port I'm using is using 1.3.2 version
>>
>
> Yikes! There have really been many fixes since then!
>
>> I'll try to follow how select is implemented
>>
>
> Why don't you actually use select? However, there may be bugs in 1.3.2's
> select...
>
>
> Simon
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] Multi threaded TCP model

2016-03-19 Thread Pîrvu Mihai
Hello, I'm developing an application that requires multiple clients to be
kept on separate threads (be it 1 client/thread or thread queue). Those
clients communicate between each other also by using the server application.

I'm using netconn API atm, but I can switch to raw api if that makes more
sense for my problem. At the moment, I'm facing some issues. I've read that
different threads cannot call the same socket/netconn session at the same
time, so I guess this is where my problem lays.

Messages can come from any client at any time, so what I'm doing right now
is make a netconn_read on each thread, and based on the message, that
respective client will send it to another thread's connection.

The problem appears to be, I think, when both client A wants to send a
message to B and B sends a message as well, so the read from thread B and
the write from thread A happens on the same netconn session.

Is there any way I can implement this safely? I tried using locks, but the
problem persists and there's some other problem, when client A tries to
send message to client B, but thread B is blocked reading the message from
client B and he doesn't send any. Thus, thread A blocks waiting for the
lock until B sends a message. Putting the mode as non blocking got me the
same problem as not using any locks (application stops and gdb says that
the threads "exit").

Mihai
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Multi-Threaded netconn API TCP application

2015-09-23 Thread Pîrvu Mihai
Yeah, the problem was that my  MEMP_NUM_NETBUF was set to only 2. I have
increased this and now it works.

Thanks for the help guys, keep the good code running :)

Mihai

On Tue, Sep 22, 2015 at 11:10 PM, Sylvain Rochet 
wrote:

> Hi Darius,
>
>
> On Tue, Sep 22, 2015 at 05:01:27PM +0300, Darius Babrauskas wrote:
> > Hi Mihai,
> >
> > It looks that you have problems with systimeouts. Each tread must have
> > self systimeout stuct.
>
> I disagree, only the lwIP core thread handle timeouts. Maybe your design
> outside of lwIP require a timeout callout system in each thread but
> that's not the case for lwIP.
>
>
> > create_thread("client", client, (void *)_index);
> >
> > //PS: The application runs on Linux atm, using lwip 1.4.0 (last stable
> one), the unix port from contrib directory and the clients connect using
> netcat  .
> > If you using Linux, why you use LWIP?  Are you want testing?
>
> Of course he want to test and understand how to use the stack before
> putting it to a microcontroller with boring flash-time and less debug
> capabilities, and he is right to do so ;-)
>
>
> > It seem to me, that linux port not very good implemented. Maybe for
> > simple testing.
>
> You can't claim that without explaining why, could you tell why it is
> "not very good implemented" ?
>
>
> Sylvain
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Multi-Threaded netconn API TCP application

2015-09-22 Thread Pîrvu Mihai
I may have misinterpreted how the API works, I'll rewrite the code.

On Tue, Sep 22, 2015 at 3:42 PM, Sylvain Rochet <grada...@gradator.net>
wrote:

> Hi Pîrvu,
>
> On Tue, Sep 22, 2015 at 01:19:36PM +0300, Pîrvu Mihai wrote:
> > Thing is that's exctly what I done before this approach. Here's a similar
> > code that I tried, where I create an array of sessions and look for the
> > first one that's available, and use that one to accept a new connection.
> I
> > have exactly the same problem: First client connects well, we can
> > communicate, I receive his messages and I can send him messages back.
> >
> > Then, whenever a second client tries to connect it's automatically
> > disconnected. Also, if i disconnect the first client and try to connect
> him
> > back, he also can't connect anymore, gets instantly disconnected.
> >
> > Here's a log of what I mean:
> > Connected: 0 //client "0" connects with netcat
> > Received from 0 : a //client sends messages
> > Received from 0 : b
> > Received from 0 : c
> > Connected: 1 //client "1" connects with netcat
> > Disconnected: 1 //disconected immediately
> > Disconnected: 0 //I close the connection of clent "0"
> > Connected: 0 // I try to connect again with client "0"
> > Disconnected: 0 //Same problem as client "1"
> > Connected: 0
> > Disconnected: 0
> >
> > Here's the current code: http://pastebin.com/1eQd9dzQ
>
> Erm.
>
>
> > static struct netconn *session[100];
> > static int free_session[100];
>
> You already have a table of pointers, pointers have a special value
> (NULL) which means the entry is unused/unset, therefore having a boolean
> table of free/used pointers associated to a pointer table is redundant.
>
>
> >/* Wait for the internal semaphore so we know when a new
> connection arived */
> >sys_arch_sem_wait(>acceptmbox->not_empty, 0);
>
> I'm not an expert of the netconn API, but it is for sure a violation of
> the lwIP threading model. You should never use "struct netconn" internal
> fields in your code, especially *not* the mbox. Since you are using the
> Netconn API in blocking mode, netconn_accept() will wait until a new
> incoming session, I don't even see why you are doing that.
>
>
> Sylvain
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Multi-Threaded netconn API TCP application

2015-09-22 Thread Pîrvu Mihai
Thing is that's exctly what I done before this approach. Here's a similar
code that I tried, where I create an array of sessions and look for the
first one that's available, and use that one to accept a new connection. I
have exactly the same problem: First client connects well, we can
communicate, I receive his messages and I can send him messages back.

Then, whenever a second client tries to connect it's automatically
disconnected. Also, if i disconnect the first client and try to connect him
back, he also can't connect anymore, gets instantly disconnected.

Here's a log of what I mean:
Connected: 0 //client "0" connects with netcat
Received from 0 : a //client sends messages
Received from 0 : b
Received from 0 : c
Connected: 1 //client "1" connects with netcat
Disconnected: 1 //disconected immediately
Disconnected: 0 //I close the connection of clent "0"
Connected: 0 // I try to connect again with client "0"
Disconnected: 0 //Same problem as client "1"
Connected: 0
Disconnected: 0

Here's the current code: http://pastebin.com/1eQd9dzQ

Mihai

On Sun, Sep 20, 2015 at 2:05 PM, Pîrvu Mihai <mihaicristianpi...@gmail.com>
wrote:

> Hello guys, I'm sorry if this was posted before, but i couldn't find an
> answer, so I'm gonna post here in search of one.
>
> I want to create a simple multi-threaded TCP server, that handled each new
> connection on a separate thread. The listener thread will listen on the
> "main" thread, and every connection will create a new thread, that will
> communicate with the session created.
>
> The code I wrote is here: http://pastebin.com/zUuTtfL0
>
> I have dug a little into the lwip API to see how netconn_accept works and
> I saw that it blocks until the "not_empty" semaphore frm the "acceptbox"
> mailbox has something in it.
>
> Now, every time this happens, I create a new thread and the session
> creation is done there, and I block the main thread using the "semaphore"
> variable, so a new connection doesn't happen while I still proces the old
> one.
>
> Now, the problem is pretty much this:
> - I connect the first client, it works just fine
> - When ANY second client tries to join, it automatically gets disconnected
> and the server's console prints: Disconnected: 1, so netconn_recv doesn't
> return ERR_OK.
>
> So my question is:
> - How can I create this multi-threaded enviroment so each client is
> processed in a different thread?
> - Also, what am I doing wrong in my current setup ?
>
> PS: The application runs on Linux atm, using lwip 1.4.0 (last stable one),
> the unix port from contrib directory and the clients connect using netcat
>  .
>
> Mihai
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Multi-Threaded netconn API TCP application

2015-09-22 Thread Pîrvu Mihai
Thanks, i'll test this too and reply with a conclusion when i am at pc.

I use linux for testing purposes only.
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] Multi-Threaded netconn API TCP application

2015-09-20 Thread Pîrvu Mihai
Hello guys, I'm sorry if this was posted before, but i couldn't find an
answer, so I'm gonna post here in search of one.

I want to create a simple multi-threaded TCP server, that handled each new
connection on a separate thread. The listener thread will listen on the
"main" thread, and every connection will create a new thread, that will
communicate with the session created.

The code I wrote is here: http://pastebin.com/zUuTtfL0

I have dug a little into the lwip API to see how netconn_accept works and I
saw that it blocks until the "not_empty" semaphore frm the "acceptbox"
mailbox has something in it.

Now, every time this happens, I create a new thread and the session
creation is done there, and I block the main thread using the "semaphore"
variable, so a new connection doesn't happen while I still proces the old
one.

Now, the problem is pretty much this:
- I connect the first client, it works just fine
- When ANY second client tries to join, it automatically gets disconnected
and the server's console prints: Disconnected: 1, so netconn_recv doesn't
return ERR_OK.

So my question is:
- How can I create this multi-threaded enviroment so each client is
processed in a different thread?
- Also, what am I doing wrong in my current setup ?

PS: The application runs on Linux atm, using lwip 1.4.0 (last stable one),
the unix port from contrib directory and the clients connect using netcat
 .

Mihai
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] Question regarding how to access a linux lwip application from outside.

2015-08-21 Thread Pîrvu Mihai
Let's say I developed an application that uses the lwip API, on linux using
the contrib/unix/ stuff. I have modified the unixsim application that
comes by default so it serves my purpose.

I have a random server application created with lwip-socket API that runs
on, let's say port  and I have a public ip of let's say 188.99.99.99.

If i were to write this application using the posix API, I could easily
connect to the server at 188.99.99.99:, but using the unix port, it
creates a virtual interface tap0, with a different set of IP and mask
from my public IP from ethernet cable or wi-fi.

My question is, how can i access my application from a different network,
over internet, using my public IP.

Mihai
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Question regarding how to access a linux lwip application from outside.

2015-08-21 Thread Pîrvu Mihai
I see, thanks Sergio. I was doing something like that but I kind of failed
and that's why I went to ask here. I used port forward with the original
simhost application, the simple http server and it only worked if I
accessed my PC with my LAN IP from another PC.

So it'd work if i port forward let's say 192.168.0.101:8080 - 10.0.0.2:80,
but accesing using my 188.xx.xx.xx IP which was kind of weird. I asked
because I thought there might be a more normal way of using lwip.

Obviously, I won't be using my server on Linux, it's just for testing
purposes, I want to use it with Mini-os (which has support for lwip-1.3.2
atm).

I'll read the README you advised me to.

Mihai

On Fri, Aug 21, 2015 at 3:26 PM, Pîrvu Mihai mihaicristianpi...@gmail.com
wrote:

 Let's say I developed an application that uses the lwip API, on linux
 using the contrib/unix/ stuff. I have modified the unixsim application
 that comes by default so it serves my purpose.

 I have a random server application created with lwip-socket API that runs
 on, let's say port  and I have a public ip of let's say 188.99.99.99.

 If i were to write this application using the posix API, I could easily
 connect to the server at 188.99.99.99:, but using the unix port, it
 creates a virtual interface tap0, with a different set of IP and mask
 from my public IP from ethernet cable or wi-fi.

 My question is, how can i access my application from a different network,
 over internet, using my public IP.

 Mihai

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Problems with MiniOS and lwIP (daytime server)

2015-07-28 Thread Pîrvu Mihai
Hello, I still have problems with this. My question is basically:

- How can I connect to a Mini-OS VM using netcat or whatever linux socket
client on a port the VM is listening to ?

Is there a maling list specifically for application-level questions ?


Mihai
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Problems with MiniOS and lwIP (1.3.2) on their daytime server application

2015-07-22 Thread Pîrvu Mihai
Alright, I have fixed this in the sense that I needed to connect with
nectonn_connect to the srerver, rather than using netcat (and linux sockets
for that matter). I realise my client/server application has to use the
lwip API.

I am now stuck with another problem, as I'm trying to compile the client on
linux using the UNIX port from unix/ports/proj/lib, linking the liblwip.so
with my application, it creates a new interface (/dev/tap0) with the
default IP 192.168.1.1. I am currently stuck with how to dynamically set
the IP to that virtual interface it automatically creates.

Well, it's not much of a problem, I'm sure following the call stack will
get me the solution, I just wanted to call the initial issue resolved in
the sense that I now somewhat understand what I must do :)

Mihai

On Sun, Jul 19, 2015 at 6:54 AM, Pîrvu Mihai mihaicristianpi...@gmail.com
wrote:


 Hello, I want to start by saying that I'm really new with the platform
 (like 3 days of research), but i stumbled upon a problem i can't fix. I
 hope this won't be considered spam :)

 Anyway, my problem is pretty simple probably. I'm trying to access the
 daytime server, which is ran default when compiling with lwIP

 I looked inside the source of daytime.c, provitded by Mini OS, and I saw
 that the setting up of an IP address is disabled with an if(0) { ... }
 construct, so I changed that and set my ip to: 10.0.2.10/24  (so it is in
 the same network as Dom0) like this:

 
 start_networking();

 if (1) {
 struct ip_addr ipaddr = { htonl(0x0a00020A) }; //10.0.2.10
 struct ip_addr netmask = { htonl(0xff00) }; // 255.255.255.0
 struct ip_addr gw = { 0 };
 networking_set_addr(ipaddr, netmask, gw);
 }
 

 The compiling is fine (though I also have something to say about this, but
 in the footer of the mail).

 I start the VM, with xl create domain_config, which looks like this:
 kernel = mini-os.gz
 memory = 32
 name = Mini-OS
 on_crash = 'destroy'
 vif=['xenif']

 I go into the console, and it all seems fine:

 .
 mac is 00:16:3e:70:4a:02
 **
 [server] IP 0 netmask 0 gateway 0.
 [server] TCP/IP bringup begins.
 Thread tcpip_thread: pointer: 0x000ca738, stack:
 0x0022
 [tcpip_thread] TCP/IP bringup ends.
 [server] Network is ready.
 [server] Opening connection
 [server] Connection at 00042820


 This is where I'm lost a little. I try to ping 10.0.2.10 and it works!

 root@ubuntuZen:/home/mihai/xen/extras/mini-os# ping 10.0.2.10
 PING 10.0.2.10 (10.0.2.10) 56(84) bytes of data.
 64 bytes from 10.0.2.10: icmp_seq=1 ttl=255 time=0.546 ms
 64 bytes from 10.0.2.10: icmp_seq=2 ttl=255 time=0.189 ms
 64 bytes from 10.0.2.10: icmp_seq=3 ttl=255 time=0.142 ms
 64 bytes from 10.0.2.10: icmp_seq=4 ttl=255 time=0.247 ms

 But when I try to connect to 10.0.2.10:13 nothing happens.
 My netcat just hangs, but it hangs on all ports, not just 13. I have to
 ctrl+c it so it dies, so it's not like the connection is rejected. But, on
 the console, nothing is printed. I even put a little print code after the

 session = netconn_accept(listener);

 part, so it shows me when that function has returned a session, thus the
 connection is understood, but it never gets there, the function just blocks
 and never returns.

 Here's the entire code, if you think I've done something wrong:
 http://pastebin.com/riuh5n0w

 I tried to look with nmap, and all ports are closed.

 Sorry if the question is 'stupid', I'm new to both projects (mini os and
 lwip) and I'm just trying to learn.


 Mihai

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] Fwd: Problems with MiniOS and lwIP (daytime server)

2015-07-18 Thread Pîrvu Mihai
Hello, I want to start by saying that I'm really new with the platform
(like 3 days of research), but i stumbled upon a problem i can't fix. I
hope this won't be considered spam :)

Anyway, my problem is pretty simple probably. I'm trying to access the
daytime server, which is ran default when compiling with lwIP

I looked inside the source of daytime.c, provitded by Mini OS, and I saw
that the setting up of an IP address is disabled with an if(0) { ... }
construct, so I changed that and set my ip to: 10.0.2.10/24  (so it is in
the same network as Dom0) like this:


start_networking();

if (1) {
struct ip_addr ipaddr = { htonl(0x0a00020A) }; //10.0.2.10
struct ip_addr netmask = { htonl(0xff00) }; // 255.255.255.0
struct ip_addr gw = { 0 };
networking_set_addr(ipaddr, netmask, gw);
}


The compiling is fine (though I also have something to say about this, but
in the footer of the mail).

I start the VM, with xl create domain_config, which looks like this:
kernel = mini-os.gz
memory = 32
name = Mini-OS
on_crash = 'destroy'
vif=['xenif']

I go into the console, and it all seems fine:

.
mac is 00:16:3e:70:4a:02
**
[server] IP 0 netmask 0 gateway 0.
[server] TCP/IP bringup begins.
Thread tcpip_thread: pointer: 0x000ca738, stack:
0x0022
[tcpip_thread] TCP/IP bringup ends.
[server] Network is ready.
[server] Opening connection
[server] Connection at 00042820


This is where I'm lost a little. I try to ping 10.0.2.10 and it works!

root@ubuntuZen:/home/mihai/xen/extras/mini-os# ping 10.0.2.10
PING 10.0.2.10 (10.0.2.10) 56(84) bytes of data.
64 bytes from 10.0.2.10: icmp_seq=1 ttl=255 time=0.546 ms
64 bytes from 10.0.2.10: icmp_seq=2 ttl=255 time=0.189 ms
64 bytes from 10.0.2.10: icmp_seq=3 ttl=255 time=0.142 ms
64 bytes from 10.0.2.10: icmp_seq=4 ttl=255 time=0.247 ms

But when I try to connect to 10.0.2.10:13 nothing happens.
My netcat just hangs, but it hangs on all ports, not just 13. I have to
ctrl+c it so it dies, so it's not like the connection is rejected. But, on
the console, nothing is printed. I even put a little print code after the

session = netconn_accept(listener);

part, so it shows me when that function has returned a session, thus the
connection is understood, but it never gets there, the function just blocks
and never returns.

Here's the entire code, if you think I've done something wrong:
http://pastebin.com/riuh5n0w

I tried to look with nmap, and all ports are closed.

Sorry if the question is 'stupid', I'm new to both projects (mini os and
lwip) and I'm just trying to learn.


Mihai
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

[lwip-users] Problems with MiniOS and lwIP (1.3.2) on their daytime server application

2015-07-18 Thread Pîrvu Mihai
Hello, I want to start by saying that I'm really new with the platform
(like 3 days of research), but i stumbled upon a problem i can't fix. I
hope this won't be considered spam :)

Anyway, my problem is pretty simple probably. I'm trying to access the
daytime server, which is ran default when compiling with lwIP

I looked inside the source of daytime.c, provitded by Mini OS, and I saw
that the setting up of an IP address is disabled with an if(0) { ... }
construct, so I changed that and set my ip to: 10.0.2.10/24  (so it is in
the same network as Dom0) like this:


start_networking();

if (1) {
struct ip_addr ipaddr = { htonl(0x0a00020A) }; //10.0.2.10
struct ip_addr netmask = { htonl(0xff00) }; // 255.255.255.0
struct ip_addr gw = { 0 };
networking_set_addr(ipaddr, netmask, gw);
}


The compiling is fine (though I also have something to say about this, but
in the footer of the mail).

I start the VM, with xl create domain_config, which looks like this:
kernel = mini-os.gz
memory = 32
name = Mini-OS
on_crash = 'destroy'
vif=['xenif']

I go into the console, and it all seems fine:

.
mac is 00:16:3e:70:4a:02
**
[server] IP 0 netmask 0 gateway 0.
[server] TCP/IP bringup begins.
Thread tcpip_thread: pointer: 0x000ca738, stack:
0x0022
[tcpip_thread] TCP/IP bringup ends.
[server] Network is ready.
[server] Opening connection
[server] Connection at 00042820


This is where I'm lost a little. I try to ping 10.0.2.10 and it works!

root@ubuntuZen:/home/mihai/xen/extras/mini-os# ping 10.0.2.10
PING 10.0.2.10 (10.0.2.10) 56(84) bytes of data.
64 bytes from 10.0.2.10: icmp_seq=1 ttl=255 time=0.546 ms
64 bytes from 10.0.2.10: icmp_seq=2 ttl=255 time=0.189 ms
64 bytes from 10.0.2.10: icmp_seq=3 ttl=255 time=0.142 ms
64 bytes from 10.0.2.10: icmp_seq=4 ttl=255 time=0.247 ms

But when I try to connect to 10.0.2.10:13 nothing happens.
My netcat just hangs, but it hangs on all ports, not just 13. I have to
ctrl+c it so it dies, so it's not like the connection is rejected. But, on
the console, nothing is printed. I even put a little print code after the

session = netconn_accept(listener);

part, so it shows me when that function has returned a session, thus the
connection is understood, but it never gets there, the function just blocks
and never returns.

Here's the entire code, if you think I've done something wrong:
http://pastebin.com/riuh5n0w

I tried to look with nmap, and all ports are closed.

Sorry if the question is 'stupid', I'm new to both projects (mini os and
lwip) and I'm just trying to learn.


Mihai
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users