cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problem with reusing persistent connections

From: Stefan Krause <stefan.krause_at_gmx.net>
Date: Tue, 11 Sep 2007 19:38:49 +0200

Hello libCurl users,

I have got a problem with reusing persistent connections after a
re-establishment of the physical data connection (over a mobile phone).

First a short description of the setup. The basic architecture is as
follows.
A client application communicates with a server application over HTTP.
Therefore libCurl is used with the multi interface in a separate thread.
A socket connection is build by libCurl from client to server host.
The client application triggers the establishment of the physical
data connection over the mobile phone. It also triggers closing of the
connection. Also other client applications can close the data connection if
nobody needs it. The used operating system is QNX 6.3.0.

Client-App -------- Server-App
    | |
libCurl |
    | |
  socket ------------ socket
    | |
Mobile phone XXXXX

The sequence of actions which leads to problems are the following:
1) Client-App: Establish data connection over mobile phone. Host gets IP-
   Address X.
2) Client-App: Do a HTTP GET via libCurl to server
3) libCurl establishes the socket connection to the server and transfers
   the file. After the transfer is done, the connection still exists
   (persistent connection)
4) Client-App: Closes the data connection over the mobile phone. The socket
   connection from libCurl is still open.
5) Client-App: Establish data connection over mobile phone. Host gets IP-
   Address Y.
6) Client-App: Do a HTTP GET via libCurl to server (same request as step 2)
7) libCurl tries to re-use the already existing connection (from step
3). That
   connection seems NOT to be usable any more. A timeout occures. The
Client-App
   then retries the HTTP GET. Then a new socket connection is
established and
   the HTTP GET works as expected.
   
   My problem: The Client-App has to wait until the timeout for the socket
   connection occured before the HTTP GET actually happened. For my
application
   that is quite undesirable because practically it would work with a new
   connection. I tried to use the option CURLOPT_FORBID_REUSE. That had the
   desired effect; after a successful HTTP GET the socket connection was
closed,
   reusing of an existing connection never happened. The very big
disadvantage
   of that is when you are using SSL secured connections. The SSL handshake
   has to be done before each new HTTP GET -> a very big overhead.
   

Questions:
1) According to my understanding I need a way to renew the connections from
   my multi and/or the contained easy handles when the physical data
connection
   of the mobile phone has been re-established? HTTP transfers are
segmented.
   That means that the physical data connection can be shut down and
   re-established during an ongoing transfer. The use case for that
might be
   a high prio voice call which needs the mobile phone, the HTTP transfer
   will then be interrupted and continued after the data connection has been
   re-established.
2) What is the right way to trigger renewal of the connections ?
   a) Should the Client-App inform somehow libCurl to renew the connections?
      How is that possible? OR
   b) Should the closing of the physical data connection force the
sockets which
      are currently in use by libCurl being closed. So that libCurl
establishes
      a new connection?
      
   Whats preferable here in the view of "technical correctness" ? I prefer
   option a) as b) involves other parties to get involved (what is possible
   of course, but causes probably more effort).
   
   If you need further informations please give me a hint.
 
 
Thanks in advance,
best regards

  Stefan
      
    
    
 
Received on 2007-09-11