HP OpenVMS Systems

ask the wizard
Content starts here

Setting IP connect() timeout?

» close window

The Question is:

I have an application running in OpenVMS as client using socket connection
to a server NT application. My problem is connect() function in Open VMS
takes too long to timeout (about 2 min.) What can I do to change this
timeout to 5 seconds or so. I attempt
ed to use an AST to close socket with a sys$setimr() but somehow it screws
up the socket after that. Please advise me on this issue.
Thank you very much

The Answer is :

  Something like the following (untested) program should be close -- the
  key here is use of the TCPIP$C_TCP_PROBE_IDLE in the setsockopt call.
#include <socket.h>
#include <stdlib.h>
#include <in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <unixio.h>
#include <tcpip$inetdef.h>
main(int argc, char *argv[]) {
   int s, i, len, five=5;
   struct sockaddr_in lcladdr, rmtaddr;
   char message[512];
   struct hostent *hp;
   if (argc != 2) {
      printf("Usage: %s <hostname>\n", argv[0]);
   if (!(hp = gethostbyname(argv[1]))) {
      printf("Unknown host: %s\n", argv[1]);
   lcladdr.sin_family = AF_INET;
   lcladdr.sin_addr.s_addr = INADDR_ANY;
   lcladdr.sin_port = htons(0);
   rmtaddr.sin_family = AF_INET;
   rmtaddr.sin_addr.s_addr = *(int *)hp->h_addr_list[0];
   rmtaddr.sin_port = htons(1234);
   if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) perror("socket");
   if (bind(s, (void *) &lcladdr, sizeof(lcladdr))) perror("bind");
   if (setsockopt(s, TCPIP$C_TCP, TCPIP$C_TCP_PROBE_IDLE, &five, sizeof(five)))
   if (connect(s, (void *) &rmtaddr, sizeof(rmtaddr))) perror("connect");
   do {
      len = read(s, message, sizeof(message));
      if (len>0) write(1, message, len);
   } while (len>0);
   if (len<0) perror("read");
   if (close(s)) perror("close");
   return EXIT_SUCCESS;

answer written or last revised on ( 4-FEB-2000 )

» close window