Overview
Features
Download
Documentation
Community
Add-Ons & Services

HttpClientSession and select() function

Please post support and help requests here.

HttpClientSession and select() function

Postby Hellbard » 02 Apr 2007, 13:50

Hi, I am creating aplication, that exchanges some information by client server connection. I have only two threads, one for client and one for server side.
When I send some messages from client to servers. It is possible that some server is offline and it takes 30 seconds, before I get error code. But I cannot block my application for so long.
I decided to use select function. Start another "select" thread. In client thread I only want to send message and then give pointer to HttpClientSession to the "select" thread. And the client thread ends. In "select" thread I need to get the filedescriptor for the socket underlaying the HttpClientSession. Or if I want to use select function in the socket.h library a need to get socket underlaying the HttpClientSession. It is possible by socket function. But this is private member function. Can I get socket or socket filedescriptor of HttpClientSession by another way??

Thanks for your advice and please sorry my english :o)
Hellbard
 
Posts: 12
Joined: 16 Mar 2007, 11:21

Re: HttpClientSession and select() function

Postby alex » 02 Apr 2007, 15:19

I may not understand your problem properly, but it seems to me that you are complicating your life unnecessarily. Since you are launching a select thread, it appears that the associated overhead is not a concern. If that's the case, why not simply launch a thread for the blocking portion rather than fiddling with select()? If you still want to do it with select(), have you considered using SocketReactor in some capacity?

Alex
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Re: HttpClientSession and select() function

Postby Hellbard » 02 Apr 2007, 18:08

It will probably need a little bit more detailed description. The system make instance of my aplication (class), that should send messages between http client and server.
When system call my function to send a message to server (from one thread), I generate a message and send, then I wait for response. But when some server is offline, it can happen that I must wait 30s for timeout. But I cannot block application for so long. And I cant make for each message separate thread.
Well I think it will be best, when I make a new thread and create set, that holds pointer to every session, that send message and still havent got response. On this set I call select(). When some response come, select breaks and I send response to system with some error code.
I think it is the best way how to resolve this problem.
I will consider your advices, but please, Is there some way to get the socket or its filedescriptor?
Hellbard
 
Posts: 12
Joined: 16 Mar 2007, 11:21

Re: Re: Re: HttpClientSession and select() function

Postby alex » 02 Apr 2007, 18:34

> I think it is the best way how to resolve this problem.

It sounds like you need a reactor. Check SocketReactor. I has select() in its guts.

> I will consider your advices, but please, Is there some way to get the socket or its filedescriptor?

Considering the fact that HTTPClientSession has a protected socket() member inherited from HTTPClient, which returns StreamSocket, which in turn has protected sockfd() member inherited from Socket, I'd say - no, you can not get the descriptor. I doubt it, but maybe Guenter would be willing to make those public. You'll have to wait and see what he says.

Alex
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: HttpClientSession and select() function

Postby guenter » 02 Apr 2007, 18:42

Have you tried setting a timeout on the HTTPClientSession?
You can do this with the setTimeout() member function (inherited from HTTPSession).

guenter
 
Posts: 1107
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Re: HttpClientSession and select() function

Postby Hellbard » 03 Apr 2007, 01:03

> Have you tried setting a timeout on the HTTPClientSession?
> You can do this with the setTimeout() member function (inherited from HTTPSession).
>
>
I set it to 30s. It is because it can take a while to get response. But I cannot hold thread for so long so I need so I need some event, that says me that I can read the response or I must do it with select
Hellbard
 
Posts: 12
Joined: 16 Mar 2007, 11:21

Re: HttpClientSession and select() function

Postby Hellbard » 03 Apr 2007, 01:22

Probably I have it. I will create a StreamSocket instance. Than I will use it in constructor of HTTPClientSession. Now I have socket underlaying the http client and on this socket I can call select() function.

I believe I am not wrong. (:question:)
Hellbard
 
Posts: 12
Joined: 16 Mar 2007, 11:21

Re: Re: HttpClientSession and select() function

Postby alex » 03 Apr 2007, 16:31

> Probably I have it. I will create a StreamSocket instance. Than I will use it in constructor of HTTPClientSession. Now I have socket underlaying the http client and on this socket I can call select() function.
>
> I believe I am not wrong. (:question:)

I'm writing off the top of my head, but I don't think you'll be able to get StreamSocket: :sockfd() needed for : :select() call because it is protected. You may want to use Socket: :select() (see SocketReactor::run() for example).
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Re: Re: HttpClientSession and select() function

Postby Hellbard » 04 Apr 2007, 00:09

But I think I do not need socketfd. If you see to the Socket::select() function, it takes as an argument vector SocketList, so I only create StreamSocket, with this I make new HttpClientSession and I give this socket to SocketList, then on this SocketList I make a select() call
Hellbard
 
Posts: 12
Joined: 16 Mar 2007, 11:21


Return to Support

Who is online

Users browsing this forum: No registered users and 6 guests

cron