OLD | NEW |
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 <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 <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 intptr_t fd; | 22 intptr_t fd; |
23 struct hostent* server; | 23 struct hostent* server; |
24 struct sockaddr_in server_address; | 24 struct sockaddr_in server_address; |
25 | 25 |
26 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); | 26 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); |
27 if (fd < 0) { | 27 if (fd < 0) { |
28 fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno)); | 28 fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno)); |
29 return -1; | 29 return -1; |
30 } | 30 } |
31 | 31 |
| 32 FDUtils::SetCloseOnExec(fd); |
32 FDUtils::SetNonBlocking(fd); | 33 FDUtils::SetNonBlocking(fd); |
33 | 34 |
34 server = gethostbyname(host); | 35 server = gethostbyname(host); |
35 if (server == NULL) { | 36 if (server == NULL) { |
36 TEMP_FAILURE_RETRY(close(fd)); | 37 TEMP_FAILURE_RETRY(close(fd)); |
37 fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno)); | 38 fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno)); |
38 return -1; | 39 return -1; |
39 } | 40 } |
40 | 41 |
41 server_address.sin_family = AF_INET; | 42 server_address.sin_family = AF_INET; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (s_addr == INADDR_NONE) { | 181 if (s_addr == INADDR_NONE) { |
181 return -5; | 182 return -5; |
182 } | 183 } |
183 | 184 |
184 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); | 185 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); |
185 if (fd < 0) { | 186 if (fd < 0) { |
186 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); | 187 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); |
187 return -1; | 188 return -1; |
188 } | 189 } |
189 | 190 |
| 191 FDUtils::SetCloseOnExec(fd); |
| 192 |
190 int optval = 1; | 193 int optval = 1; |
191 TEMP_FAILURE_RETRY( | 194 TEMP_FAILURE_RETRY( |
192 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); | 195 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); |
193 | 196 |
194 server_address.sin_family = AF_INET; | 197 server_address.sin_family = AF_INET; |
195 server_address.sin_port = htons(port); | 198 server_address.sin_port = htons(port); |
196 server_address.sin_addr.s_addr = s_addr; | 199 server_address.sin_addr.s_addr = s_addr; |
197 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); | 200 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); |
198 | 201 |
199 if (TEMP_FAILURE_RETRY( | 202 if (TEMP_FAILURE_RETRY( |
(...skipping 26 matching lines...) Expand all Loading... |
226 // error. We got woken up from the poll on the listening socket, | 229 // error. We got woken up from the poll on the listening socket, |
227 // but there is no connection ready to be accepted. | 230 // but there is no connection ready to be accepted. |
228 ASSERT(kTemporaryFailure != -1); | 231 ASSERT(kTemporaryFailure != -1); |
229 socket = kTemporaryFailure; | 232 socket = kTemporaryFailure; |
230 } | 233 } |
231 } else { | 234 } else { |
232 FDUtils::SetNonBlocking(socket); | 235 FDUtils::SetNonBlocking(socket); |
233 } | 236 } |
234 return socket; | 237 return socket; |
235 } | 238 } |
OLD | NEW |