(Dec 20, 2019 02:10 PM)aeiro Wrote: yes but shouldn't i keep a dedicated socket open for strictly sending each frame captured to not "clog" up other things and to have true async?
https://github.com/HFaeiro/Lialis/blob/f...w.cpp#L212
Yes i admit i shouldn't have this dedicated remoterecv socket open strictly to receive remote commands. that can easily be done from the original socket.
Here there are my 2 cents:
We all agree that given N client, for sure you should use at least (N + 1) socket on the server side.
So we can say that we have 1
ListenNewClient socket and N
ServeClient sockets that could be used to send/receive simple commands .
Now, answering your question, you can have async both with 1 socket or 20 sockets for client.
In fact the real bottleneck should be:
- Bandwidth: Given you have a 10kbit/s minimum speed, you can have 1 socket sending at 10 kbit/s or you can have 2 socket sending at 1kbit/s and 9kbit/s and it will be the same for the network layer. It's not relevant (and it's also unknown) for the network layer how many socket and which protocol are being sent, they are just bit.
- CPU: Parallelism is capped, we can't run an infinite number of thread and pretend to be executed in an infinite pipeline.
After receiving the data we should think about processing it ASAP. What I mean is that, assuming we got this 10kbit/s of data on the receiver buffer (again, please note that there is no difference between 1 socket and 2 socket), we should be quickly at its elaboration to free the buffer and go on.
So what about the differences?
In real you are introducing some overhead when adding an other thread and socket for the same client.
If you have many thread per client you are losing some CPU cycles for the context switch of threads and the time needed to establish the new TCP connection.
As a personal opinion I think that you could spawn a new thread and open a new socket on the server for some "intensive" communication feature (like a video streaming could be). But just because it could be useful to isolate (logically) different communication channels.
It's useless to say that I would use without any doubt the
ServeClient socket for commands similar to getComputerInfo or getCurrentUser.
As an addition I looked at just some piece of your code, and maybe there are some potential issue with mutex.
Since you are not using lock_guard (which usage is highly suggested when possible), you should be careful on releasing the locks.
For example #178, #183 show some of this cases.
https://github.com/HFaeiro/Lialis/blob/f...e.cpp#L178
And if I got it right (I dat not so much time to do a deep analysis of the code, the lines #208,209 shouldn't be something like:
if(try_lock)
unlock()
to avoid undefined behaviour caused by unlocking an already unlocked mutex?
The last one things I noticed were some nested if that could be avoided by specifying a multiple condition in the head of the if statement or by "anticipating" the failure condition. This is an example applied to your code:
https://pastebin.com/GHQi2RGr
PS: I'm happy that you know uncle Bob too 👍