read and write to same socket (TCP) using select

前端 未结 4 461
悲&欢浪女
悲&欢浪女 2020-12-16 18:00

We\'re writing a client and a server to do (what I thought was) pretty simple network communications. Mulitple clients connect to the server which then is supposed to send

4条回答
  •  旧巷少年郎
    2020-12-16 18:30

    I seem to recall a trick about creating and sharing a read/write filedescriptor between the network thread and the main thread that is added to the descriptors in the select call. This fd has one byte written to it by the main thread when it has something to send. The write wakes up network thread from the select call and the network thread is then grabs the data from a shared buffer and writes it to the network then go back to sleep in the select.

    Sorry if that's a bit vague and lacking of code ... and my memory may be incorrect.. so others may have to guide you further.

提交回复
热议问题