diff --git a/std/c/linux/socket.d b/std/c/linux/socket.d index ad31d0964..03bdb71a3 100644 --- a/std/c/linux/socket.d +++ b/std/c/linux/socket.d @@ -236,6 +236,7 @@ enum: int MSG_OOB = 0x1, MSG_PEEK = 0x2, MSG_DONTROUTE = 0x4, + MSG_NOSIGNAL = 0x4000, } diff --git a/std/c/windows/winsock.d b/std/c/windows/winsock.d index 87ee5175e..178d9b9b1 100644 --- a/std/c/windows/winsock.d +++ b/std/c/windows/winsock.d @@ -381,6 +381,7 @@ enum: int MSG_OOB = 0x1, MSG_PEEK = 0x2, MSG_DONTROUTE = 0x4, + MSG_NOSIGNAL = 0x0, /// not supported on win32, would be 0x4000 if it was } diff --git a/std/socket.d b/std/socket.d index c84a9f066..5dfc54af9 100644 --- a/std/socket.d +++ b/std/socket.d @@ -729,11 +729,12 @@ enum SocketShutdown: int /// Flags may be OR'ed together: enum SocketFlags: int { - NONE = 0, /// no flags specified + NONE = 0, /// no flags specified - OOB = MSG_OOB, /// out-of-band stream data - PEEK = MSG_PEEK, /// peek at incoming data without removing it from the queue, only for receiving + OOB = MSG_OOB, /// out-of-band stream data + PEEK = MSG_PEEK, /// peek at incoming data without removing it from the queue, only for receiving DONTROUTE = MSG_DONTROUTE, /// data should not be subject to routing; this flag may be ignored. Only for sending + NOSIGNAL = MSG_NOSIGNAL, /// don't send SIGPIPE signal on socket write error and instead return EPIPE } @@ -1270,6 +1271,7 @@ class Socket //returns number of bytes actually sent, or -1 on error int send(void[] buf, SocketFlags flags) { + flags |= SocketFlags.NOSIGNAL; int sent = .send(sock, buf.ptr, buf.length, cast(int)flags); return sent; } @@ -1277,7 +1279,7 @@ class Socket /// ditto int send(void[] buf) { - return send(buf, SocketFlags.NONE); + return send(buf, SocketFlags.NOSIGNAL); } /** @@ -1285,6 +1287,7 @@ class Socket */ int sendTo(void[] buf, SocketFlags flags, Address to) { + flags |= SocketFlags.NOSIGNAL; int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, to.name(), to.nameLen()); return sent; } @@ -1300,6 +1303,7 @@ class Socket /// ditto int sendTo(void[] buf, SocketFlags flags) { + flags |= SocketFlags.NOSIGNAL; int sent = .sendto(sock, buf.ptr, buf.length, cast(int)flags, null, 0); return sent; } diff --git a/unittest.d b/unittest.d index fcd96483b..0e43eee8a 100644 --- a/unittest.d +++ b/unittest.d @@ -52,6 +52,7 @@ import std.uni; import std.file; import std.signals; import std.cpuid; +import std.socket; int main(char[][] args) {