Skip to content

Commit

Permalink
* src/ne_socket.c (write_raw): Use send(,,,MSG_NOSIGNAL) if available.
Browse files Browse the repository at this point in the history
  (writev_raw): Use sendmsg(,,MSG_NOSIGNAL) if available.

* macros/neon.m4 (NEON_COMMON_CHECKS): Check for sendmsg.
  • Loading branch information
notroj committed Nov 21, 2020
1 parent 0f2d079 commit 3870f24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion macros/neon.m4
Expand Up @@ -614,7 +614,7 @@ NE_LARGEFILE
AC_REPLACE_FUNCS(strcasecmp)
AC_CHECK_FUNCS(signal setvbuf setsockopt stpcpy poll fcntl getsockopt)
AC_CHECK_FUNCS(signal setvbuf setsockopt stpcpy poll fcntl getsockopt sendmsg)
if test "x${ac_cv_func_poll}${ac_cv_header_sys_poll_h}y" = "xyesyesy"; then
AC_DEFINE([NE_USE_POLL], 1, [Define if poll() should be used])
Expand Down
19 changes: 18 additions & 1 deletion src/ne_socket.c
Expand Up @@ -536,6 +536,12 @@ static ssize_t read_raw(ne_socket *sock, char *buffer, size_t len)
#define MAP_ERR(e) (NE_ISCLOSED(e) ? NE_SOCK_CLOSED : \
(NE_ISRESET(e) ? NE_SOCK_RESET : NE_SOCK_ERROR))

#ifdef MSG_NOSIGNAL
#define SEND_FLAGS MSG_NOSIGNAL
#else
#define SEND_FLAGS (0)
#endif

static ssize_t write_raw(ne_socket *sock, const char *data, size_t length)
{
ssize_t ret;
Expand All @@ -547,7 +553,7 @@ static ssize_t write_raw(ne_socket *sock, const char *data, size_t length)
#endif

do {
ret = send(sock->fd, data, length, 0);
ret = send(sock->fd, data, length, SEND_FLAGS);
} while (ret == -1 && NE_ISINTR(ne_errno));

if (ret < 0) {
Expand Down Expand Up @@ -576,6 +582,17 @@ static ssize_t writev_raw(ne_socket *sock, const struct ne_iovec *vector, int co
ret = total;

ne_free(wasvector);
#elif defined(MSG_NOSIGNAL) && defined(HAVE_SENDMSG)
struct msghdr m;

memset(&m, 0, sizeof m);
m.msg_iov = (struct iovec *)vector;
m.msg_iovlen = count;

do {
ret = sendmsg(sock->fd, &m, MSG_NOSIGNAL);
} while (ret == -1 && NE_ISINTR(ne_errno));

#else
const struct iovec *vec = (const struct iovec *) vector;

Expand Down

0 comments on commit 3870f24

Please sign in to comment.