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 <errno.h> | 5 #include <errno.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 19 matching lines...) Expand all Loading... |
30 if (fd < 0) { | 30 if (fd < 0) { |
31 Log::PrintErr("Error CreateConnect: %s\n", strerror(errno)); | 31 Log::PrintErr("Error CreateConnect: %s\n", strerror(errno)); |
32 return -1; | 32 return -1; |
33 } | 33 } |
34 | 34 |
35 FDUtils::SetCloseOnExec(fd); | 35 FDUtils::SetCloseOnExec(fd); |
36 FDUtils::SetNonBlocking(fd); | 36 FDUtils::SetNonBlocking(fd); |
37 | 37 |
38 server = gethostbyname(host); | 38 server = gethostbyname(host); |
39 if (server == NULL) { | 39 if (server == NULL) { |
40 TEMP_FAILURE_RETRY(close(fd)); | 40 VOID_TEMP_FAILURE_RETRY(close(fd)); |
41 Log::PrintErr("Error CreateConnect: %s\n", strerror(errno)); | 41 Log::PrintErr("Error CreateConnect: %s\n", strerror(errno)); |
42 return -1; | 42 return -1; |
43 } | 43 } |
44 | 44 |
45 server_address.sin_family = AF_INET; | 45 server_address.sin_family = AF_INET; |
46 server_address.sin_port = htons(port); | 46 server_address.sin_port = htons(port); |
47 bcopy(server->h_addr, &server_address.sin_addr.s_addr, server->h_length); | 47 bcopy(server->h_addr, &server_address.sin_addr.s_addr, server->h_length); |
48 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); | 48 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); |
49 intptr_t result = TEMP_FAILURE_RETRY( | 49 intptr_t result = TEMP_FAILURE_RETRY( |
50 connect(fd, | 50 connect(fd, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 198 |
199 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); | 199 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); |
200 if (fd < 0) { | 200 if (fd < 0) { |
201 Log::PrintErr("Error CreateBind: %s\n", strerror(errno)); | 201 Log::PrintErr("Error CreateBind: %s\n", strerror(errno)); |
202 return -1; | 202 return -1; |
203 } | 203 } |
204 | 204 |
205 FDUtils::SetCloseOnExec(fd); | 205 FDUtils::SetCloseOnExec(fd); |
206 | 206 |
207 int optval = 1; | 207 int optval = 1; |
208 TEMP_FAILURE_RETRY( | 208 VOID_TEMP_FAILURE_RETRY( |
209 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); | 209 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
210 | 210 |
211 server_address.sin_family = AF_INET; | 211 server_address.sin_family = AF_INET; |
212 server_address.sin_port = htons(port); | 212 server_address.sin_port = htons(port); |
213 server_address.sin_addr.s_addr = s_addr; | 213 server_address.sin_addr.s_addr = s_addr; |
214 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); | 214 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); |
215 | 215 |
216 if (TEMP_FAILURE_RETRY( | 216 if (TEMP_FAILURE_RETRY( |
217 bind(fd, | 217 bind(fd, |
218 reinterpret_cast<struct sockaddr *>(&server_address), | 218 reinterpret_cast<struct sockaddr *>(&server_address), |
219 sizeof(server_address))) < 0) { | 219 sizeof(server_address))) < 0) { |
220 TEMP_FAILURE_RETRY(close(fd)); | 220 VOID_TEMP_FAILURE_RETRY(close(fd)); |
221 Log::PrintErr("Error Bind: %s\n", strerror(errno)); | 221 Log::PrintErr("Error Bind: %s\n", strerror(errno)); |
222 return -1; | 222 return -1; |
223 } | 223 } |
224 | 224 |
225 if (TEMP_FAILURE_RETRY(listen(fd, backlog)) != 0) { | 225 if (TEMP_FAILURE_RETRY(listen(fd, backlog)) != 0) { |
226 Log::PrintErr("Error Listen: %s\n", strerror(errno)); | 226 Log::PrintErr("Error Listen: %s\n", strerror(errno)); |
227 return -1; | 227 return -1; |
228 } | 228 } |
229 | 229 |
230 FDUtils::SetNonBlocking(fd); | 230 FDUtils::SetNonBlocking(fd); |
(...skipping 24 matching lines...) Expand all Loading... |
255 void Socket::Close(intptr_t fd) { | 255 void Socket::Close(intptr_t fd) { |
256 ASSERT(fd >= 0); | 256 ASSERT(fd >= 0); |
257 int err = TEMP_FAILURE_RETRY(close(fd)); | 257 int err = TEMP_FAILURE_RETRY(close(fd)); |
258 if (err != 0) { | 258 if (err != 0) { |
259 const int kBufferSize = 1024; | 259 const int kBufferSize = 1024; |
260 char error_message[kBufferSize]; | 260 char error_message[kBufferSize]; |
261 strerror_r(errno, error_message, kBufferSize); | 261 strerror_r(errno, error_message, kBufferSize); |
262 Log::PrintErr("%s\n", error_message); | 262 Log::PrintErr("%s\n", error_message); |
263 } | 263 } |
264 } | 264 } |
OLD | NEW |