apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken Simpson <ksimp...@larch.mailchannels.com>
Subject Unable to set sockets to non blocking on OpenBSD
Date Fri, 27 Aug 2004 02:30:33 GMT
(Preamble -- this problem was reported on the modperl mailing list
earlier this week; I was advised to post it here -- I hope I have come
to the right place!)

Before actually setting the blocking or nonblocking state of a socket
by making a system call, the apr_socket_opt_set() function first
checks whether its cached copy of the socket state indicates that the
blocking state needs to be changed:

 /* network_io/unix/sockopt.c */
 /* If the blocking state needs to be changed, then...
 if (apr_is_option_set(sock->netmask, APR_SO_NONBLOCK) != on) {
  /* .. go ahead and toggle the blocking state */

Unfortunately, in APR, Unix sockets are assumed to initially be
blocking even though on OpenBSD this appears to not be true:

  /* network_io/unix/sockets.c */
  static void set_socket_vars(apr_socket_t *sock, int family,
    int type, int protocol)
      sock->type = type;
      sock->protocol = protocol;
      apr_sockaddr_vars_set(sock->local_addr, family, 0);
      apr_sockaddr_vars_set(sock->remote_addr, family, 0);
      sock->netmask = 0;
  #if defined(BEOS) && !defined(BEOS_BONE)
      /* BeOS pre-BONE has TCP_NODELAY on by default and it can't be
       * switched off!
      sock->netmask |= APR_TCP_NODELAY;

(setting sock->netmask to 0 means that the socket is blocking)

So when you try to set a socket to blocking, Apache just skips your
request because.. obviously there's no need to set a blocking socket
to blocking again.

The permanent fix is to patch up set_socket_vars() that it sets
blocking off by default on OpenBSD; e.g.:

  sock->netmask = 0;
  sock->netmask |= APR_SO_NONBLOCK;

I'd love to put together a full patch, but I don't know what #define I
should #ifdef to check whether OpenBSD is the building platform. Can
someone tell me?


MailChannels: Imagine no more spam

View raw message