Operating System - OpenVMS
1820635 Members
1777 Online
109626 Solutions
New Discussion юеВ

how to implement timeout with sys$qio in tcp ip programming

 
RAVIKANTH_3
Occasional Advisor

how to implement timeout with sys$qio in tcp ip programming

I have to make tcp ip connection to server by sending xml messages as request and have to recieve xml messages as response. I have done coding using Sys$qio system calls to communicate with the server.

When i send correct xml requests, i am gettng xml response properly. But when i am sending incorrect xml requests, the sys$qiow system call is hanging indefinitely for getting response.
Please find the timer routine and system calls i have used.

void timer_routine()
{
printf("timer has fired");
exit(1);
}
status = sys$setimr(0,timeout,timer_routine,TIMER_ID,0);

status = sys$qiow(0, channel, IO$_READVBLK, iosb, 0, 0, buffer, bufLen, 0, 0, 0, 0);

sys$cantim(TIMER_ID,0);

can one help me in solving this?
3 REPLIES 3
Jess Goodman
Esteemed Contributor

Re: how to implement timeout with sys$qio in tcp ip programming

To implement a timeout you have to use SYS$QIO instead of SYS$QIOW. CAUTION: do not use event flag #0 with SYS$QIO (best to call LIB$GET_EF).

I have attached a useful routine I wrote years ago, SYNCH_WITH_TIMEOUT.C.

Use it like this:
...
short channel;
short volatile iosb[4];
float timeout=10.0;
...
status = sys$qio(1, channel, IO$_READVBLK, iosb, 0, 0, buffer, bufLen, 0, 0, 0, 0);
if (!(status&1)) return(status);
status = synch_with_timeout( 1, channel, iosb, timeout);
if (!(status&1)) return(status);
status = iosb[0];
return(status);
I have one, but it's personal.
John Gillings
Honored Contributor

Re: how to implement timeout with sys$qio in tcp ip programming

Ravikanth,

You're nearly there!

Your timer AST just needs to $CANCEL(channel). If it fires before the $QIOW completes, it will cancel the I/O. You then cancel the timer and can check the IOSB to see if the I/O completed. SS$_ABORT or SS$_CANCEL indicate it was timed out.

$setimr(EFN$C_ENF,timout,cancel_io,TIMER_ID)
$qiow(EFN$C_ENF,channel,IO$_READVBLK,iosb,,,buffer,bufLen)
$cantim(TIMER_ID)


cancel_io looks like
$cancel(channel)
A crucible of informative mistakes
Richard J Maher
Trusted Contributor

Re: how to implement timeout with sys$qio in tcp ip programming

Hi Ravikanth,

John G has the answer, but a slight addition maybe to use the address of channel as your timer id. That way it would be delivered as the first arg to your timer_routine that could then do a generic $cancel(inchan)

Channel "value" otoh is probably not a very unique timer-id choice :-)

Don't forget to check for ss$_abort and ss$_cancel statii.

Cheers Richard Maher