On Sun, Sep 20 2020, Nick Gasson <n...@nickg.me.uk> wrote: > Hi, > > Recently I was porting a program that uses Boost Asio to OpenBSD and > found it was exiting frequently with SIGPIPE. This doesn't happen on > Linux because on that platform Asio passes the MSG_NOSIGNAL flag to > sendmsg(2). (It doesn't on FreeBSD either because Asio uses the > SO_NOSIGNAL socket option there.) > > The patch below for Boost 1.67 sets MSG_NOSIGNAL on OpenBSD too. Could > you add it to the patches in the ports tree? I've also submitted it > upstream [1] but not sure if/when it will be applied.
I see the discussion at https://github.com/chriskohlhoff/asio/pull/549 In the patch below I would replace +#if defined(__linux__) || defined(__OpenBSD__) ... #endif // defined(__linux__) with +#if defined(MSG_NOSIGNAL) ... +#endif // defined(MSG_NOSIGNAL) as suggested by Brad. Simple, no need to fiddle with POSIX versions. I think it would be a worthwhile addition to the boost port before 6.8 is tagged. Rafael, do you want to handle this? > --- boost/asio/detail/impl/socket_ops.ipp.orig Sun Sep 20 09:48:05 2020 > +++ boost/asio/detail/impl/socket_ops.ipp Sun Sep 20 09:52:00 2020 > @@ -1178,7 +1178,7 @@ > msghdr msg = msghdr(); > msg.msg_iov = const_cast<buf*>(bufs); > msg.msg_iovlen = static_cast<int>(count); > -#if defined(__linux__) > +#if defined(__linux__) || defined(__OpenBSD__) > flags |= MSG_NOSIGNAL; > #endif // defined(__linux__) > signed_size_type result = error_wrapper(::sendmsg(s, &msg, flags), ec); > @@ -1307,7 +1307,7 @@ > msg.msg_namelen = static_cast<int>(addrlen); > msg.msg_iov = const_cast<buf*>(bufs); > msg.msg_iovlen = static_cast<int>(count); > -#if defined(__linux__) > +#if defined(__linux__) || defined(__OpenBSD__) > flags |= MSG_NOSIGNAL; > #endif // defined(__linux__) > signed_size_type result = error_wrapper(::sendmsg(s, &msg, flags), ec); > > > [1] https://github.com/chriskohlhoff/asio/pull/549 > > -- > Thanks, > Nick > -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE