Overview
Features
Download
Documentation
Community
Add-Ons & Services

How to set timeout when opening an url

A general discussion forum.

How to set timeout when opening an url

Postby hardegg » 28 Mar 2013, 10:24

Dear all,

I'm using code below to open an URL. But we should specify the timeout time, in case the program is stuck here for too much time.

std::auto_ptr<std::istream> pStr(URIStreamOpener::defaultOpener().open(uri));

Could you guys give some idea where and how to set it? (Sorry I'm a beginner of POCO.) Specifically, if I set a timeout value, say, 2 seconds, the program should continue to do the left jobs in 2 seconds.

Thanks you all.
hardegg
 
Posts: 2
Joined: 28 Mar 2013, 10:17

Re: How to set timeout when opening an url

Postby alex » 28 Mar 2013, 14:58

hardegg wrote:Could you guys give some idea where and how to set it? (Sorry I'm a beginner of POCO.) Specifically, if I set a timeout value, say, 2 seconds, the program should continue to do the left jobs in 2 seconds.

Can't do that with URIStreamOpener. If you want your main thread to continue while opener is fetching URI, run it in separate thread. Alternatively, you can use HTTPClientSession, which allows you to pass in your own socket with the timeout set.
alex
 
Posts: 1143
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: How to set timeout when opening an url

Postby hardegg » 28 Mar 2013, 15:22

alex wrote:
hardegg wrote:Could you guys give some idea where and how to set it? (Sorry I'm a beginner of POCO.) Specifically, if I set a timeout value, say, 2 seconds, the program should continue to do the left jobs in 2 seconds.

Can't do that with URIStreamOpener. If you want your main thread to continue while opener is fetching URI, run it in separate thread. Alternatively, you can use HTTPClientSession, which allows you to pass in your own socket with the timeout set.

Thanks Alex. Multithreading is the last choice since I'm not familiar about it. I'll turn to "HTTPClientSession". By the way, one more question about URIStreamOpener. Isn't there a default timeout value for the "open" method, although we cannot set it manualy?
hardegg
 
Posts: 2
Joined: 28 Mar 2013, 10:17

Re: How to set timeout when opening an url

Postby alex » 29 Mar 2013, 04:40

hardegg wrote:Isn't there a default timeout value for the "open" method, although we cannot set it manualy?

No, sockets are created in blocking mode by default.
alex
 
Posts: 1143
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests