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 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 intptr_t backlog) { | 193 intptr_t backlog) { |
194 intptr_t fd; | 194 intptr_t fd; |
195 struct sockaddr_in server_address; | 195 struct sockaddr_in server_address; |
196 | 196 |
197 in_addr_t s_addr = inet_addr(host); | 197 in_addr_t s_addr = inet_addr(host); |
198 if (s_addr == INADDR_NONE) { | 198 if (s_addr == INADDR_NONE) { |
199 return -5; | 199 return -5; |
200 } | 200 } |
201 | 201 |
202 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); | 202 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); |
203 if (fd < 0) { | 203 if (fd < 0) return -1; |
204 Log::PrintErr("Error CreateBind: %s\n", strerror(errno)); | |
205 return -1; | |
206 } | |
207 | 204 |
208 FDUtils::SetCloseOnExec(fd); | 205 FDUtils::SetCloseOnExec(fd); |
209 | 206 |
210 int optval = 1; | 207 int optval = 1; |
211 VOID_TEMP_FAILURE_RETRY( | 208 VOID_TEMP_FAILURE_RETRY( |
212 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); | 209 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
213 | 210 |
214 server_address.sin_family = AF_INET; | 211 server_address.sin_family = AF_INET; |
215 server_address.sin_port = htons(port); | 212 server_address.sin_port = htons(port); |
216 server_address.sin_addr.s_addr = s_addr; | 213 server_address.sin_addr.s_addr = s_addr; |
217 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); | 214 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); |
218 | 215 |
219 if (TEMP_FAILURE_RETRY( | 216 if (TEMP_FAILURE_RETRY( |
220 bind(fd, | 217 bind(fd, |
221 reinterpret_cast<struct sockaddr *>(&server_address), | 218 reinterpret_cast<struct sockaddr *>(&server_address), |
222 sizeof(server_address))) < 0) { | 219 sizeof(server_address))) < 0) { |
223 VOID_TEMP_FAILURE_RETRY(close(fd)); | 220 VOID_TEMP_FAILURE_RETRY(close(fd)); |
224 Log::PrintErr("Error Bind: %s\n", strerror(errno)); | |
225 return -1; | 221 return -1; |
226 } | 222 } |
227 | 223 |
228 if (TEMP_FAILURE_RETRY(listen(fd, backlog)) != 0) { | 224 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { |
229 Log::PrintErr("Error Listen: %s\n", strerror(errno)); | 225 TEMP_FAILURE_RETRY(close(fd)); |
230 return -1; | 226 return -1; |
231 } | 227 } |
232 | 228 |
233 FDUtils::SetNonBlocking(fd); | 229 FDUtils::SetNonBlocking(fd); |
234 return fd; | 230 return fd; |
235 } | 231 } |
236 | 232 |
237 | 233 |
238 intptr_t ServerSocket::Accept(intptr_t fd) { | 234 intptr_t ServerSocket::Accept(intptr_t fd) { |
239 intptr_t socket; | 235 intptr_t socket; |
(...skipping 20 matching lines...) Expand all Loading... |
260 int err = TEMP_FAILURE_RETRY(close(fd)); | 256 int err = TEMP_FAILURE_RETRY(close(fd)); |
261 if (err != 0) { | 257 if (err != 0) { |
262 const int kBufferSize = 1024; | 258 const int kBufferSize = 1024; |
263 char error_message[kBufferSize]; | 259 char error_message[kBufferSize]; |
264 strerror_r(errno, error_message, kBufferSize); | 260 strerror_r(errno, error_message, kBufferSize); |
265 Log::PrintErr("%s\n", error_message); | 261 Log::PrintErr("%s\n", error_message); |
266 } | 262 } |
267 } | 263 } |
268 | 264 |
269 #endif // defined(TARGET_OS_MACOS) | 265 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |