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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
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/signal_blocker.h" |
22 #include "bin/socket.h" | 22 #include "bin/socket.h" |
| 23 #include "vm/thread.h" |
23 | 24 |
24 | 25 |
25 namespace dart { | 26 namespace dart { |
26 namespace bin { | 27 namespace bin { |
27 | 28 |
28 SocketAddress::SocketAddress(struct sockaddr* sa) { | 29 SocketAddress::SocketAddress(struct sockaddr* sa) { |
29 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); | 30 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
30 if (!Socket::FormatNumericAddress( | 31 if (!Socket::FormatNumericAddress( |
31 reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { | 32 reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { |
32 as_string_[0] = 0; | 33 as_string_[0] = 0; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 strerror_r(errno, error_buf, kBufferSize)); | 199 strerror_r(errno, error_buf, kBufferSize)); |
199 return NULL; | 200 return NULL; |
200 } | 201 } |
201 *port = SocketAddress::GetAddrPort(&raw); | 202 *port = SocketAddress::GetAddrPort(&raw); |
202 return new SocketAddress(&raw.addr); | 203 return new SocketAddress(&raw.addr); |
203 } | 204 } |
204 | 205 |
205 | 206 |
206 void Socket::GetError(intptr_t fd, OSError* os_error) { | 207 void Socket::GetError(intptr_t fd, OSError* os_error) { |
207 int len = sizeof(errno); | 208 int len = sizeof(errno); |
| 209 int err = 0; |
208 getsockopt(fd, | 210 getsockopt(fd, |
209 SOL_SOCKET, | 211 SOL_SOCKET, |
210 SO_ERROR, | 212 SO_ERROR, |
211 &errno, | 213 &err, |
212 reinterpret_cast<socklen_t*>(&len)); | 214 reinterpret_cast<socklen_t*>(&len)); |
| 215 errno = err; |
213 os_error->SetCodeAndMessage(OSError::kSystem, errno); | 216 os_error->SetCodeAndMessage(OSError::kSystem, errno); |
214 } | 217 } |
215 | 218 |
216 | 219 |
217 int Socket::GetType(intptr_t fd) { | 220 int Socket::GetType(intptr_t fd) { |
218 struct stat64 buf; | 221 struct stat64 buf; |
219 int result = fstat64(fd, &buf); | 222 int result = fstat64(fd, &buf); |
220 if (result == -1) return -1; | 223 if (result == -1) return -1; |
221 if (S_ISCHR(buf.st_mode)) return File::kTerminal; | 224 if (S_ISCHR(buf.st_mode)) return File::kTerminal; |
222 if (S_ISFIFO(buf.st_mode)) return File::kPipe; | 225 if (S_ISFIFO(buf.st_mode)) return File::kPipe; |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 mreq.gr_interface = interfaceIndex; | 626 mreq.gr_interface = interfaceIndex; |
624 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 627 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
625 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( | 628 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( |
626 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 629 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
627 } | 630 } |
628 | 631 |
629 } // namespace bin | 632 } // namespace bin |
630 } // namespace dart | 633 } // namespace dart |
631 | 634 |
632 #endif // defined(TARGET_OS_LINUX) | 635 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |