How to do HTTP Connection pooling

Login to reply to this topic.
Tue, 2007-09-04 04:44
Joined: 2007-08-28
Forum posts: 3

My application needs to do HTTP transactions from multiple classes. Is it efficient to do RSocketServer 'connect' and RConnection - 'open' and 'start' separately for each request ? Can i do some kind of Connection Pooling where i reuse the RConnection and the RSocketServ objects.

The API Reference says this Regarding RConnection

"Rather like RSocket/RHostResolver objects, an individual RConnection object is not designed to be used by multiple clients simultaneously (ie: have multiple requests outstanding on it from different clients)."

Does this mean that i need to have one connection dedicated each class in my app.

Thanks for demystifying this.

=sharath


Wed, 2007-09-05 10:12
Joined: 2007-06-21
Forum posts: 82
Re: How to do HTTP Connection pooling

This is very much possible. What I understand is that you want to use same instance of your HttpEngine from all the classes for seperate downloads.
Did you see the S60 Example of Http Engine. In the example, a RConnection is created in each IssueHTTPGetL or IssueHTTPPostL. I would suggest to have only one RConnection in your engine, Open n Start that in ConstructL, like

        User::LeaveIfError(iSocketServ.Connect()); //iSocketServ is RSocketServ
        User::LeaveIfError(iConnection.Open(iSocketServ));//iConnection is RConnection
        User::LeaveIfError(iConnection.Start());       

and IssueHTTPGetL use the same connection,

TInt CHttpEngine::IssueHTTPGetL( const TDesC8& aUri, TInt aUniqueId,TBool aStartWaitDialog /*=EFalse*/)
    {
    // Parse string to URI (as defined in RFC2396)
    TUriParser8 uri;
    uri.Parse( aUri );
       
    // Get request method string for HTTP GET
    RStringF method = iSession.StringPool().StringF( HTTP::EGET,
        RHTTPSession::GetTable());

        // set them for use with open http session represented by iSession
        RStringPool strP = iSession.StringPool();
        RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
        connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );
        TInt connPtr = REINTERPRET_CAST(TInt, &(iConnection));
        connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) );


    // Open transaction with previous method and parsed uri. This class will
    // receive transaction events in MHFRunL and MHFRunError.
    iTransaction = iSession.OpenTransactionL( uri, *this, method );

    // Set headers for request; user agent and accepted content type
    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    SetHeaderL( hdr, HTTP::EUserAgent, KUserAgent );
    SetHeaderL( hdr, HTTP::EAccept, KAccept );

        SetHeaderL(hdr, HTTP::EHost,uri.Extract(EUriHost));

        //Put this info in the Array
        AddTransactionToArray(iTransaction.Id(),aUniqueId);

    // Submit the transaction. After this the framework will give transaction
    // events via MHFRunL and MHFRunError.
    iTransaction.SubmitL();

    iRunning = ETrue;

    return iTransaction.Id();
    }

You can see in above code I have used
//Put this info in the Array
AddTransactionToArray(iTransaction.Id());

What I'm doing is adding the transactionId in an Array, so that when I get MHFRunL, I can figure out that the callback is for particular Id. So you can respond in a way you want.
In brief, with above code, your different classes can make multiple IssueHTTPGetL or IssueHTTPPostL, and HttpEngine will take care of all the downloads.

If you don't want to use HttpEngine, you can also use DownloadManager(S60 3rd ed onwards). You can find a lot of documentation on that.

Br
G;p
www.mobisy.com

Mon, 2007-09-10 07:08
Joined: 2007-08-28
Forum posts: 3
Re: How to do HTTP Connection pooling

singhgupi.

Thanks for the suggestion. I will do like wise and see.

Regards,
Sharath

  • Login to reply to this topic.