Skip to content

Commit

Permalink
Change from using writev to sendmsg so that MSG_NOSIGNAL flag can be …
Browse files Browse the repository at this point in the history
…used on Linux.
  • Loading branch information
Eamon Walshe committed Nov 25, 2011
1 parent 7010259 commit fcd5183
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
22 changes: 18 additions & 4 deletions src/LibAmqp/Buffer/BufferWrite.c
Expand Up @@ -16,21 +16,35 @@

#include <assert.h>
#include <limits.h>
#include <string.h>
#include <ctype.h>

#include <sys/types.h>
#include <sys/socket.h>

#include "Buffer/Buffer.h"
#include "Buffer/BufferInternal.h"
#include "Memory/Memory.h"
#include "Misc/Bits.h"

#include "Context/Context.h"

#include "debug_helper.h"

#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif

int amqp_buffer_write(int fd, amqp_buffer_t *buffer)
{
int iov_count;
struct iovec *io_vec = amqp_buffer_read_io_vec(buffer, &iov_count);
return writev(fd, io_vec, iov_count);
struct msghdr header = {
.msg_name = 0,
.msg_namelen = 0,
.msg_iov = io_vec,
.msg_iovlen = iov_count,
.msg_control = 0,
.msg_controllen = 0,
.msg_flags = 0
};

return sendmsg(fd, &header, MSG_NOSIGNAL);
}
10 changes: 7 additions & 3 deletions src/LibAmqp/Transport/LowLevel/Socket.c
Expand Up @@ -115,8 +115,12 @@ int amqp_set_socket_to_ignore_sigpipe(amqp_socket_t fd)
int value = 1;
return amqp_set_socket_option(fd, SO_NOSIGPIPE, value);
#else
#error "Ignore SIGPIPE"
#ifdef MSG_NOSIGNAL
return 0;
#else
#error "Neither SO_NOSIGPIPE nor MSG_NOSIGNAL is available. (Must ignore SIGPIPE)"
return -1;
#endif
#endif
#endif /* MSG_NOSIGNAL */
#endif /* SO_NOSIGPIPE */
#endif /* AMQP_WINDOWS_PORT */
}

0 comments on commit fcd5183

Please sign in to comment.