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

Side by Side Diff: runtime/bin/socket_android.cc

Issue 22634003: Replaced strerror() calls with threadsafe strerror_r() (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/process_macos.cc ('k') | runtime/bin/socket_linux.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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
(...skipping 29 matching lines...) Expand all
40 // Nothing to do on Android. 40 // Nothing to do on Android.
41 return true; 41 return true;
42 } 42 }
43 43
44 44
45 intptr_t Socket::Create(RawAddr addr) { 45 intptr_t Socket::Create(RawAddr addr) {
46 intptr_t fd; 46 intptr_t fd;
47 47
48 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); 48 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0));
49 if (fd < 0) { 49 if (fd < 0) {
50 Log::PrintErr("Error Create: %s\n", strerror(errno)); 50 const int kBufferSize = 1024;
51 char error_message[kBufferSize];
52 strerror_r(errno, error_message, kBufferSize);
53 Log::PrintErr("Error Create: %s\n", error_message);
51 return -1; 54 return -1;
52 } 55 }
53 56
54 FDUtils::SetCloseOnExec(fd); 57 FDUtils::SetCloseOnExec(fd);
55 return fd; 58 return fd;
56 } 59 }
57 60
58 61
59 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { 62 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
60 SocketAddress::SetAddrPort(&addr, port); 63 SocketAddress::SetAddrPort(&addr, port);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 117
115 118
116 intptr_t Socket::GetPort(intptr_t fd) { 119 intptr_t Socket::GetPort(intptr_t fd) {
117 ASSERT(fd >= 0); 120 ASSERT(fd >= 0);
118 RawAddr raw; 121 RawAddr raw;
119 socklen_t size = sizeof(raw); 122 socklen_t size = sizeof(raw);
120 if (TEMP_FAILURE_RETRY( 123 if (TEMP_FAILURE_RETRY(
121 getsockname(fd, 124 getsockname(fd,
122 &raw.addr, 125 &raw.addr,
123 &size))) { 126 &size))) {
124 Log::PrintErr("Error getsockname: %s\n", strerror(errno)); 127 const int kBufferSize = 1024;
128 char error_message[kBufferSize];
129 strerror_r(errno, error_message, kBufferSize);
130 Log::PrintErr("Error getsockname: %s\n", error_message);
125 return 0; 131 return 0;
126 } 132 }
127 return SocketAddress::GetAddrPort(&raw); 133 return SocketAddress::GetAddrPort(&raw);
128 } 134 }
129 135
130 136
131 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { 137 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) {
132 ASSERT(fd >= 0); 138 ASSERT(fd >= 0);
133 RawAddr raw; 139 RawAddr raw;
134 socklen_t size = sizeof(raw); 140 socklen_t size = sizeof(raw);
135 if (TEMP_FAILURE_RETRY( 141 if (TEMP_FAILURE_RETRY(
136 getpeername(fd, 142 getpeername(fd,
137 &raw.addr, 143 &raw.addr,
138 &size))) { 144 &size))) {
139 Log::PrintErr("Error getpeername: %s\n", strerror(errno)); 145 const int kBufferSize = 1024;
146 char error_message[kBufferSize];
147 strerror_r(errno, error_message, kBufferSize);
148 Log::PrintErr("Error getpeername: %s\n", error_message);
140 return false; 149 return false;
141 } 150 }
142 const void* src; 151 const void* src;
143 if (raw.ss.ss_family == AF_INET6) { 152 if (raw.ss.ss_family == AF_INET6) {
144 src = reinterpret_cast<const void*>(&raw.in6.sin6_addr); 153 src = reinterpret_cast<const void*>(&raw.in6.sin6_addr);
145 } else { 154 } else {
146 src = reinterpret_cast<const void*>(&raw.in.sin_addr); 155 src = reinterpret_cast<const void*>(&raw.in.sin_addr);
147 } 156 }
148 if (inet_ntop(raw.ss.ss_family, 157 if (inet_ntop(raw.ss.ss_family,
149 src, 158 src,
150 host, 159 host,
151 INET_ADDRSTRLEN) == NULL) { 160 INET_ADDRSTRLEN) == NULL) {
152 Log::PrintErr("Error inet_ntop: %s\n", strerror(errno)); 161 const int kBufferSize = 1024;
162 char error_message[kBufferSize];
163 strerror_r(errno, error_message, kBufferSize);
164 Log::PrintErr("Error inet_ntop: %s\n", error_message);
153 return false; 165 return false;
154 } 166 }
155 *port = SocketAddress::GetAddrPort(&raw); 167 *port = SocketAddress::GetAddrPort(&raw);
156 return true; 168 return true;
157 } 169 }
158 170
159 171
160 void Socket::GetError(intptr_t fd, OSError* os_error) { 172 void Socket::GetError(intptr_t fd, OSError* os_error) {
161 int errorNumber; 173 int errorNumber;
162 socklen_t len = sizeof(errorNumber); 174 socklen_t len = sizeof(errorNumber);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 IPPROTO_TCP, 375 IPPROTO_TCP,
364 TCP_NODELAY, 376 TCP_NODELAY,
365 reinterpret_cast<char *>(&on), 377 reinterpret_cast<char *>(&on),
366 sizeof(on))) == 0; 378 sizeof(on))) == 0;
367 } 379 }
368 380
369 } // namespace bin 381 } // namespace bin
370 } // namespace dart 382 } // namespace dart
371 383
372 #endif // defined(TARGET_OS_ANDROID) 384 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/process_macos.cc ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698