Nicolas Baradakis, 2005-07-07:
>
>
> Leandro Santi wrote:
>
> > IIRC these socket options (i.e. SO_SNDTIMEO, SO_RCVTIMEO) are not
> > available in Linux <= 2.2, so not every deployment could actually
> > use this feature.
>
> I searched a little and it seems that SO_RCVTIMEO and SO_SNDTIMEO are
> supported since Linux 2.3.41. I think we can do something like that:
>
> #ifdef SO_RCVTIMEO
> setsockopt (...)
> #endif
IMHO this will work with systems that don't #define these sockopts. But
Linux 2.2-based systems do actually #define these numbers, and don't
implement them:
% grep -r SO_...TIMEO /usr/include/
/usr/include/asm/socket.h:#define SO_RCVTIMEO 20
/usr/include/asm/socket.h:#define SO_SNDTIMEO 21
Looking at net/core/sock.c, it seems that getsockopt() will always
return {0, 0}:
int sock_getsockopt(struct socket *sock, int level, int optname,
char *optval, int *optlen)
{
...
switch(optname)
{
...
case SO_RCVTIMEO:
case SO_SNDTIMEO:
lv=sizeof(struct timeval);
v.tm.tv_sec=0;
v.tm.tv_usec=0;
break;
and from my understanting of the code, the setsockopt() will probably
return with errno=ENOPROTOOPT.
> In that way, the biggest majority will have the socket timeouts, and
> it doesn't break anything for the others.
>
> > Perhaps the patch could be modified so that network timeouts are
> > detected using read and write-select operations when the operating
> > system doesn't support such sockopts? This is IMHO a more portable
> > approach.
>
> I've read the comments under the bug #4143 and it seems that this
> approach isn't welcome by the developpers of MySQL.
>
> http://bugs.mysql.com/bug.php?id=4143
Perhaps this (slower) operation mode could be enabled on demand?
] I will add a request in our 'to-do' database about this and see if we
] could add a variable to have timeouts and only use 'slower code' in
] the case where the user have requested timeouts on read/write.
The rationale is that some applications (highly available Postfix, for
instance) won't probably notice this extra select() overhead ...
Leandro.
ps: Just for completeness. I'm currently doing timeout enforcement on
Postfix's dict_mysql driver by carefully closing the database descriptor
in signal (SIGALRM) handler context, and disabling automatic client
reconnects. This hack works pretty well for me ...