Avoid clashes with same-name constants defined by MS WIndows Socket API.
Also removed a few related ununsed macros.
#define _PATH_DEVNULL "NUL"
#endif
-#undef FD_CLOSE
-#undef FD_OPEN
-#undef FD_READ
-#undef FD_WRITE
-
#ifndef EISCONN
#define EISCONN WSAEISCONN
#endif
#define SID_MAX_LEN 64
-#define READ 1
-#define WRITE 0
-
#define SNMP_RESERVE1 0
#define SNMP_RESERVE2 1
#define SNMP_COMMIT 2
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;
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;
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
}
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) {
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;
}
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;
/* 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;
}
#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.
} 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;
break;
}
- fd_bytes(fd, len, FD_READ);
+ fd_bytes(fd, len, IoDirection::Read);
assert(N);
++(*N);
FD_UNKNOWN
};
-enum {
- FD_READ,
- FD_WRITE
-};
-
typedef enum {
PEER_NONE,
PEER_SIBLING,
}
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
#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);
++ statCounter.syscalls.disk.writes;
- fd_bytes(fd, len, FD_WRITE);
+ fd_bytes(fd, len, IoDirection::Write);
if (len < 0) {
if (!ignoreErrno(xerrno)) {
++ statCounter.syscalls.disk.reads;
- fd_bytes(fd, len, FD_READ);
+ fd_bytes(fd, len, IoDirection::Read);
if (len < 0) {
if (ignoreErrno(xerrno)) {
// 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;
}
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;
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) {
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