On Fri, 29 Apr 2005 11:16:23 +0200 Serassio Guido <[EMAIL PROTECTED]> wrote:
You make me laugh. squid2.5 use read/write/send/recv/ etc. as well as FD_READ_METHOD/FD_WRITE_METHOD.Hi Evgeny,
At 09.52 29/04/2005, Evgeny Kotsuba wrote:I don't understand why macros may be more efficient.FD_READ_METHOD/FD_WRITE_METHOD macros should be more efficient. Look here: http://cvs.sourceforge.net/viewcvs.py/squid/squid/src/fd.c?rev=1.7.16.9&only_with_tag=nt-2_5&view=auto
I use things like
int squid_fde::read(char *buf, int len)
{ int rc=-1;
switch(type)
{ case FD_SOCKET:
if(fh < 0)
{ debug(91, 0) ("squid_fde::read WARNING: fh=%i\n",fh);
rc = -1;
break;
}
rc = recv(fh, buf, len, 0 /* MSG_DONTWAIT ? */);
break;
case FD_NONE:
fatalf("Attempt to Read with FD_NONE type handle %i bytes", len);
return -1;
case FD_PIPE:
case FD_PIPE_READ:
rc = ::read(fh, buf, len);
break;
default:
rc = ::read(fh, buf, len);
}
if(rc>0) bytes_read += rc;
return rc;
}
Your code is more bigger and long, for any I/O you do:
- a function call with stack and context switch (your function seems to be not inlined)
- a fd_table lookup
- a decision
- call to the correct I/O function.
Macros are defined in squid.h as:
#define FD_READ_METHOD(fd, buf, len) (*fd_table[fd].read_method)(fd, buf, len)
#define FD_WRITE_METHOD(fd, buf, len) (*fd_table[fd].write_method)(fd, buf, len)
read_method and write_method pointers are initialized during fd_open
Everywher in the 2.5 and 3.0 source code you find already only the FD_READ_METHOD/FD_WRITE_METHOD macros instead of read() and write().
Whith macros for any I/O we do: - a fd_table lookup for the function pointer - call to the correct I/O function with the previous pointer
More faster.
It seems the same things are in squid3.
With classes we have only read/write/open/close to any handle and can control it in single place.
Why you don't see "bytes_read += rc;" that is fd_bytes() and that is one more function call etc. ?
SY,
Evgeny Kotsuba
