cURL / Mailing Lists / curl-library / Single Mail

curl-library

Can't connect: how to find out why ?

From: Vincent Penquerc'h <Vincent.Penquerch_at_artworks.co.uk>
Date: Tue, 8 Oct 2002 16:23:19 +0100

Hi,

I've made some code using libcurl, and that works fine at home
(Linux 2.2.10, Apache). However, when compiled on Win32 (Cygwin),
it doesn't. It can't connect to the outside world, though curl
itself can without problem (and without any switches).
It just says:

About to connect() to www.kernel.org:80
Closing connection #0
Error opening http://www.kernel.org/

I would like to know what I can do to get more information on
what is actually failing.

In case there is anything wrong with my code, here is the bit
that initializes libcurl and connects (it's a sample Ogg/Vorbis
streamer).

struct alogg_stream *alogg_start_streaming_url(
  AL_CONST char *url,int (*configurator)(CURL*),size_t block_size
)
{
  struct alogg_stream *stream=NULL;
  alogg_curl_data *data=NULL;
  CURLcode code;

  ASSERT(url);
  if (!url) return NULL;

  /* Allocate a structure to keep track of URL specific data */
  data=malloc(sizeof(alogg_curl_data));
  if (!data) return NULL;
  data->handle=NULL;
  data->multi=NULL;
  data->url=NULL;
  data->size=block_size*2;
  data->block=NULL;
  data->write_pos=0;
  data->read_pos=0;

  /* Allocate the memory we need in this structure */
  data->url=aloggint_strdup(url);
  if (!data->url) goto alogg_start_streaming_url_error;
  data->block=malloc(data->size);
  if (!data->block) goto alogg_start_streaming_url_error;

  /* Initialize cURL */
  data->handle=curl_easy_init();
  if (!data->handle) goto alogg_start_streaming_url_error;

  /* Configure the access to the specified URL */
  code=curl_easy_setopt(data->handle,CURLOPT_URL,data->url);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_NOPROGRESS,1);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_FAILONERROR,1);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_WRITEFUNCTION,&curl_writer);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_WRITEDATA,data);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_BUFFERSIZE,block_size);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_USERAGENT,alogg_user_agent);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_VERBOSE,1);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;
  code=curl_easy_setopt(data->handle,CURLOPT_DEBUGFUNCTION,&alogg_debug);
  if (code!=CURLE_OK) goto alogg_start_streaming_url_error;

  /* Allow the user to configure cURL options */
  if (configurator) {
    if ((*configurator)(data->handle)) goto alogg_start_streaming_url_error;
  }

  data->multi=curl_multi_init();
  if (!data->multi) goto alogg_start_streaming_url_error;
  curl_multi_add_handle(data->multi,data->handle);

  /* Start streaming */
  stream=alogg_start_streaming_callbacks(
    data,(struct ov_callbacks*)&url_callbacks,block_size
  );
  if (!stream) goto alogg_start_streaming_url_error;
  return stream;

alogg_start_streaming_url_error:
  /* In case of an error, make sure we don't leak */
  if (data) {
    if (data->multi) curl_multi_cleanup(data->multi);
    if (data->handle) curl_easy_cleanup(data->handle);
    free(data->block);
    free(data->url);
    free(data);
  }
  return NULL;
}

Thanks in advance!

-- 
Vincent Penquerc'h 
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-10-08