socket: Use alternatives if MSG_NOSIGNAL is unavailable
Only Linux has MSG_NOSIGNAL as a socket flag (see http://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properly ) which makes compilation fail on other OSes. The BSDs and OS X have SO_NOSIGPIPE which implements the same thing but others like Solaris don't even have that (see http://stackoverflow.com/questions/2205455/detecting-broken-pipe-in-solaris-send-call )... Work around this by checking using MSG_NOSIGNAL or SO_NOSIGPIPE if available otherwise don't set anything at all so we at least continue to compile.
This commit is contained in:
11
lib/socket.c
11
lib/socket.c
@@ -643,6 +643,13 @@ iscsi_write_to_socket(struct iscsi_context *iscsi)
|
||||
size_t total;
|
||||
struct iscsi_pdu *pdu;
|
||||
static char padding_buf[3];
|
||||
int socket_flags = 0;
|
||||
|
||||
#ifdef MSG_NOSIGNAL
|
||||
socket_flags |= MSG_NOSIGNAL;
|
||||
#elif SO_NOSIGPIPE
|
||||
socket_flags |= SO_NOSIGPIPE;
|
||||
#endif
|
||||
|
||||
if (iscsi->fd == -1) {
|
||||
iscsi_set_error(iscsi, "trying to write but not connected");
|
||||
@@ -697,7 +704,7 @@ iscsi_write_to_socket(struct iscsi_context *iscsi)
|
||||
count = send(iscsi->fd,
|
||||
pdu->outdata.data + pdu->outdata_written,
|
||||
pdu->outdata.size - pdu->outdata_written,
|
||||
MSG_NOSIGNAL);
|
||||
socket_flags);
|
||||
if (count == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
return 0;
|
||||
@@ -746,7 +753,7 @@ iscsi_write_to_socket(struct iscsi_context *iscsi)
|
||||
|
||||
/* Write padding */
|
||||
if (pdu->payload_written < total) {
|
||||
count = send(iscsi->fd, padding_buf, total - pdu->payload_written, MSG_NOSIGNAL);
|
||||
count = send(iscsi->fd, padding_buf, total - pdu->payload_written, socket_flags);
|
||||
if (count == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user