| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <arpa/inet.h> | 5 #include <arpa/inet.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <netdb.h> | 7 #include <netdb.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 | 57 |
| 58 intptr_t Socket::Available(intptr_t fd) { | 58 intptr_t Socket::Available(intptr_t fd) { |
| 59 return FDUtils::AvailableBytes(fd); | 59 return FDUtils::AvailableBytes(fd); |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { | 63 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 64 ASSERT(fd >= 0); | 64 ASSERT(fd >= 0); |
| 65 ssize_t read_bytes = read(fd, buffer, num_bytes); | 65 ssize_t read_bytes = read(fd, buffer, num_bytes); |
| 66 if (read_bytes == -1 && |
| 67 (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) { |
| 68 // If the read was interrupted or the read would block we need |
| 69 // to retry and therefore return 0 as the number of bytes written. |
| 70 read_bytes = 0; |
| 71 } |
| 66 return read_bytes; | 72 return read_bytes; |
| 67 } | 73 } |
| 68 | 74 |
| 69 | 75 |
| 70 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 76 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
| 71 ASSERT(fd >= 0); | 77 ASSERT(fd >= 0); |
| 72 ssize_t written_bytes = write(fd, buffer, num_bytes); | 78 ssize_t written_bytes = write(fd, buffer, num_bytes); |
| 79 if (written_bytes == -1 && |
| 80 (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) { |
| 81 // If the write was interrupted or the write would block we need |
| 82 // to retry and therefore return 0 as the number of bytes written. |
| 83 written_bytes = 0; |
| 84 } |
| 73 return written_bytes; | 85 return written_bytes; |
| 74 } | 86 } |
| 75 | 87 |
| 76 | 88 |
| 77 intptr_t Socket::GetPort(intptr_t fd) { | 89 intptr_t Socket::GetPort(intptr_t fd) { |
| 78 ASSERT(fd >= 0); | 90 ASSERT(fd >= 0); |
| 79 struct sockaddr_in socket_address; | 91 struct sockaddr_in socket_address; |
| 80 socklen_t size = sizeof(socket_address); | 92 socklen_t size = sizeof(socket_address); |
| 81 if (getsockname(fd, reinterpret_cast<struct sockaddr *>(&socket_address), | 93 if (getsockname(fd, reinterpret_cast<struct sockaddr *>(&socket_address), |
| 82 &size)) { | 94 &size)) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 struct sockaddr clientaddr; | 145 struct sockaddr clientaddr; |
| 134 socklen_t addrlen = sizeof(clientaddr); | 146 socklen_t addrlen = sizeof(clientaddr); |
| 135 socket = accept(fd, &clientaddr, &addrlen); | 147 socket = accept(fd, &clientaddr, &addrlen); |
| 136 if (socket < 0) { | 148 if (socket < 0) { |
| 137 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); | 149 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); |
| 138 } else { | 150 } else { |
| 139 FDUtils::SetNonBlocking(socket); | 151 FDUtils::SetNonBlocking(socket); |
| 140 } | 152 } |
| 141 return socket; | 153 return socket; |
| 142 } | 154 } |
| OLD | NEW |