cURL / Mailing Lists / curl-library / Single Mail

curl-library

Automated telnet problems

From: Pierre Brico <pierre.brico_at_tsdsoftware.eu>
Date: Tue, 10 Mar 2009 22:28:06 +0100

Hello,

I tried to use libcurl to automate telnet procedure in a Windows XP/Vista
environment. I've downloaded the last binary 32bits version of libcurl
(7.19.4 provided by Günter Knauf <eflash%20at%20gmx%20dot%20net>) and I'm
using MinGW to compile the application.

Everything is working fine except two little issues:

1. The timeout option doesn't work. I use the following C statement to set
the timeout:
curl_easy_setopt(ps_ctx->ps_curl, CURLOPT_TIMEOUT, 1L);

If the command which is executed takes more than 1 seconds the connection
should be aborted but nothing happens. Looking the telnet.c source in the
distribution, it seems that the code is different for Unix and Windows and
that in the Windows code, the main loop doesn't manage timeout.

    wait_timeout = INFINITE;

and later

    waitret = WaitForMultipleObjects(obj_count, objs, FALSE, wait_timeout);

Why is it a difference between Windows and Unix behaviour ? It shouldn't be
difficult to place a timeout of 1s for the WaitForMultipleObjects function
and to add a code similar to (the Unix code)

    if(data->set.timeout) {
      struct timeval now; /* current time */
      now = Curl_tvnow();
      if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {
        failf(data, "Time-out");
        code = CURLE_OPERATION_TIMEDOUT;
        keepon = FALSE;
      }
    }

2. My second issue is about the writecallback function. I set it with a call
to
   curl_easy_setopt(ps_ctx->ps_curl, CURLOPT_WRITEFUNCTION, write_callback);

In that function, if the automated procedure detects a failure, the
write_callback returns 0 indicating a failure as the documentation states
it:
"If that amount differs from the amount passed to your function, it'll
signal an error to the library and it will abort the transfer and return
CURLE_WRITE_ERROR."
But the library continues the telnet communication without failure!

Thanks for your help,
Pierre
Received on 2009-03-10