Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: net/socket/socket_descriptor.cc

Issue 2034433002: Try to tolerate running on contexts with SIGPIPE enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/socket/socket_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/socket_descriptor.h" 5 #include "net/socket/socket_descriptor.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #endif 10 #endif
11 11
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include <ws2tcpip.h> 13 #include <ws2tcpip.h>
14 #include "net/base/winsock_init.h" 14 #include "net/base/winsock_init.h"
15 #endif 15 #endif
16 16
17 #if defined(OS_MACOSX)
18 #include <unistd.h>
19 #endif
20
17 namespace net { 21 namespace net {
18 22
19 SocketDescriptor CreatePlatformSocket(int family, int type, int protocol) { 23 SocketDescriptor CreatePlatformSocket(int family, int type, int protocol) {
20 #if defined(OS_WIN) 24 #if defined(OS_WIN)
21 EnsureWinsockInit(); 25 EnsureWinsockInit();
22 SocketDescriptor result = ::WSASocket(family, type, protocol, nullptr, 0, 26 SocketDescriptor result = ::WSASocket(family, type, protocol, nullptr, 0,
23 WSA_FLAG_OVERLAPPED); 27 WSA_FLAG_OVERLAPPED);
24 if (result != kInvalidSocket && family == AF_INET6) { 28 if (result != kInvalidSocket && family == AF_INET6) {
25 DWORD value = 0; 29 DWORD value = 0;
26 if (setsockopt(result, IPPROTO_IPV6, IPV6_V6ONLY, 30 if (setsockopt(result, IPPROTO_IPV6, IPV6_V6ONLY,
27 reinterpret_cast<const char*>(&value), sizeof(value))) { 31 reinterpret_cast<const char*>(&value), sizeof(value))) {
28 closesocket(result); 32 closesocket(result);
29 return kInvalidSocket; 33 return kInvalidSocket;
30 } 34 }
31 } 35 }
32 return result; 36 return result;
33 #else // OS_WIN 37 #else // OS_WIN
34 return ::socket(family, type, protocol); 38 SocketDescriptor result = ::socket(family, type, protocol);
39 #if defined(OS_MACOSX)
40 // Disable SIGPIPE on this socket. Although Chromium globally disables
41 // SIGPIPE, the net stack may be used in other consumers which do not do
42 // this. SO_NOSIGPIPE is a Mac-only API. On Linux, it is a flag on send.
43 if (result != kInvalidSocket) {
44 int value = 1;
45 if (setsockopt(result, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value))) {
46 close(result);
47 return kInvalidSocket;
48 }
49 }
50 #endif
51 return result;
35 #endif // OS_WIN 52 #endif // OS_WIN
36 53
37 } 54 }
38 55
39 } // namespace net 56 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/socket/socket_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698