cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Working with curl connections as with sockets.

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 25 Apr 2008 12:09:09 +0200 (CEST)

On Fri, 25 Apr 2008, tetetest tetetest wrote:

>> That's pretty much exactly what CONNECT_ONLY does today!
>
> Oh... hmmm... sorry, I have missed that. Connecting and getting the
> descriptor is almost exactly what I wanted.
>
> Still, I have some doubts:

Sure, but most of these can be cured with better docs, don't you think?

> - it is not clear how should I close the socket after use;

Don't, use libcurl's curl_easy_cleanup function when you're done and it'll
close the connection.

> - is it a blocking socket?

No, it'll be non-blocking but you can of course change that yourself to
whatever you'd like it to be.

> - I must handle timeouts, network errors and all such myself;

Yes, you get a plain socket to an established TCP connection, the rest is your
problem. :-)

> - in case of SSL connections, which descriptor is returned? The socket
> connected to the server, or the SSL engine's handle?

The socket. So you need to use a SSL library that you can hand a socket and
tell it that here's an established SSL connection. I'm not sure this is really
properly feasable though...

> - under Windows, should I use socket-oriented or file-oriented functions?
> And what about SSL connections?

Windows is no exception to this functionality, it works the same all over.

> I still think that libcurl can handle its sockets better than the
> application - simply because libcurl knows more about the socket. Providing
> an interface for sending/receiving the data will greatly simplify the usage
> of libcurl in aplications using CURLOPT_CONNECT_ONLY.

Yeah, especially in the case with SSL it is a bit messy for the app.

Adding curl_socket_recv() and curl_socket_send() would possibly make sense and
not involve too many hoops and weird stuff. These functions would then
basically require that you do a successful CURLOPT_CONNECT_ONLY first.

But will it be enough with just these two ones then? I'm a bit scared it'll be
like opening pandora's box here and we'll soon have to add more and more to
make this API usable when going down this road.

I did hack a little on a proxy-tunneling tool based on libcurl[1] a while ago
and that would've been a lot nicer and easier if libcurl had such functions.

[1] = http://daniel.haxx.se/blog/2007/11/28/tunneling-with-libcurl/

> So, could such interface be possibly implemented? Please. :)

Me being open to the idea of course doesn't make it automatically happen. If
you really want it to start happening you better step up and start doing some
work on it.

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2008-04-25