]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Declutter FD_WRITE and FD_READ (#1614)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Fri, 8 Dec 2023 21:26:00 +0000 (21:26 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 8 Dec 2023 21:26:12 +0000 (21:26 +0000)
Avoid clashes with same-name constants defined by MS WIndows Socket API.

Also removed a few related ununsed macros.

16 files changed:
compat/os/mswindows.h
include/snmp_impl.h
src/DiskIO/IpcIo/IpcIoFile.cc
src/clients/Client.cc
src/clients/FtpClient.cc
src/comm/Read.cc
src/comm/Write.cc
src/dns_internal.cc
src/enums.h
src/fd.cc
src/fd.h
src/fs_io.cc
src/http.cc
src/log/ModStdio.cc
src/log/ModUdp.cc
src/tests/stub_fd.cc

index 5446bb8adb04b727dd4ceed85f5da138e70f43a4..2fba4ed9c71b4da5a046a7811c1ab80097400ea8 100644 (file)
@@ -284,11 +284,6 @@ struct timezone {
 #define _PATH_DEVNULL "NUL"
 #endif
 
-#undef FD_CLOSE
-#undef FD_OPEN
-#undef FD_READ
-#undef FD_WRITE
-
 #ifndef EISCONN
 #define EISCONN WSAEISCONN
 #endif
index ac346f4a03b793e30cc148d6ba84536c9b34a052..f949111906be75bf8f612a9dd1cec41bfa1fec38 100644 (file)
@@ -40,9 +40,6 @@ SOFTWARE.
 
 #define SID_MAX_LEN 64
 
-#define READ        1
-#define WRITE       0
-
 #define SNMP_RESERVE1    0
 #define SNMP_RESERVE2    1
 #define SNMP_COMMIT      2
index c156a1dc2675f9989bb0e7e46a04f2b146f96ad2..449a6c97b0914ba5cd1a50580e174e29db9a413b 100644 (file)
@@ -741,7 +741,7 @@ diskerRead(IpcIoMsg &ipcIo)
     char *const buf = Ipc::Mem::PagePointer(ipcIo.page);
     const ssize_t read = pread(TheFile, buf, min(ipcIo.len, Ipc::Mem::PageSize()), ipcIo.offset);
     ++statCounter.syscalls.disk.reads;
-    fd_bytes(TheFile, read, FD_READ);
+    fd_bytes(TheFile, read, IoDirection::Read);
 
     if (read >= 0) {
         ipcIo.xerrno = 0;
@@ -773,7 +773,7 @@ diskerWriteAttempts(IpcIoMsg &ipcIo)
     for (int attempts = 1; attempts <= attemptLimit; ++attempts) {
         const ssize_t result = pwrite(TheFile, buf, toWrite, offset);
         ++statCounter.syscalls.disk.writes;
-        fd_bytes(TheFile, result, FD_WRITE);
+        fd_bytes(TheFile, result, IoDirection::Write);
 
         if (result < 0) {
             ipcIo.xerrno = errno;
index cbf5693e28d60da7e89e59cd14c9702edd0bb6fd..60ab7d087812e2d465574b2ac1456d704e05417e 100644 (file)
@@ -369,7 +369,7 @@ Client::sentRequestBody(const CommIoCbParams &io)
     requestSender = nullptr;
 
     if (io.size > 0) {
-        fd_bytes(io.fd, io.size, FD_WRITE);
+        fd_bytes(io.fd, io.size, IoDirection::Write);
         statCounter.server.all.kbytes_out += io.size;
         // kids should increment their counters
     }
index 3630766f830151ab598524cfbcf308dc200209bb..fe737832469327478a786715d5a84276b8dffd3e 100644 (file)
@@ -379,7 +379,7 @@ Ftp::Client::readControlReply(const CommIoCbParams &io)
     assert(ctrl.offset < ctrl.size);
 
     if (io.flag == Comm::OK && io.size > 0) {
-        fd_bytes(io.fd, io.size, FD_READ);
+        fd_bytes(io.fd, io.size, IoDirection::Read);
     }
 
     if (io.flag != Comm::OK) {
@@ -858,7 +858,7 @@ Ftp::Client::writeCommandCallback(const CommIoCbParams &io)
     debugs(9, 5, "wrote " << io.size << " bytes");
 
     if (io.size > 0) {
-        fd_bytes(io.fd, io.size, FD_WRITE);
+        fd_bytes(io.fd, io.size, IoDirection::Write);
         statCounter.server.all.kbytes_out += io.size;
         statCounter.server.ftp.kbytes_out += io.size;
     }
index 18913444ad24e95cae7d139e468ea9210421549d..452a8d5605b9b2cc39ea6d1cf13ec152a7b7aac3 100644 (file)
@@ -94,7 +94,7 @@ Comm::ReadNow(CommIoCbParams &params, SBuf &buf)
 
     if (retval > 0) { // data read most common case
         buf.rawAppendFinish(inbuf, retval);
-        fd_bytes(params.conn->fd, retval, FD_READ);
+        fd_bytes(params.conn->fd, retval, IoDirection::Read);
         params.flag = Comm::OK;
         params.size = retval;
 
@@ -150,7 +150,7 @@ Comm::HandleRead(int fd, void *data)
     /* See if we read anything */
     /* Note - read 0 == socket EOF, which is a valid read */
     if (retval >= 0) {
-        fd_bytes(fd, retval, FD_READ);
+        fd_bytes(fd, retval, IoDirection::Read);
         ccb->offset = retval;
         ccb->finish(Comm::OK, 0);
         return;
index e6f2770a4cac2d9b0f3d11c9744fc8cd98d235f1..2b9d8228e06c934237c8a5b0c0894a9129b16518 100644 (file)
@@ -91,7 +91,7 @@ Comm::HandleWrite(int fd, void *data)
     }
 #endif /* USE_DELAY_POOLS */
 
-    fd_bytes(fd, len, FD_WRITE);
+    fd_bytes(fd, len, IoDirection::Write);
     ++statCounter.syscalls.sock.writes;
     // After each successful partial write,
     // reset fde::writeStart to the current time.
index c080cf817b59bc11e0d42384e69fdb6c358411b6..e684e1433bdf11390fe6a05591060fa3dbfb8ed1 100644 (file)
@@ -998,10 +998,10 @@ idnsSendQuery(idns_query * q)
     } while ( (x<0 && y<0) && q->nsends % nsCount != 0);
 
     if (y > 0) {
-        fd_bytes(DnsSocketB, y, FD_WRITE);
+        fd_bytes(DnsSocketB, y, IoDirection::Write);
     }
     if (x > 0) {
-        fd_bytes(DnsSocketA, x, FD_WRITE);
+        fd_bytes(DnsSocketA, x, IoDirection::Write);
     }
 
     ++ nameservers[nsn].nqueries;
@@ -1357,7 +1357,7 @@ idnsRead(int fd, void *)
             break;
         }
 
-        fd_bytes(fd, len, FD_READ);
+        fd_bytes(fd, len, IoDirection::Read);
 
         assert(N);
         ++(*N);
index 4ad4f0c94340edf878658645e0d884b050ad5746..87415b5ecd6b3f50a8025461e0843a062fb572c0 100644 (file)
@@ -19,11 +19,6 @@ enum fd_type {
     FD_UNKNOWN
 };
 
-enum {
-    FD_READ,
-    FD_WRITE
-};
-
 typedef enum {
     PEER_NONE,
     PEER_SIBLING,
index ab4fc57e4e653efc2fbd2207f00ee8e1b56aa294..8a69d44ca7ff7f295734de3f8ad01d4522c7eb66 100644 (file)
--- a/src/fd.cc
+++ b/src/fd.cc
@@ -223,19 +223,21 @@ fd_note(int fd, const char *s)
 }
 
 void
-fd_bytes(int fd, int len, unsigned int type)
+fd_bytes(const int fd, const int len, const IoDirection direction)
 {
     fde *F = &fd_table[fd];
 
     if (len < 0)
         return;
 
-    assert(type == FD_READ || type == FD_WRITE);
-
-    if (type == FD_READ)
+    switch (direction) {
+    case IoDirection::Read:
         F->bytes_read += len;
-    else
+        break;
+    case IoDirection::Write:
         F->bytes_written += len;
+        break;
+    }
 }
 
 void
index 918459d24d386b0479993364a757e48c21380862..aeeeecbf3d269ee6fd6185eeb50eb92af9ca5d4f 100644 (file)
--- a/src/fd.h
+++ b/src/fd.h
 #ifndef SQUID_FD_H_
 #define SQUID_FD_H_
 
+/// distinguishes reading/importing I/O operations from their writing/exporting counterparts
+enum class IoDirection {
+    Read,
+    Write
+};
+
 void fd_close(int fd);
 void fd_open(int fd, unsigned int type, const char *);
 void fd_note(int fd, const char *);
-void fd_bytes(int fd, int len, unsigned int type);
+void fd_bytes(int fd, int len, IoDirection);
 void fdDumpOpen(void);
 int fdUsageHigh(void);
 void fdAdjustReserved(void);
index 2309a9975b93f0b5550732fd712ed5842bf3ebd6..609e03a43d6b3b9278311bc3fce4b68e24496a78 100644 (file)
@@ -217,7 +217,7 @@ diskHandleWrite(int fd, void *)
 
     ++ statCounter.syscalls.disk.writes;
 
-    fd_bytes(fd, len, FD_WRITE);
+    fd_bytes(fd, len, IoDirection::Write);
 
     if (len < 0) {
         if (!ignoreErrno(xerrno)) {
@@ -422,7 +422,7 @@ diskHandleRead(int fd, void *data)
 
     ++ statCounter.syscalls.disk.reads;
 
-    fd_bytes(fd, len, FD_READ);
+    fd_bytes(fd, len, IoDirection::Read);
 
     if (len < 0) {
         if (ignoreErrno(xerrno)) {
index 79ae7c61878dd3b12c5c45bdc3cad9f69adce14b..56223e3066577650abe2f0328d9f24aef33180b0 100644 (file)
@@ -1704,7 +1704,7 @@ HttpStateData::wroteLast(const CommIoCbParams &io)
     // TODO: Extract common parts.
 
     if (io.size > 0) {
-        fd_bytes(io.fd, io.size, FD_WRITE);
+        fd_bytes(io.fd, io.size, IoDirection::Write);
         statCounter.server.all.kbytes_out += io.size;
         statCounter.server.http.kbytes_out += io.size;
     }
index 3c6863332fcc0063020b07e7b6c2cb4063648225..0dc7f0df9ce7effa86189d0d2a8ba59e6dfce02a 100644 (file)
@@ -38,7 +38,7 @@ logfileWriteWrapper(Logfile * lf, const void *buf, size_t len)
     size_t s;
     s = FD_WRITE_METHOD(ll->fd, (char const *) buf, len);
     int xerrno = errno;
-    fd_bytes(ll->fd, s, FD_WRITE);
+    fd_bytes(ll->fd, s, IoDirection::Write);
 
     if (s == len)
         return;
index 905f7ba30380f72c4c6ef8dd6d854f7ee617bf49..157e60179da263a9275a1fd35d54e2ba887470fe 100644 (file)
@@ -42,7 +42,7 @@ logfile_mod_udp_write(Logfile * lf, const char *buf, size_t len)
     l_udp_t *ll = (l_udp_t *) lf->data;
     ssize_t s;
     s = write(ll->fd, (char const *) buf, len);
-    fd_bytes(ll->fd, s, FD_WRITE);
+    fd_bytes(ll->fd, s, IoDirection::Write);
 #if 0
     // TODO: Enable after polishing to properly log these errors.
     if (s < 0) {
index 4a74005e7140bebaaf5091b893e9ea359e1fb426..1089a76b116cf0f27d265d1dafe0f87d1a7df298 100644 (file)
@@ -18,7 +18,7 @@ fde *fde::Table = nullptr;
 int fdNFree(void) STUB_RETVAL(-1)
 void fd_open(int, unsigned int, const char *) STUB
 void fd_close(int) STUB
-void fd_bytes(int, int, unsigned int) STUB
+void fd_bytes(int, int, IoDirection) STUB
 void fd_note(int, const char *) STUB
 void fdAdjustReserved() STUB