tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* TCP pb
@ 1995-01-31  9:54 bouti
  0 siblings, 0 replies; only message in thread
From: bouti @ 1995-01-31  9:54 UTC (permalink / raw)
  To: tru64-unix-managers


----- Begin Included Message -----

From dehaudt@acri.fr Mon Jan 30 09:45:37 1995
X-Authentication-Warning: soft204: Host localhost didn't use HELO protocol
To: os@acri.fr
Subject: TCP pb 
Date: Mon, 30 Jan 95 09:45:31 +0100
From: "Christophe DEHAUDT" <dehaudt@acri.fr>
X-Mts: smtp
Content-Length: 4760




PROBLEM:
We have got a TCP problem with the DEC/OSF3.0 that didn't have with DEC/OSF1.3:

We have 2 processes which communicate with 1 socket but only in one way.
(We have shutdowned the way that is not used)
We use the connection for a while, and don't use it for (perhaps) a long time
(ex: 4 hours)

	---------                     ---------
	|       |                     |       |
	|  P1   |<--------------------|  P2   |
	| rcver	|                     | sender|
	|       |                     |       |
	---------                     ---------
	shutdown OUT                  shutdown IN
	                              set keep alive

With this configuration, we receive a timeout error (ETIMEDOUT) after 2 hours
of non use when running on a 3.0 version (this was not happening on the 1.3).

In annexes, there are 2 source codes which reproduce the problem.



rmq: Even if the sender don't set the KEEPALIVE option, the rcver will
die after 2 hours of inactivity.

CONCLUSION:

Either we use the shutdown functionality in a bad way, but no particular
specifications have been found to prevent this use,
or there is a miss in the kernel for this case.


ANNEXES:
/**************************** SENDER ****************************/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define PORT  5432

void
main(argc, argv)
int	argc;
char	*argv[];
{
    register int        si, out;
    struct sockaddr_in	inaddr, claddr;
    int                 clilen;
    int	                yes = 1;

    if ((si = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
	exit(errno);
    }

    /* initialize inet addr */
    bzero((char *)&inaddr, sizeof(inaddr));
    inaddr.sin_family = AF_INET;
    inaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    inaddr.sin_port = htons(PORT);

    if (setsockopt(si, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0) {
	exit(errno);
    }

    if (bind(si, &inaddr, sizeof(inaddr)) <  0) {
	exit(errno);
    }
    listen(si, 5);

    printf("Waiting for connection ...\n");
    if ((out = accept(si, &claddr, &clilen)) < 0) {
	exit(errno);
    }

    printf("Connection established.\n");

    if (shutdown(out, 0) < 0) {
        exit(errno);
    }
    if (setsockopt(out, SOL_SOCKET, SO_KEEPALIVE, (char *)&yes,
		   sizeof(int)) < 0) {
	fprintf(stdout, "set SO_KEEPALIVE failed");
	exit(-1);
    }

    write(out, &yes, 8);
    for (;;)
      sleep(100); /* wait for the crash of the rcver */
}

/************************* END SENDER ****************************/

/**************************** RCVER ******************************/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

#define PORT		5432

#define CRASH_TIME	7200
#define TIME_INCR       1
void
main(argc, argv)
int	argc;
char	*argv[];
{
    register int        in;
    struct sockaddr_in	inaddr;
    int	                yes = 1;
    int                 pid;
    fd_set      	inmask;
    int                 maxfd, nfound;
    struct timeval	timeout;
    int                 crashdate = CRASH_TIME;
    char     		buffer[8];

    /* initialize inet addr */
    bzero((char *)&inaddr, sizeof(inaddr));
    inaddr.sin_family = AF_INET;
    inaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    inaddr.sin_port = htons(PORT);

    if ((in = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
	fprintf(stdout,"socket error");
	exit(-1);
    }
    if (connect(in, &inaddr, sizeof(inaddr)) < 0) {
	fprintf(stdout, "connect failed, exit...\n");
	exit(-1);
    }

    if (shutdown(in, 1)) {
	fprintf(stdout, "error during shutdown\n");
	exit(-1);
    }

    /* the sender send one byte to test it is working */
    if (read(in, buffer, 8) <= 0) {
	printf("Socket read error: %d\n", errno);
	exit (-1);
    }

    for (;;) {
	FD_ZERO(&inmask);
	FD_SET(in, &inmask);
	
	timeout.tv_sec = TIME_INCR;
	timeout.tv_usec = 0;
	maxfd = NOFILE + 1;
	nfound = select(maxfd, &inmask, (fd_set *)0, (fd_set *)0, &timeout );
	if (nfound < 0) {
	    printf ("error\n");
	    exit(errno);
	}
	
	crashdate -= TIME_INCR;

	printf ("Time before crash in seconds: %d\r", crashdate);
	fflush(stdout);
    
	if (FD_ISSET(in, &inmask)) {
	    int      nbytes;
	    
	    printf("\nReceived someting on the socket\n");
	    
	    if (ioctl(in, FIONREAD, &nbytes) < 0) {
		printf ("error\n");
		exit(errno);
	    }
	    if (nbytes == 0) {
		printf("0 bytes received, it should be an error ...\n");
	    }
	    
	    if (read(in, buffer, 8) <= 0) {
		printf("Socket read error: %d (should be 60 ETIMEOUT)\n",
		       errno);
		exit (-1);
	    }
	}
    }
}
/************************* END RCVER ****************************/


----- End Included Message -----

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-01-31  9:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-01-31  9:54 TCP pb bouti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox