curl-library
Re: read function callback problem while processing telnet:// URL
Date: Fri, 11 Jan 2002 18:45:21 +0100
Hello!
I can see that you define URL to be "ftp://localhost". Shouldn't
it be "telnet://localhost"?
/Linus
On Fri, 11 Jan 2002 11:43:46 +0100, Ondrej_BOSIK_at_tatrabanka.sk wrote:
>
>
> Hi,
>
> I've got a problem with processing telnet url in form "
> telnet://tatrasun2". The problem is, that I want my application to
> communicate
> automaticaly via the telnet protocol on the remote host. I've set
> up read and
> write callback functions. Since write function is called properly,
> read function
> is never called. I've tried to deubg and view source but I can't
> figure out what
> is the problem.My code follows:
>
> #include <iostream>
> #include <stdio.h>
>
> #include <curl/curl.h>
> #include <curl/types.h>
> #include <curl/easy.h>
>
> using namespace std;
>
> const char* URL = "ftp://localhost";
> FILE* iFile;
> FILE* oFile;
> CURLcode res;
>
> size_t write_data(void* ptr,size_t size, size_t nmemb, void*
> stream) {
> char* cp = (char*)ptr;
> cout << "write_data(" << cp[0] << "," << size << "," << nmemb
> << ")" <<
> endl;
> return fwrite(ptr,size,nmemb,(FILE*)stream);
> }
>
> size_t read_data(void* ptr,size_t size, size_t nmemb, void* stream)
> {
> cout << "read_data being called" << endl;
> return fread(ptr,size,nmemb,(FILE*)stream);
> }
>
> int main(int argc,char* argv[]) {
> cout << "CURL try" << endl;
> iFile = fopen("data.in.txt","r");
> if (! iFile) {
> cerr << "Cant open iFile" << endl;
> return 1;
> }
>
> oFile = fopen("data.out.txt","w");
> if (! oFile) {
> cerr << "Cant open oFile" << endl;
> return 2;
> }
>
> CURL* curlHandle = curl_easy_init();
>
> res = curl_easy_setopt(curlHandle,CURLOPT_URL,URL);
> cout << "res = " << res << endl;
>
> res = curl_easy_setopt(curlHandle,CURLOPT_INFILE,iFile);
> cout << "res = " << res << endl;
>
> res =
> curl_easy_setopt(curlHandle,CURLOPT_READFUNCTION,read_data);
> cout << "res = " << res << endl;
>
> res = curl_easy_setopt(curlHandle,CURLOPT_FILE,oFile);
> cout << "res = " << res << endl;
>
> res =
> curl_easy_setopt(curlHandle,CURLOPT_WRITEFUNCTION,write_data);
> cout << "res = " << res << endl;
>
> res = curl_easy_perform(curlHandle);
> cout << "res = " << res << endl;
>
> curl_easy_cleanup(curlHandle);
>
> fclose(iFile);
> fclose(oFile);
>
> return 0;
> }
>
> Could anyone tell me what I am doing wrong ? (And how to achieve
> decided
> functionality)
>
> Ondrej
>
>
>
>
-- Linus Nielsen Feltzing, linus_at_haxx.seReceived on 2002-01-11