curl/lib
Daniel Stenberg e85e30546c Roland Blom filed bug report #1481217
(http://curl.haxx.se/bug/view.cgi?id=1481217), with follow-ups by Michele Bini
and David Byron. libcurl previously wrongly used GetLastError() on windows to
get error details after socket-related function calls, when it really should
use WSAGetLastError() instead.

When changing to this, the former function Curl_ourerrno() is now instead
called Curl_sockerrno() as it is necessary to only use it to get errno from
socket-related functions as otherwise it won't work as intended on Windows.
2006-05-04 22:39:47 +00:00
..
.cvsignore
amigaos.c Made the copyright year match the latest modification's year. 2006-01-09 13:17:14 +00:00
amigaos.h Made the copyright year match the latest modification's year. 2006-01-09 13:17:14 +00:00
arpa_telnet.h
base64.c
base64.h
ca-bundle.crt
config-amigaos.h
config-mac.h
config-riscos.h
config-tpf.h First commit of David McCreedy's EBCDIC and TPF changes. 2006-04-07 21:50:47 +00:00
config-win32.h Added support for Salford-C under Win32 (scc). HAVE_MALLOC_H and 2006-04-26 17:11:05 +00:00
config-win32ce.h Added support for Salford-C under Win32 (scc). HAVE_MALLOC_H and 2006-04-26 17:11:05 +00:00
config.dj djgpp has <process.h> too. 2006-04-26 17:15:57 +00:00
connect.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
connect.h Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
content_encoding.c Paul Querna fixed libcurl to better deal with deflate content encoding when 2006-04-25 20:49:40 +00:00
content_encoding.h
cookie.c
cookie.h Made the copyright year match the latest modification's year. 2006-01-09 13:17:14 +00:00
curllib.dsw
curlx.h
dict.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
dict.h
easy.c First commit of David McCreedy's EBCDIC and TPF changes. 2006-04-07 21:50:47 +00:00
easyif.h First commit of David McCreedy's EBCDIC and TPF changes. 2006-04-07 21:50:47 +00:00
escape.c First commit of David McCreedy's EBCDIC and TPF changes. 2006-04-07 21:50:47 +00:00
escape.h First commit of David McCreedy's EBCDIC and TPF changes. 2006-04-07 21:50:47 +00:00
file.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
file.h
formdata.c Fixed signed/unsigned convertion errors in Salford-C. 2006-04-26 17:26:22 +00:00
formdata.h
ftp.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
ftp.h First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
getenv.c Made the copyright year match the latest modification's year. 2006-01-09 13:17:14 +00:00
getinfo.c David McCreedy added CURLINFO_FTP_ENTRY_PATH to export the FTP entry path 2006-03-21 22:30:03 +00:00
getinfo.h
gtls.c Mark Eichin submitted bug report #1480821 2006-05-04 06:00:40 +00:00
gtls.h
hash.c First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
hash.h
hostares.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
hostasyn.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
hostip4.c Use the HAVE_MALLOC_H and HAVE_PROCESS_H defines 2006-04-26 17:23:28 +00:00
hostip6.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
hostip.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
hostip.h added docs and removed proto 2006-04-11 07:22:55 +00:00
hostsyn.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
hostthre.c Use the HAVE_MALLOC_H and HAVE_PROCESS_H defines 2006-04-26 17:23:28 +00:00
http_chunks.c
http_chunks.h
http_digest.c
http_digest.h
http_negotiate.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
http_negotiate.h
http_ntlm.c readint_le() not needed in USE_WINDOWS_SSPI code. 2006-04-08 11:04:53 +00:00
http_ntlm.h only enable NTLM if HTTP and NTLM is not disabled, and if NTLM is disabled 2005-11-23 11:51:31 +00:00
http.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
http.h First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
if2ip.c
if2ip.h build fix for Interix 2006-03-04 22:39:31 +00:00
inet_ntoa_r.h
inet_ntop.c Replaced nonstandard u_char and u_int types 2005-12-08 22:59:58 +00:00
inet_ntop.h Yang Tse: fixes the use of Curl_inet_ntop and Curl_inet_pton with no 2005-11-25 22:20:02 +00:00
inet_pton.c Replaced nonstandard u_char and u_int types 2005-12-08 22:59:58 +00:00
inet_pton.h Yang Tse's changes to provide an inet_pton() proto for the platforms who 2005-11-28 20:21:35 +00:00
krb4.c updated source header 2006-01-26 10:39:25 +00:00
krb4.h
ldap.c Use the HAVE_MALLOC_H and HAVE_PROCESS_H defines 2006-04-26 17:23:28 +00:00
ldap.h
libcurl.def
libcurl.framework.make
libcurl.imp there's an curl_easy_unescape too now 2006-04-18 09:23:03 +00:00
libcurl.plist
libcurl.rc
llist.c
llist.h
Makefile.am added README.multi_socket 2006-04-10 14:54:12 +00:00
makefile.amiga
Makefile.b32
makefile.dj
Makefile.inc First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
Makefile.m32
Makefile.netware removed -fpack-struct because gcc4 seems to know its obsolete and warns... 2006-04-20 10:26:51 +00:00
Makefile.riscos
Makefile.vc6 added splay 2006-04-12 18:12:46 +00:00
Makefile.Watcom Added splay.c. 2006-04-12 14:01:21 +00:00
md5.c
md5.h
memdebug.c
memdebug.h
memory.h
mprintf.c
msvcproj.foot
msvcproj.head
multi.c Fixed signed/unsigned convertion errors in Salford-C. 2006-04-26 17:26:22 +00:00
multiif.h First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
netrc.c
netrc.h
nwlib.c
parsedate.c fix questionable compare 2005-12-30 00:35:21 +00:00
parsedate.h
progress.c
progress.h
README.ares
README.curlx
README.encoding Fixed a lingering omission of gzip support. 2005-12-08 18:59:19 +00:00
README.hostip
README.httpauth
README.memoryleak
README.multi_socket each socket is used by exactly one easy handle, but of course each easy handle 2006-04-21 13:40:07 +00:00
security.c
select.c Fixed signed/unsigned convertion errors in Salford-C. 2006-04-26 17:26:22 +00:00
select.h First commit of David McCreedy's EBCDIC and TPF changes. 2006-04-07 21:50:47 +00:00
sendf.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
sendf.h
setup.h Added support for Salford-C under Win32 (scc). HAVE_MALLOC_H and 2006-04-26 17:11:05 +00:00
share.c
share.h Added support for Salford-C under Win32 (scc). HAVE_MALLOC_H and 2006-04-26 17:11:05 +00:00
sockaddr.h
speedcheck.c First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
speedcheck.h
splay.c First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
splay.h First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
sslgen.c Xavier Bouchoux made the SSL connection non-blocking for the multi interface 2006-03-21 21:54:44 +00:00
sslgen.h Xavier Bouchoux made the SSL connection non-blocking for the multi interface 2006-03-21 21:54:44 +00:00
ssluse.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
ssluse.h Xavier Bouchoux made the SSL connection non-blocking for the multi interface 2006-03-21 21:54:44 +00:00
strequal.c
strequal.h
strerror.c Added revision ID-tag. 2006-04-26 17:27:36 +00:00
strerror.h
strtok.c
strtok.h
strtoofft.c Made the copyright year match the latest modification's year. 2006-01-09 13:17:14 +00:00
strtoofft.h
telnet.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
telnet.h
tftp.c Roland Blom filed bug report #1481217 2006-05-04 22:39:47 +00:00
tftp.h
timeval.c Made the copyright year match the latest modification's year. 2006-01-09 13:17:14 +00:00
timeval.h Made the copyright year match the latest modification's year. 2006-01-09 13:17:14 +00:00
transfer.c David McCreedy brought line end conversions when doing FTP ASCII 2006-04-26 07:40:37 +00:00
transfer.h First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
url.c First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
url.h First curl_multi_socket() commit. Should primarily be considered as an internal 2006-04-10 15:00:53 +00:00
urldata.h crlf_conversions needs to be a curl_off_t for ASCII transfers > 4GB on 32bit 2006-04-26 13:08:12 +00:00
version.c CURL_VERSION_CONV is returned by curl_version_info if libcurl has been built 2006-04-19 09:03:21 +00:00

Implementation of the curl_multi_socket API

  Most of the design decisions and debates about this new API have already
  been held on the curl-library mailing list a long time ago so I had a basic
  idea on what approach to use. The main ideas of the new API are simply:

   1 - The application can use whatever event system it likes as it gets info
       from libcurl about what file descriptors libcurl waits for what action
       on. (The previous API returns fd_sets which is very select()-centric).

   2 - When the application discovers action on a single socket, it calls
       libcurl and informs that there was action on this particular socket and
       libcurl can then act on that socket/transfer only and not care about
       any other transfers. (The previous API always had to scan through all
       the existing transfers.)

  The idea is that curl_multi_socket() calls a given callback with information
  about what socket to wait for what action on, and the callback only gets
  called if the status of that socket has changed.

  In the API draft from before, we have a timeout argument on a per socket
  basis and we also allowed curl_multi_socket() to pass in an 'easy handle'
  instead of socket to allow libcurl to shortcut a lookup and work on the
  affected easy handle right away. Both these turned out to be bad ideas.

  The timeout argument was removed from the socket callback since after much
  thinking I came to the conclusion that we really don't want to handle
  timeouts on a per socket basis. We need it on a per transfer (easy handle)
  basis and thus we can't provide it in the callbacks in a nice way. Instead,
  we have to offer a curl_multi_timeout() that returns the largest amount of
  time we should wait before we call the "timeout action" of libcurl, to
  trigger the proper internal timeout action on the affected transfer. To get
  this to work, I added a struct to each easy handle in which we store an
  "expire time" (if any). The structs are then "splay sorted" so that we can
  add and remove times from the linked list and yet somewhat swiftly figure
  out 1 - how long time there is until the next timer expires and 2 - which
  timer (handle) should we take care of now. Of course, the upside of all this
  is that we get a curl_multi_timeout() that should also work with old-style
  applications that use curl_multi_perform().

  The easy handle argument was removed fom the curl_multi_socket() function
  because having it there would require the application to do a socket to easy
  handle conversion on its own. I find it very unlikely that applications
  would want to do that and since libcurl would need such a lookup on its own
  anyway since we didn't want to force applications to do that translation
  code (it would be optional), it seemed like an unnecessary option.

  Instead I created an internal "socket to easy handles" hash table that given
  a socket (file descriptor) return the easy handle that waits for action on
  that socket.  This hash is made using the already existing hash code
  (previously only used for the DNS cache).

  To make libcurl be able to report plain sockets in the socket callback, I
  had to re-organize the internals of the curl_multi_fdset() etc so that the
  conversion from sockets to fd_sets for that function is only done in the
  last step before the data is returned. I also had to extend c-ares to get a
  function that can return plain sockets, as that library too returned only
  fd_sets and that is no longer good enough. The changes done to c-ares have
  been committed and are available in the c-ares CVS repository destined to be
  included in the upcoming c-ares 1.3.1 release.

  The 'shiper' tool is the test application I wrote that uses the new
  curl_multi_socket() in its current state. It seems to be working and it uses
  the API as it is documented and supposed to work. It is still using
  select(), because I needed that during development (like until I had the
  socket hash implemented etc) and because I haven't yet learned how to use
  libevent or similar.

  The hiper/shiper tools are very simple and initiates lots of connections and
  have them running for the test period and then kills them all.

  Since I wasn't done with the implementation until early January I haven't
  had time to run very many measurements and checks, but I have done a few
  runs with up to a few hundred connections (with a single active one). The
  curl_multi_socket() invoke then takes 3-6 microseconds in average (using the
  read-only-1-byte-at-a-time hack). If this number does increase a lot when we
  add connections, it certainly matches my in my opinion very ambitious goal.
  We are now below the 60 microseconds "per socket action" goal. It is
  destined to be somewhat higher the more connections we have since the hash
  table gets more populated and the splay tree will grow etc.

  Some tests at 7000 and 9000 connections showed that the socket hash lookup
  is somewhat of a bottle neck. Its current implementation may be a bit too
  limiting. It simply has a fixed-size array, and on each entry in the array
  it has a linked list with entries. So the hash only checks which list to
  scan through. The code I had used so for used a list with merely 7 slots (as
  that is what the DNS hash uses) but with 7000 connections that would make an
  average of 1000 nodes in each list to run through. I upped that to 97 slots
  (I believe a prime is suitable) and noticed a significant speed increase.  I
  need to reconsider the hash implementation or use a rather large default
  value like this. At 9000 connections I was still below 10us per call.

Status Right Now

  The curl_multi_socket() API is implemented according to how it is
  documented.

    http://curl.haxx.se/libcurl/c/curl_multi_socket.html
    http://curl.haxx.se/libcurl/c/curl_multi_timeout.html
    http://curl.haxx.se/libcurl/c/curl_multi_setopt.html

What is Left for the curl_multi_socket API

  1 - More measuring with more extreme number of connections

  2 - More testing with actual URLs and complete from start to end transfers.

  I'm quite sure we don't set expire times all over in the code properly, so
  there is bound to be some timeout bugs left.

  What it really takes is for me to commit the code and to make an official
  release with it so that we get people "out there" to help out testing it.