[Date Prev][Date Next] [Chronological] [Thread] [Top]

close connection with shutdown(,SHUT_RDWR) (ITS#2265)



Full_Name: lise Didillon
Version: 2.0.27
OS: linux kernel 2.4.18 or Mandrake 7.2 with kernel 2.2.14
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (193.252.109.90)


SHUT_RDWR is defined and non null in /usr/include/sys/socket.h (glibc 2.2.5) 

enum
{
  SHUT_RD = 0,          /* No more receptions.  */
#define SHUT_RD         SHUT_RD
  SHUT_WR,              /* No more transmissions.  */
#define SHUT_WR         SHUT_WR
  SHUT_RDWR             /* No more receptions or transmissions.  */
#define SHUT_RDWR       SHUT_RDWR
};


but in openldap-2.27/include/ac/socket.h you have:
#else
#       define tcp_read( s, buf, len)   read( s, buf, len )
#       define tcp_write( s, buf, len)  write( s, buf, len )


#       if SHUT_RDWR
#               define tcp_close( s )   (shutdown( s, SHUT_RDWR ), close( s ))
#else
#               define tcp_close( s )           close( s )
#endif

and it's like SHUT_DOWN was null and so tcp_close( s ) call only close( s)

If I put
# ifdef SHUT_RDWR
instead of
# if SHUT_RDWR
then slapd make a shutdown(,SHUT_RDWR) before calling close()
I do that because we got many and many connection in FIN_WAIT or CLOSE_WAIT
state.  Now it's better. I already reported this bug for openldap-2.0.15 but not
on the good mailing list.

here a C code example to reproduce:

#include <stdio.h>
#include <sys/socket.h>

#ifdef SHUT_RDWR
#define Myprint1()	printf ("SHUT_RDWR defined\n")
#else
#define Myprint1()	printf ("SHUT_RDWR not defined\n")
#endif

#if SHUT_RDWR
#define Myprint2()	printf ("SHUT_RDWR != 0\n")
#else
#define Myprint2()	printf ("SHUT_RDWR == 0\n")
#endif

/* ----------------------------- */
   main (int argc, char *argv[])
/* ----------------------------- */
{
	int shut;
	
	shut= SHUT_RDWR;
	printf ("SHUT_RDWR = %d\n",shut);
	Myprint1();
	Myprint2();
	return (0);
}	/* main */

running this code has the following result:

SHUT_RDWR=2
SHUT_RDWR defined
SHUT_RDWR == 0

I use gcc 2.95.2 or 2.95.3

thank you for your help.
best regards,

Lise DIDILLON