| Index: runtime/bin/socket_macos.cc
|
| diff --git a/runtime/bin/socket_macos.cc b/runtime/bin/socket_macos.cc
|
| index c75cc454b76fb1a10625cc0f1c59987b3ed6ac6e..0e4acd0f85076fc025370dc94d477167233c9dd6 100644
|
| --- a/runtime/bin/socket_macos.cc
|
| +++ b/runtime/bin/socket_macos.cc
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| @@ -26,7 +26,7 @@ intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
|
| struct hostent* server;
|
| struct sockaddr_in server_address;
|
|
|
| - fd = socket(AF_INET, SOCK_STREAM, 0);
|
| + fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
|
| if (fd < 0) {
|
| fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno));
|
| return -1;
|
| @@ -36,7 +36,7 @@ intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
|
|
|
| server = gethostbyname(host);
|
| if (server == NULL) {
|
| - close(fd);
|
| + TEMP_FAILURE_RETRY(close(fd));
|
| fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno));
|
| return -1;
|
| }
|
| @@ -45,9 +45,10 @@ intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
|
| server_address.sin_port = htons(port);
|
| bcopy(server->h_addr, &server_address.sin_addr.s_addr, server->h_length);
|
| memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
|
| - intptr_t result = connect(fd,
|
| - reinterpret_cast<struct sockaddr *>(&server_address),
|
| - sizeof(server_address));
|
| + intptr_t result = TEMP_FAILURE_RETRY(
|
| + connect(fd,
|
| + reinterpret_cast<struct sockaddr *>(&server_address),
|
| + sizeof(server_address)));
|
| if (result == 0 || errno == EINPROGRESS) {
|
| return fd;
|
| }
|
| @@ -62,11 +63,11 @@ intptr_t Socket::Available(intptr_t fd) {
|
|
|
| int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
|
| ASSERT(fd >= 0);
|
| - ssize_t read_bytes = read(fd, buffer, num_bytes);
|
| - if (read_bytes == -1 &&
|
| - (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) {
|
| - // If the read was interrupted or the read would block we need
|
| - // to retry and therefore return 0 as the number of bytes written.
|
| + ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
|
| + ASSERT(EAGAIN == EWOULDBLOCK);
|
| + if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
| + // If the read would block we need to retry and therefore return 0
|
| + // as the number of bytes written.
|
| read_bytes = 0;
|
| }
|
| return read_bytes;
|
| @@ -75,11 +76,11 @@ int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
|
|
|
| int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
|
| ASSERT(fd >= 0);
|
| - ssize_t written_bytes = write(fd, buffer, num_bytes);
|
| - if (written_bytes == -1 &&
|
| - (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) {
|
| - // If the write was interrupted or the write would block we need
|
| - // to retry and therefore return 0 as the number of bytes written.
|
| + ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
|
| + ASSERT(EAGAIN == EWOULDBLOCK);
|
| + if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
| + // If the would block we need to retry and therefore return 0 as
|
| + // the number of bytes written.
|
| written_bytes = 0;
|
| }
|
| return written_bytes;
|
| @@ -90,8 +91,10 @@ intptr_t Socket::GetPort(intptr_t fd) {
|
| ASSERT(fd >= 0);
|
| struct sockaddr_in socket_address;
|
| socklen_t size = sizeof(socket_address);
|
| - if (getsockname(fd, reinterpret_cast<struct sockaddr *>(&socket_address),
|
| - &size)) {
|
| + if (TEMP_FAILURE_RETRY(
|
| + getsockname(fd,
|
| + reinterpret_cast<struct sockaddr *>(&socket_address),
|
| + &size))) {
|
| fprintf(stderr, "Error getsockname: %s\n", strerror(errno));
|
| return 0;
|
| }
|
| @@ -105,33 +108,36 @@ intptr_t Socket::GetStdioHandle(int num) {
|
|
|
|
|
| intptr_t ServerSocket::CreateBindListen(const char* host,
|
| - intptr_t port,
|
| - intptr_t backlog) {
|
| + intptr_t port,
|
| + intptr_t backlog) {
|
| intptr_t fd;
|
| struct sockaddr_in server_address;
|
|
|
| - fd = socket(AF_INET, SOCK_STREAM, 0);
|
| + fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
|
| if (fd < 0) {
|
| fprintf(stderr, "Error CreateBind: %s\n", strerror(errno));
|
| return -1;
|
| }
|
|
|
| int optval = 1;
|
| - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
|
| + TEMP_FAILURE_RETRY(
|
| + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
|
|
|
| server_address.sin_family = AF_INET;
|
| server_address.sin_port = htons(port);
|
| server_address.sin_addr.s_addr = inet_addr(host);
|
| memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
|
|
|
| - if (bind(fd, reinterpret_cast<struct sockaddr *>(&server_address),
|
| - sizeof(server_address)) < 0) {
|
| - close(fd);
|
| + if (TEMP_FAILURE_RETRY(
|
| + bind(fd,
|
| + reinterpret_cast<struct sockaddr *>(&server_address),
|
| + sizeof(server_address))) < 0) {
|
| + TEMP_FAILURE_RETRY(close(fd));
|
| fprintf(stderr, "Error Bind: %s\n", strerror(errno));
|
| return -1;
|
| }
|
|
|
| - if (listen(fd, backlog) != 0) {
|
| + if (TEMP_FAILURE_RETRY(listen(fd, backlog)) != 0) {
|
| fprintf(stderr, "Error Listen: %s\n", strerror(errno));
|
| return -1;
|
| }
|
| @@ -144,7 +150,7 @@ intptr_t ServerSocket::Accept(intptr_t fd) {
|
| intptr_t socket;
|
| struct sockaddr clientaddr;
|
| socklen_t addrlen = sizeof(clientaddr);
|
| - socket = accept(fd, &clientaddr, &addrlen);
|
| + socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen));
|
| if (socket < 0) {
|
| fprintf(stderr, "Error Accept: %s\n", strerror(errno));
|
| } else {
|
|
|