cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: SOCKS proxy problem

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 15 Sep 2006 09:37:15 +0200 (CEST)

On Thu, 14 Sep 2006, Dmitriy Sergeyev wrote:

> It seems that handleSock4Proxy and handleSock5Proxy has one problem while
> receiving response from SOCKS proxy. Both of them uses Curl_read() to read
> the response, but when proxy sends the response byte-by-byte (just like my
> sample SOCKS server) Curl_read() sometimes returns only one byte instead of
> several stated in buffersize.

No, Curl_read() reads as many bytes as it is provided by the TCP layer (and
that fits in the buffer) so if it reads only one byte there was only byte to
read!

> And it causes failure of these functions. For example url.c:1989

The line numbers are much changed since last release, but I figure you mean
one of the socks functions?

> The only way I have found to solve this problem is to add something like
> Curl_read_all() function that performs Curl_read() until entire buffer will
> be filled. Is this a good solution?

No, it would possibly make it work better than now but it would be far away
from a good solution.

A good solution to doing SOCKS would mean using the ordinary libcurl connect
procedure (which is multi interface friendly and more reliable on more
operating systems) just like the HTTP proxy connect does, and then we would do
the SOCKS negotiation in a non- blocking manner, most probably with a kind of
state-machine so that partial reads and writes during SOCKS negotiations don't
mess anything up and don't block internals.

> And may be hadnleSocks* functions in case of failure must to
> return CURLE_COULDNT_CONNECT instead of 1 ? Because ConnectPlease()
> function verifies only this return value to determine the failure.
> But CURLE_COULDNT_CONNECT == 7 and it returns CURLE_OK even if
> handleSocks failed (url.c:2324)

The handleSock[45]Proxy functions are called from ConnectPlease() and that
function treads a non-zero return code as error and will then return
CURLE_COULDNT_CONNECT upstream. But that's a somewhat weird approach, and the
least we should do is make them return CURLcode types themselves.

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2006-09-15