How to implement a full duplex channel over TCP using a single thread?

On the network I am writing, I need to send and receive messages through a TCP socket. Messages can be sent or received at any time, that is, they must work as a full duplex channel.

I managed to implement such a scenario using two threads: the main thread calling send (), and the dedicated thread, which was mostly blocked when recv () was called.

My question is: is it possible to implement the same scenario with a single thread? That is, by registering some callback function?

As a side note: I need to implement this script in C ++, Java and Python.

+3
source share
2 answers

, . API, -. C/++ Python select() -, , - , select(). poll() epoll() API, , . Java API -.

-, , -, (- ), . , .

+4

, , / .

, , , , select(), poll() . , select()/poll(), , , .

0

Source: https://habr.com/ru/post/1785110/


All Articles