From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Fri, 8 Dec 2023 21:26:00 +0000 (+0000) Subject: Declutter FD_WRITE and FD_READ (#1614) X-Git-Tag: SQUID_7_0_1~262 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5baf2c78554e319b6798bbf9b6fbb98ad0a7fd42;p=thirdparty%2Fsquid.git Declutter FD_WRITE and FD_READ (#1614) Avoid clashes with same-name constants defined by MS WIndows Socket API. Also removed a few related ununsed macros. --- diff --git a/compat/os/mswindows.h b/compat/os/mswindows.h index 5446bb8adb..2fba4ed9c7 100644 --- a/compat/os/mswindows.h +++ b/compat/os/mswindows.h @@ -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 diff --git a/include/snmp_impl.h b/include/snmp_impl.h index ac346f4a03..f949111906 100644 --- a/include/snmp_impl.h +++ b/include/snmp_impl.h @@ -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 diff --git a/src/DiskIO/IpcIo/IpcIoFile.cc b/src/DiskIO/IpcIo/IpcIoFile.cc index c156a1dc26..449a6c97b0 100644 --- a/src/DiskIO/IpcIo/IpcIoFile.cc +++ b/src/DiskIO/IpcIo/IpcIoFile.cc @@ -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; diff --git a/src/clients/Client.cc b/src/clients/Client.cc index cbf5693e28..60ab7d0878 100644 --- a/src/clients/Client.cc +++ b/src/clients/Client.cc @@ -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 } diff --git a/src/clients/FtpClient.cc b/src/clients/FtpClient.cc index 3630766f83..fe73783246 100644 --- a/src/clients/FtpClient.cc +++ b/src/clients/FtpClient.cc @@ -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; } diff --git a/src/comm/Read.cc b/src/comm/Read.cc index 18913444ad..452a8d5605 100644 --- a/src/comm/Read.cc +++ b/src/comm/Read.cc @@ -94,7 +94,7 @@ Comm::ReadNow(CommIoCbParams ¶ms, 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; diff --git a/src/comm/Write.cc b/src/comm/Write.cc index e6f2770a4c..2b9d8228e0 100644 --- a/src/comm/Write.cc +++ b/src/comm/Write.cc @@ -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. diff --git a/src/dns_internal.cc b/src/dns_internal.cc index c080cf817b..e684e1433b 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -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); diff --git a/src/enums.h b/src/enums.h index 4ad4f0c943..87415b5ecd 100644 --- a/src/enums.h +++ b/src/enums.h @@ -19,11 +19,6 @@ enum fd_type { FD_UNKNOWN }; -enum { - FD_READ, - FD_WRITE -}; - typedef enum { PEER_NONE, PEER_SIBLING, diff --git a/src/fd.cc b/src/fd.cc index ab4fc57e4e..8a69d44ca7 100644 --- 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 diff --git a/src/fd.h b/src/fd.h index 918459d24d..aeeeecbf3d 100644 --- a/src/fd.h +++ b/src/fd.h @@ -11,10 +11,16 @@ #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); diff --git a/src/fs_io.cc b/src/fs_io.cc index 2309a9975b..609e03a43d 100644 --- a/src/fs_io.cc +++ b/src/fs_io.cc @@ -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)) { diff --git a/src/http.cc b/src/http.cc index 79ae7c6187..56223e3066 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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; } diff --git a/src/log/ModStdio.cc b/src/log/ModStdio.cc index 3c6863332f..0dc7f0df9c 100644 --- a/src/log/ModStdio.cc +++ b/src/log/ModStdio.cc @@ -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; diff --git a/src/log/ModUdp.cc b/src/log/ModUdp.cc index 905f7ba303..157e60179d 100644 --- a/src/log/ModUdp.cc +++ b/src/log/ModUdp.cc @@ -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) { diff --git a/src/tests/stub_fd.cc b/src/tests/stub_fd.cc index 4a74005e71..1089a76b11 100644 --- a/src/tests/stub_fd.cc +++ b/src/tests/stub_fd.cc @@ -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