curl-library
curl_easy_perform never returns for telnet connection
Date: Thu, 6 Aug 2009 12:03:22 +0400
Hello!
I am just a newbie in libcurl usage and I've faced with strange issue
for me. When I establish a telnet connection via libcurl this
connection is established succesfully but curl_easy_perform call never
returns. Here is outline of my code.
_______________________________________
// callbacks
size_t curl_callback_write_data(
void* buffer, size_t size, size_t nmemb, void* userp
) {
...
};
size_t curl_callback_read_data(
void* buf, size_t size, size_t nmemb, void* userp
) {
...
};
// Part of initialization and connection establishment method
// Obtain CURL handle for connection
CurlHandle = curl_easy_init();
if (0 == CurlHandle) {
APP_THROW(stateFatalCurl, "Unable to get CURL handle");
}
// Set buffer pointer to store CURL error messages
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_ERRORBUFFER, CurlErrBuf);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
// Disable signal handling
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_NOSIGNAL, 1L);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
/* According to documentation in is an HTTP option,
but most of telnet examples set this */
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_FAILONERROR, 1);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
// Additional tune for telnet protocol
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_TCP_NODELAY, 1L);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
// Set URI of the DAN terminal server
ss << "telnet://" << Hostname;
if (0 != Port) ss << ":" << Port;
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_URL, ss.str().c_str());
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
// Set telnet authentication parameters
if ("" != Login) {
str = Login + ":" + Password;
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_USERPWD, str.c_str());
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
}
#ifdef DEBUG
// Enable CURL verbosity for debug
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_VERBOSE, 1);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
#endif // #ifdef DEBUG
/* Set a pointer on so called 'stream'. This pointer will passed as
a stream id to the callback write function and will be used to
rmine exact object for whom this call belongs */
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_WRITEDATA, this);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
// Register callback for data writing
curl_code = curl_easy_setopt(
CurlHandle, CURLOPT_WRITEFUNCTION, curl_callback_write_data);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
/* Set a pointer on so called 'stream'. This pointer will passed as
a stream id to the callback read function and will be used to
determine exact object for whom this call belongs */
curl_code = curl_easy_setopt(CurlHandle, CURLOPT_READDATA, this);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
// Register callback for data reading
curl_code = curl_easy_setopt(
CurlHandle, CURLOPT_READFUNCTION, curl_callback_read_data);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
// Establish connection
curl_code = curl_easy_perform(CurlHandle);
if (CURLE_OK != curl_code) {
APP_THROW(stateFatalCurl, curl_easy_strerror(curl_code));
}
TRACE();
___________________________________________________________________
On execution of this code I see that connection is established with
success. Moreover curl_callback_write_data callback is called multiply
times and receives expected data. But final TRACE() macro is never
executed.
My libcurl version is 7.14.0.
Have anybody any idea why this happens?
Thank you!
-- /vap/Received on 2009-08-06