cURL / Mailing Lists / curl-library / Single Mail


CURLOPT_FRESH_CONNECT and multithreading

From: Dima Tisnek <>
Date: Tue, 24 Sep 2013 18:03:30 +0200

Hey all, I'm working on some legacy code that uses FRESH_CONNECT as a
hack to ensure that sockets left in inconsistent state are closed and

Possible causes of inconsistent state are http-level
timeout/confusion, server bugs, read/write function bugs, incomplete
chunked transfer read-out via error return from readdata function,
incorrect content-length, etc.

First off, was the original developer's logic sounds in single-threaded case?

I'm trying to make this code logically thread-safe. New libcurl handle
is allocated for each transfer, but the underlying socket is up to
libcurl to reuse or recreate.

This begs the question, is libcurl's socket cache per-thread or global?

If it's global, are sockets reused between threads?

If so, I suppose FRESH_CONNECT only hides the problem. in this case,
what's the right way to explicitly close the underlying socket?

List admin:
Received on 2013-09-24