From c41fa51542a5bb23ad2917e98ffcc4bb4db52158 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Thu, 21 May 1998 03:47:44 +0000 Subject: [PATCH] From: Stewart Forster This is the final patch that I decided upon that avoids extra system calls (ie. faster). It adds two extra flags, FD_NOLINGER, and FD_NONBLOCKING to allow for easy testing of these conditions when deciding what to do in comm_close(). It also allows for easy changing of the doaioclose test in the future when it's decided what actually takes precedence. --- src/comm.cc | 19 +++++++++++-------- src/enums.h | 4 +++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/comm.cc b/src/comm.cc index bf7b7fd32e..8d217b7fa3 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,7 +1,7 @@ /* - * $Id: comm.cc,v 1.256 1998/05/15 18:57:42 wessels Exp $ + * $Id: comm.cc,v 1.257 1998/05/20 21:47:44 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -665,8 +665,7 @@ comm_close(int fd) { fde *F = NULL; #if USE_ASYNC_IO - int flags; - int dummy = 0; + int doaioclose = 1; #endif debug(5, 5) ("comm_close: FD %d\n", fd); assert(fd >= 0); @@ -678,6 +677,11 @@ comm_close(int fd) return; assert(F->open); assert(F->type != FD_FILE); +#ifdef USE_ASYNC_IO + if (EBIT_TEST(F->flags, FD_NOLINGER)) + if (EBIT_TEST(F->flags, FD_NONBLOCKING)) + doaioclose = 0; +#endif EBIT_SET(F->flags, FD_CLOSING); CommWriteStateCallbackAndFree(fd, COMM_ERR_CLOSING); commCallCloseHandlers(fd); @@ -691,13 +695,10 @@ comm_close(int fd) */ close(fd); #elif USE_ASYNC_IO - /* slf@connect.com.au */ - if ((flags = fcntl(fd, F_GETFL, dummy)) < 0) + if (doaioclose) aioClose(fd); - else if (flags & SQUID_NONBLOCK) - close(fd); else - aioClose(fd); + close(fd); #else close(fd); #endif @@ -1236,6 +1237,7 @@ commSetNoLinger(int fd) L.l_linger = 0; if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &L, sizeof(L)) < 0) debug(50, 0) ("commSetNoLinger: FD %d: %s\n", fd, xstrerror()); + EBIT_SET(fd_table[fd].flags, FD_NOLINGER); } static void @@ -1267,6 +1269,7 @@ commSetNonBlocking(int fd) debug(50, 0) ("commSetNonBlocking: FD %d: %s\n", fd, xstrerror()); return COMM_ERROR; } + EBIT_SET(fd_table[fd].flags, FD_NONBLOCKING); return 0; } diff --git a/src/enums.h b/src/enums.h index 3d0261ee12..9812698aff 100644 --- a/src/enums.h +++ b/src/enums.h @@ -463,7 +463,9 @@ enum { FD_CLOSE_REQUEST, FD_WRITE_DAEMON, FD_CLOSING, - FD_SOCKET_EOF + FD_SOCKET_EOF, + FD_NOLINGER, + FD_NONBLOCKING }; enum { -- 2.47.3