Page 1 of 1

HTTPAPI Timeout question

Posted: Wed Nov 02, 2022 2:42 pm
by assignment400
What happens in a HTTPAPI call when the target system is unavailable?

How long is the timeout wait?

Can the timeout period be reduced?

I am using HTTPAPI in an interactive situation. If there is a remote failure, we cannot have the system locking the system until the timeout expires. I would like to see if there is a way to identify the failure.

Thanks, Darryl Freinkel.

Re: HTTPAPI Timeout question

Posted: Wed Nov 02, 2022 4:15 pm
by jonboy49
Most of the APIs in HTTPAPI offer an optional timeout parameter Darryl which allow you to specify the timeout delay in seconds. For example:

Code: Select all

     D http_get        PR            10I 0 extproc('HTTP_URL_GET')
     D  peURL                     32767A   varying const options(*varsize)
     D  peFilename                32767A   varying const options(*varsize)
     D  peTimeout                    10I 0 value options(*nopass)
     D  peUserAgent               16384A   varying const  options(*nopass:*omit)
     D  ...
The return code allow you to differentiate between success, failure, and timeout.

Just search the header file for the word "timeout" there's over 60 references.

Re: HTTPAPI Timeout question

Posted: Wed Nov 02, 2022 6:50 pm
by Scott Klement
I would prefer that people not use the old APIs like the one Jon posted for new applications.

Instead, use http_req, http_stmf or http_string.

Code: Select all

http_setOption('timeout': '30'); // time out after 30 seconds

rc = http_req(...parameters...);
You mention the other system is "unavailable". The timeout only applies to lack of data being received -- i.e. you try to connect and get no response, or you are expecting to be able to send or receive data and get no response for the given number of seconds.

Frequently when a system is unavailable, it's because the HTTP server isn't running on that system. In that case, you wouldn't get a timeout, you'd get an error connecting (typically "Connection Refused" but sometimes "Host not available") That is because the TCP/IP stack on the remote computer's operating system is still running, even if the program is not. And so it will send back an error code immediately.

Re: HTTPAPI Timeout question

Posted: Fri Nov 04, 2022 10:24 pm
by assignment400
Thank you.
I'll add your recommendation in the program.
Darryl.