/*
- * $Id: comm.cc,v 1.227 1998/02/10 21:44:31 wessels Exp $
+ * $Id: comm.cc,v 1.228 1998/02/17 23:28:22 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
default:
debug(50, 0) ("comm_open: socket failure: %s\n", xstrerror());
}
+ fdAdjustReserved();
return -1;
}
/* update fdstat */
fd2 = socket(AF_INET, SOCK_STREAM, 0);
if (fd2 < 0) {
debug(5, 0) ("commResetFD: socket: %s\n", xstrerror());
+ fdAdjustReserved();
return 0;
}
if (dup2(fd2, cs->fd) < 0) {
debug(5, 0) ("commResetFD: dup2: %s\n", xstrerror());
+ fdAdjustReserved();
return 0;
}
close(fd2);
/*
- * $Id: fd.cc,v 1.20 1998/02/10 21:44:33 wessels Exp $
+ * $Id: fd.cc,v 1.21 1998/02/17 23:28:23 wessels Exp $
*
* DEBUG: section 51 Filedescriptor Functions
* AUTHOR: Duane Wessels
{
return Squid_MaxFD - Number_FD;
}
+
+/* Called when we runs out of file descriptors */
+void
+fdAdjustReserved(void)
+{
+ int new;
+ int x;
+ static time_t last = 0;
+ /*
+ * don't update too frequently
+ */
+ if (last + 5 > squid_curtime)
+ return;
+ /*
+ * Calculate a new reserve, based on current usage and a small extra
+ */
+ new = Squid_MaxFD - Number_FD + XMIN(25, Squid_MaxFD / 16);
+ if (new <= RESERVED_FD)
+ return;
+ x = Squid_MaxFD - 20 - XMIN(25, Squid_MaxFD / 16);
+ if (new > x) {
+ /* perhaps this should be fatal()? -DW */
+ debug(51, 0) ("WARNING: This machine has a serious shortage of filedescriptors.\n");
+ new = x;
+ }
+ debug(51, 0) ("Reserved FD adjusted from %d to %d due to failures\n",
+ RESERVED_FD, new);
+ RESERVED_FD = new;
+}
extern void fdFreeMemory(void);
extern void fdDumpOpen(void);
extern int fdNFree(void);
+extern void fdAdjustReserved(void);
extern fileMap *file_map_create(int);
extern int file_map_allocate(fileMap *, int);