curl-library
Re: Proper way to convert ssh.c to non-blocking
Date: Sun, 10 Jun 2007 23:03:07 +0200 (CEST)
On Sun, 10 Jun 2007, James Housley wrote:
> I know from pervious discussions that once libssh2 works in non-blocking
> mode that ssh.c will need to be converted to run in a state machine to "play
> nice" with the rest of libcurl. I also remember being told that ftp.c is
> not the ideal way it should be done, but I don't remember what was the best
> example of how it should be done.
Actually, ftp.c is a pretty good example (the _really_ bad examples are
tftp.c, file.c, telnet.c and ldap.c). The bad places in ftp.c are hopefully
all marked "BLOCKING". It does feature a pretty complicated state machine that
was implemented and goes a long way in attempting to work nicely non-blocking.
> If I am right for the actual transfers Curl_setup_transfer() would be called
> and then the state machine would run from withing the read and write call
> backs.
Well, the (protocol-specific) read and write functions I would call them! :-)
(not callbacks)
> Would the same be done for connect?
For the connect phase, you can view the ftp.c example for how it does it. The
same function will simply be called repeatedly until it sets *done = TRUE.
> Below is a highly edited version of the connect only showing the routines
> that can block. Do I just do an initial transfer setup with unknown size
> for connect?
No, the connect phase is only connecting (and authenticating) to the host, it
does no transfer. The transfer is inited by the DO-command. The procedure is
like:
1 connect
2 do
3 done
[possibly loop to 2 when another request is done on a persistant connection]
4 disconnect
Most protocols do nothing special on disconnect (except FTP again).
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.htmlReceived on 2007-06-10