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

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

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 months 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.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) 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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 intptr_t backlog) { 197 intptr_t backlog) {
198 intptr_t fd; 198 intptr_t fd;
199 struct sockaddr_in server_address; 199 struct sockaddr_in server_address;
200 200
201 in_addr_t s_addr = inet_addr(host); 201 in_addr_t s_addr = inet_addr(host);
202 if (s_addr == INADDR_NONE) { 202 if (s_addr == INADDR_NONE) {
203 return -5; 203 return -5;
204 } 204 }
205 205
206 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0)); 206 fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
207 if (fd < 0) { 207 if (fd < 0) return -1;
208 Log::PrintErr("Error CreateBind: %s\n", strerror(errno));
209 return -1;
210 }
211 208
212 FDUtils::SetCloseOnExec(fd); 209 FDUtils::SetCloseOnExec(fd);
213 210
214 int optval = 1; 211 int optval = 1;
215 TEMP_FAILURE_RETRY( 212 TEMP_FAILURE_RETRY(
216 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); 213 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
217 214
218 server_address.sin_family = AF_INET; 215 server_address.sin_family = AF_INET;
219 server_address.sin_port = htons(port); 216 server_address.sin_port = htons(port);
220 server_address.sin_addr.s_addr = s_addr; 217 server_address.sin_addr.s_addr = s_addr;
221 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero)); 218 memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
222 219
223 if (TEMP_FAILURE_RETRY( 220 if (TEMP_FAILURE_RETRY(
224 bind(fd, 221 bind(fd,
225 reinterpret_cast<struct sockaddr *>(&server_address), 222 reinterpret_cast<struct sockaddr *>(&server_address),
226 sizeof(server_address))) < 0) { 223 sizeof(server_address))) < 0) {
227 TEMP_FAILURE_RETRY(close(fd)); 224 TEMP_FAILURE_RETRY(close(fd));
228 Log::PrintErr("Error Bind: %s\n", strerror(errno));
229 return -1; 225 return -1;
230 } 226 }
231 227
232 if (TEMP_FAILURE_RETRY(listen(fd, backlog)) != 0) { 228 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
233 Log::PrintErr("Error Listen: %s\n", strerror(errno)); 229 TEMP_FAILURE_RETRY(close(fd));
234 return -1; 230 return -1;
235 } 231 }
236 232
237 FDUtils::SetNonBlocking(fd); 233 FDUtils::SetNonBlocking(fd);
238 return fd; 234 return fd;
239 } 235 }
240 236
241 237
242 static bool IsTemporaryAcceptError(int error) { 238 static bool IsTemporaryAcceptError(int error) {
243 // On Linux a number of protocol errors should be treated as EAGAIN. 239 // On Linux a number of protocol errors should be treated as EAGAIN.
(...skipping 30 matching lines...) Expand all
274 int err = TEMP_FAILURE_RETRY(close(fd)); 270 int err = TEMP_FAILURE_RETRY(close(fd));
275 if (err != 0) { 271 if (err != 0) {
276 const int kBufferSize = 1024; 272 const int kBufferSize = 1024;
277 char error_message[kBufferSize]; 273 char error_message[kBufferSize];
278 strerror_r(errno, error_message, kBufferSize); 274 strerror_r(errno, error_message, kBufferSize);
279 Log::PrintErr("%s\n", error_message); 275 Log::PrintErr("%s\n", error_message);
280 } 276 }
281 } 277 }
282 278
283 #endif // defined(TARGET_OS_LINUX) 279 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/socket.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698