OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
9 #include <stdio.h> // NOLINT | 9 #include <stdio.h> // NOLINT |
10 #include <stdlib.h> // NOLINT | 10 #include <stdlib.h> // NOLINT |
11 #include <string.h> // NOLINT | 11 #include <string.h> // NOLINT |
12 #include <sys/stat.h> // NOLINT | 12 #include <sys/stat.h> // NOLINT |
13 #include <unistd.h> // NOLINT | 13 #include <unistd.h> // NOLINT |
14 #include <net/if.h> // NOLINT | 14 #include <net/if.h> // NOLINT |
15 #include <netinet/tcp.h> // NOLINT | 15 #include <netinet/tcp.h> // NOLINT |
16 #include <ifaddrs.h> // NOLINT | 16 #include <ifaddrs.h> // NOLINT |
17 | 17 |
18 #include "bin/fdutils.h" | 18 #include "bin/fdutils.h" |
19 #include "bin/file.h" | 19 #include "bin/file.h" |
20 #include "bin/log.h" | 20 #include "bin/log.h" |
| 21 #include "bin/signal_blocker.h" |
21 #include "bin/socket.h" | 22 #include "bin/socket.h" |
22 | 23 |
23 | 24 |
24 namespace dart { | 25 namespace dart { |
25 namespace bin { | 26 namespace bin { |
26 | 27 |
27 SocketAddress::SocketAddress(struct sockaddr* sa) { | 28 SocketAddress::SocketAddress(struct sockaddr* sa) { |
28 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); | 29 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
29 if (!Socket::FormatNumericAddress( | 30 if (!Socket::FormatNumericAddress( |
30 reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { | 31 reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 100 } |
100 | 101 |
101 | 102 |
102 intptr_t Socket::Available(intptr_t fd) { | 103 intptr_t Socket::Available(intptr_t fd) { |
103 return FDUtils::AvailableBytes(fd); | 104 return FDUtils::AvailableBytes(fd); |
104 } | 105 } |
105 | 106 |
106 | 107 |
107 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 108 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
108 ASSERT(fd >= 0); | 109 ASSERT(fd >= 0); |
| 110 // Block profile interrupts while making I/O call. |
| 111 ThreadSignalBlocker tsb(SIGPROF); |
109 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); | 112 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); |
110 ASSERT(EAGAIN == EWOULDBLOCK); | 113 ASSERT(EAGAIN == EWOULDBLOCK); |
111 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 114 if (read_bytes == -1 && errno == EWOULDBLOCK) { |
112 // If the read would block we need to retry and therefore return 0 | 115 // If the read would block we need to retry and therefore return 0 |
113 // as the number of bytes written. | 116 // as the number of bytes written. |
114 read_bytes = 0; | 117 read_bytes = 0; |
115 } | 118 } |
116 return read_bytes; | 119 return read_bytes; |
117 } | 120 } |
118 | 121 |
119 | 122 |
120 int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes, | 123 int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes, |
121 RawAddr* addr) { | 124 RawAddr* addr) { |
122 ASSERT(fd >= 0); | 125 ASSERT(fd >= 0); |
123 socklen_t addr_len = sizeof(addr->ss); | 126 socklen_t addr_len = sizeof(addr->ss); |
| 127 // Block profile interrupts while making I/O call. |
| 128 ThreadSignalBlocker tsb(SIGPROF); |
124 ssize_t read_bytes = | 129 ssize_t read_bytes = |
125 TEMP_FAILURE_RETRY( | 130 TEMP_FAILURE_RETRY( |
126 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); | 131 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); |
127 if (read_bytes == -1 && errno == EWOULDBLOCK) { | 132 if (read_bytes == -1 && errno == EWOULDBLOCK) { |
128 // If the read would block we need to retry and therefore return 0 | 133 // If the read would block we need to retry and therefore return 0 |
129 // as the number of bytes written. | 134 // as the number of bytes written. |
130 read_bytes = 0; | 135 read_bytes = 0; |
131 } | 136 } |
132 return read_bytes; | 137 return read_bytes; |
133 } | 138 } |
134 | 139 |
135 | 140 |
136 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 141 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
137 ASSERT(fd >= 0); | 142 ASSERT(fd >= 0); |
| 143 // Block profile interrupts while making I/O call. |
| 144 ThreadSignalBlocker tsb(SIGPROF); |
138 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); | 145 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); |
139 ASSERT(EAGAIN == EWOULDBLOCK); | 146 ASSERT(EAGAIN == EWOULDBLOCK); |
140 if (written_bytes == -1 && errno == EWOULDBLOCK) { | 147 if (written_bytes == -1 && errno == EWOULDBLOCK) { |
141 // If the would block we need to retry and therefore return 0 as | 148 // If the would block we need to retry and therefore return 0 as |
142 // the number of bytes written. | 149 // the number of bytes written. |
143 written_bytes = 0; | 150 written_bytes = 0; |
144 } | 151 } |
145 return written_bytes; | 152 return written_bytes; |
146 } | 153 } |
147 | 154 |
148 | 155 |
149 int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes, | 156 int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes, |
150 RawAddr addr) { | 157 RawAddr addr) { |
151 ASSERT(fd >= 0); | 158 ASSERT(fd >= 0); |
| 159 // Block profile interrupts while making I/O call. |
| 160 ThreadSignalBlocker tsb(SIGPROF); |
152 ssize_t written_bytes = | 161 ssize_t written_bytes = |
153 TEMP_FAILURE_RETRY( | 162 TEMP_FAILURE_RETRY( |
154 sendto(fd, buffer, num_bytes, 0, | 163 sendto(fd, buffer, num_bytes, 0, |
155 &addr.addr, SocketAddress::GetAddrLength(&addr))); | 164 &addr.addr, SocketAddress::GetAddrLength(&addr))); |
156 ASSERT(EAGAIN == EWOULDBLOCK); | 165 ASSERT(EAGAIN == EWOULDBLOCK); |
157 if (written_bytes == -1 && errno == EWOULDBLOCK) { | 166 if (written_bytes == -1 && errno == EWOULDBLOCK) { |
158 // If the would block we need to retry and therefore return 0 as | 167 // If the would block we need to retry and therefore return 0 as |
159 // the number of bytes written. | 168 // the number of bytes written. |
160 written_bytes = 0; | 169 written_bytes = 0; |
161 } | 170 } |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 | 663 |
655 bool Socket::LeaveMulticast( | 664 bool Socket::LeaveMulticast( |
656 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { | 665 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { |
657 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); | 666 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); |
658 } | 667 } |
659 | 668 |
660 } // namespace bin | 669 } // namespace bin |
661 } // namespace dart | 670 } // namespace dart |
662 | 671 |
663 #endif // defined(TARGET_OS_MACOS) | 672 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |