cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Converting ssh.c (sftp) to use Curl_setup_transfer()

From: James Housley <jim_at_thehousleys.net>
Date: Tue, 26 Jun 2007 22:10:53 -0400

I did find that this quick hack works:

ssh.c:1490
#if 1
         /* code left here just because this is what this function
will use the
         day libssh2 is improved */
         res = Curl_setup_transfer(conn, FIRSTSOCKET,
                                   data->reqdata.size, FALSE, NULL,
-1, NULL);
         conn->cselect_bits = CURL_CSELECT_IN;
         state(conn, SSH_STOP);
         break;
#endif

But that did make me think. data_pending() in transfer.c has special
code for SCP and SFTP.

static int data_pending(struct connectdata *conn)
{
   /* in the case of libssh2, we can never be really sure that we
have emptied
      its internal buffers so we MUST always try until we get EAGAIN
back */
   return conn->protocol&(PROT_SCP|PROT_SFTP) ||
     Curl_ssl_data_pending(conn, FIRSTSOCKET);
}

I suppose some thing similar could be done in Curl_readwrite() to set
CURL_CSELECT_IN and/or CURL_CSELECT_OUT. Are there any unseen
problems with adding the following code?

Index: lib/transfer.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/transfer.c,v
retrieving revision 1.357
diff -u -r1.357 transfer.c
--- lib/transfer.c 25 Jun 2007 14:17:52 -0000 1.357
+++ lib/transfer.c 27 Jun 2007 02:10:15 -0000
@@ -330,14 +330,22 @@
    /* only use the proper socket if the *_HOLD bit is not set
simultaneously as
       then we are in rate limiting state in that transfer direction */
- if((k->keepon & (KEEP_READ|KEEP_READ_HOLD)) == KEEP_READ)
+ if((k->keepon & (KEEP_READ|KEEP_READ_HOLD)) == KEEP_READ) {
      fd_read = conn->sockfd;
- else
+#if defined(USE_LIBSSH2) && (LIBSSH2_APINO >= 200706012030)
+ if (conn->protocol & (PROT_SCP|PROT_SFTP))
+ select_res |= CURL_CSELECT_IN;
+#endif /* USE_LIBSSH2 && (LIBSSH2_APINO >= 200706012030) */
+ } else
      fd_read = CURL_SOCKET_BAD;
- if((k->keepon & (KEEP_WRITE|KEEP_WRITE_HOLD)) == KEEP_WRITE)
+ if((k->keepon & (KEEP_WRITE|KEEP_WRITE_HOLD)) == KEEP_WRITE) {
      fd_write = conn->writesockfd;
- else
+#if defined(USE_LIBSSH2) && (LIBSSH2_APINO >= 200706012030)
+ if (conn->protocol & (PROT_SCP|PROT_SFTP))
+ select_res |= CURL_CSELECT_OUT;
+#endif /* USE_LIBSSH2 && (LIBSSH2_APINO >= 200706012030) */
+ } else
      fd_write = CURL_SOCKET_BAD;
     if (!select_res) { /* Call for select()/poll() only, if read/
write/error

Jim

--
/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
                      http://www.FreeBSD.org     The Power to Serve
jim@TheHousleys.Net  http://www.TheHousleys.net
---------------------------------------------------------------------
Q: Because it reverses the logical flow of conversation.
A: Why is putting a reply at the top of the message frowned upon?
Received on 2007-06-27