lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Pîrvu Mihai
Subject: Re: [lwip-users] Multi-Threaded netconn API TCP application
Date: Tue, 22 Sep 2015 15:44:14 +0300

I may have misinterpreted how the API works, I'll rewrite the code.

On Tue, Sep 22, 2015 at 3:42 PM, Sylvain Rochet <address@hidden> 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(&listener->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
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users


reply via email to

[Prev in Thread] Current Thread [Next in Thread]