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

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

Issue 11416006: Added FD_CLOEXEC flag to client/server socket file descriptors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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/fdutils_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 <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
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (s_addr == INADDR_NONE) { 182 if (s_addr == INADDR_NONE) {
182 return -5; 183 return -5;
183 } 184 }
184 185
185 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); 186 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
186 if (fd < 0) { 187 if (fd < 0) {
187 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); 188 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno));
188 return -1; 189 return -1;
189 } 190 }
190 191
192 FDUtils::SetCloseOnExec(fd);
193
191 int optval = 1; 194 int optval = 1;
192 TEMP_FAILURE_RETRY( 195 TEMP_FAILURE_RETRY(
193 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); 196 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
194 197
195 server_address.sin_family = AF_INET; 198 server_address.sin_family = AF_INET;
196 server_address.sin_port = htons(port); 199 server_address.sin_port = htons(port);
197 server_address.sin_addr.s_addr = s_addr; 200 server_address.sin_addr.s_addr = s_addr;
198 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); 201 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
199 202
200 if (TEMP_FAILURE_RETRY( 203 if (TEMP_FAILURE_RETRY(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // error. We got woken up from the poll on the listening socket, 240 // error. We got woken up from the poll on the listening socket,
238 // but there is no connection ready to be accepted. 241 // but there is no connection ready to be accepted.
239 ASSERT(kTemporaryFailure != -1); 242 ASSERT(kTemporaryFailure != -1);
240 socket = kTemporaryFailure; 243 socket = kTemporaryFailure;
241 } 244 }
242 } else { 245 } else {
243 FDUtils::SetNonBlocking(socket); 246 FDUtils::SetNonBlocking(socket);
244 } 247 }
245 return socket; 248 return socket;
246 } 249 }
OLDNEW
« no previous file with comments | « runtime/bin/fdutils_macos.cc ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698