{"id":4145,"date":"2012-09-03T23:13:19","date_gmt":"2012-09-03T21:13:19","guid":{"rendered":"http:\/\/daniel.haxx.se\/blog\/?p=4145"},"modified":"2024-09-03T08:28:00","modified_gmt":"2024-09-03T06:28:00","slug":"introducing-curl_multi_wait","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2012\/09\/03\/introducing-curl_multi_wait\/","title":{"rendered":"Introducing curl_multi_wait"},"content":{"rendered":"\n<p><strong>Facebook contributes fix to libcurl&#8217;s <a href=\"http:\/\/curl.haxx.se\/libcurl\/c\/libcurl-multi.html\">multi interface<\/a> to overcome problem with more than 1024 file descriptors.<\/strong><\/p>\n\n\n\n<p>When we introduced the multi interface to libcurl about (what feels like) one hundred years ago, we went with simple in some ways. One way it shows: an application that wants to do many transfers in parallel asks libcurl to do it, and then it extracts the set of file descriptors (sockets!) from libcurl (using <a href=\"http:\/\/curl.haxx.se\/libcurl\/c\/curl_multi_fdset.html\">curl_multi_fdset<\/a>) to wait for as plain <em>fd_sets<\/em>. fd_set is the variable type made for <a href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/007908775\/xsh\/select.html\">select()<\/a>.\u00a0This API choice made applications pretty much forced to use select. <a href=\"http:\/\/daniel.haxx.se\/docs\/poll-vs-select.html\">select() has its fair share of problems<\/a>, where possibly the biggest one is that it has problems with file descriptors > 1024.<\/p>\n\n\n\n<p>Later on we introduced an enhanced version of the multi interface for libcurl that allows an application to use whatever method it pleases. I tend to refer to that variation as the <em>multi_socket<\/em> API after its main function <a href=\"http:\/\/curl.haxx.se\/libcurl\/c\/curl_multi_socket_action.html\">curl_multi_socket_action<\/a>. That&#8217;s the high performance, event-driven API.<\/p>\n\n\n\n<p>As you may be aware, event-driven code make things a bit more complicated at times so many people still prefer to use the older and simpler multi interface and thus they were forced to remain using select(). But now that era has ended. Now&#8230;<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"http:\/\/curl.haxx.se\/libcurl\/c\/curl_multi_wait.html\">curl_multi_wait()<\/a> is introduced!<\/p>\n\n\n\n<p>This poll(3)-like function basically works as a replacement for <a href=\"http:\/\/curl.haxx.se\/libcurl\/c\/curl_multi_fdset.html\">curl_multi_fdset()<\/a> + select(). Starting in <strong>libcurl 7.28.0<\/strong> (strictly speaking in commit\u00a0<a href=\"https:\/\/github.com\/bagder\/curl\/commit\/de24d7bd4c03ea3eeba928edc9ae9e7a826c67c8\">de24d7bd4c03ea3<\/a>), this is a function that any application can use for this purpose, and thus avoid the problem with many file descriptors.<\/p>\n\n\n\n<p>This new function doesn&#8217;t use any struct from the &#8220;real&#8221; poll() or associated headers to make sure that it works even for systems without a real <a href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/007908799\/xsh\/poll.html\">poll()<\/a> implementation. It instead uses private curl versions of both the struct and the defines used. An application can of course also tell <a href=\"http:\/\/curl.haxx.se\/libcurl\/c\/curl_multi_wait.html\">curl_multi_wait<\/a> to wait for a set of private file descriptors, just like poll() or select().<\/p>\n\n\n\n<p>The patch set that brought this function was provided by Sara Golemon, a friend from from a <a href=\"http:\/\/www.libssh2.org\/\">related project<\/a>&#8230;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/curl.haxx.se\/\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"110\" src=\"http:\/\/daniel.haxx.se\/blog\/wp-content\/uploads\/2007\/09\/curl-keywords300.jpg\" alt=\"cURL\" class=\"wp-image-64\" title=\"cURL\"\/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Facebook contributes fix to libcurl&#8217;s multi interface to overcome problem with more than 1024 file descriptors. When we introduced the multi interface to libcurl about (what feels like) one hundred years ago, we went with simple in some ways. One way it shows: an application that wants to do many transfers in parallel asks libcurl &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2012\/09\/03\/introducing-curl_multi_wait\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Introducing curl_multi_wait<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[33,424,144],"class_list":["post-4145","post","type-post","status-publish","format-standard","hentry","category-curl","tag-curl-and-libcurl","tag-libssh2","tag-sockets"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/4145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=4145"}],"version-history":[{"count":30,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/4145\/revisions"}],"predecessor-version":[{"id":25457,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/4145\/revisions\/25457"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=4145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=4145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=4145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}