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").