On Wed, 3 May 2017, Pahome Chen wrote:

The reason what I do that( add while(1) ) is to verify the sock_cb activate after the events exits. If the application always check the fifo in the event loop without leaving, the sock_cb never activates.

I don't understand a word of this description.

Can we take a step back and instead discuss exactly how the API works and what you're trying to do? I rather avoid discussing specifics about the example code, let's talk how the API works instead!

I figure you want to add an easy handle to a multi handle, and then have the regular event loop continue and transfer all the parallel transfers?

Have you read the "Driving with the multi_socket interface" chapter in the curl book? If you haven't, I really urge you to start there:

  https://ec.haxx.se/libcurl-drive-multi-socket.html

If I replace the fifo with a socket, the sock_cb will activate after
waiting all message received completely.

The CURLMOPT_SOCKETFUNCTION callback gets called by libcurl when you've called curl_multi_socket_action(). That callback then gets told what sockets to wait for on the behalf of libcurl.

That makes me hardly receive message and handle the message(such as download the message requested) asynchronously.

When you use the event-based API, you should ask your event library to wait for all sockets/file descriptors you want to handle in parallel and as soon as there's activity on any of them you act. One or more of hose file descriptors can be your own application communications, such as reading from a fifo or a socket, and you can then in there add transfers to the libcurl multi handle if you want.

Maybe I need to try other interface to finish my plan !?

libcurl supports unlimted parallel transfers in the same thread using either the normal multi interface or the event-based multi_socket interface. So you actually don't get any paritularly different set of features really by changing API.

Which one of these to use is up to you. The event-based one will scale significantly better when you grow the number of parallel connections up to the hundreds or so, but it is also more complicated to understand and use (as anything event-based tends to be).

--

 / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html

Reply via email to