Event-driven Model in C with Sockets

后端 未结 5 1393
攒了一身酷
攒了一身酷 2021-01-30 14:40

I am really interested in event-driven programming in C especially with sockets so I am going to dedicate some time doing my researches.

Let\'s assume that I want to bui

5条回答
  •  渐次进展
    2021-01-30 15:32

    That kind of TCP servers/clients can be implemented by using select(2) call and non-blocking sockets.

    It is more tricky to use non-blocking sockets than blocking sockets.

    Example:

    connect call usually return -1 immediately and set errno EINPROGRESS when non-blocking socket are used. In this case you should use select to wait when connection is opened or failed. connect may also return 0. This can happen if you create connection to the local host. This way you can serve other sockets, while one socket is opening a TCP connection.

提交回复
热议问题