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

Side by Side Diff: runtime/bin/socket_linux.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/socket_android.cc ('k') | runtime/bin/socket_macos.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 static const size_t kTempBufSize = 1024; 35 static const size_t kTempBufSize = 1024;
35 char temp_buf[kTempBufSize]; 36 char temp_buf[kTempBufSize];
36 struct hostent *unused; 37 struct hostent *unused;
37 int err; 38 int err;
38 if (gethostbyname_r( 39 if (gethostbyname_r(
39 host, &server, temp_buf, kTempBufSize, &unused, &err) != 0) { 40 host, &server, temp_buf, kTempBufSize, &unused, &err) != 0) {
40 TEMP_FAILURE_RETRY(close(fd)); 41 TEMP_FAILURE_RETRY(close(fd));
41 fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno)); 42 fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (s_addr == INADDR_NONE) { 185 if (s_addr == INADDR_NONE) {
185 return -5; 186 return -5;
186 } 187 }
187 188
188 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); 189 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
189 if (fd < 0) { 190 if (fd < 0) {
190 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); 191 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno));
191 return -1; 192 return -1;
192 } 193 }
193 194
195 FDUtils::SetCloseOnExec(fd);
196
194 int optval = 1; 197 int optval = 1;
195 TEMP_FAILURE_RETRY( 198 TEMP_FAILURE_RETRY(
196 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); 199 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
197 200
198 server_address.sin_family = AF_INET; 201 server_address.sin_family = AF_INET;
199 server_address.sin_port = htons(port); 202 server_address.sin_port = htons(port);
200 server_address.sin_addr.s_addr = s_addr; 203 server_address.sin_addr.s_addr = s_addr;
201 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); 204 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
202 205
203 if (TEMP_FAILURE_RETRY( 206 if (TEMP_FAILURE_RETRY(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // error. We got woken up from the poll on the listening socket, 243 // error. We got woken up from the poll on the listening socket,
241 // but there is no connection ready to be accepted. 244 // but there is no connection ready to be accepted.
242 ASSERT(kTemporaryFailure != -1); 245 ASSERT(kTemporaryFailure != -1);
243 socket = kTemporaryFailure; 246 socket = kTemporaryFailure;
244 } 247 }
245 } else { 248 } else {
246 FDUtils::SetNonBlocking(socket); 249 FDUtils::SetNonBlocking(socket);
247 } 250 }
248 return socket; 251 return socket;
249 } 252 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698