| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 return -1; | 54 return -1; |
| 55 } | 55 } |
| 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 intptr_t Socket::Read(intptr_t fd, | 63 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { |
| 64 void* buffer, | |
| 65 intptr_t num_bytes) { | |
| 66 ASSERT(fd >= 0); | 64 ASSERT(fd >= 0); |
| 67 intptr_t read_bytes = read(fd, buffer, num_bytes); | 65 ssize_t read_bytes = read(fd, buffer, num_bytes); |
| 68 return read_bytes; | 66 return read_bytes; |
| 69 } | 67 } |
| 70 | 68 |
| 71 | 69 |
| 72 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 70 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
| 73 ASSERT(fd >= 0); | 71 ASSERT(fd >= 0); |
| 74 return write(fd, buffer, num_bytes); | 72 ssize_t written_bytes = write(fd, buffer, num_bytes); |
| 73 return written_bytes; |
| 75 } | 74 } |
| 76 | 75 |
| 77 | 76 |
| 78 intptr_t Socket::GetPort(intptr_t fd) { | 77 intptr_t Socket::GetPort(intptr_t fd) { |
| 79 ASSERT(fd >= 0); | 78 ASSERT(fd >= 0); |
| 80 struct sockaddr_in socket_address; | 79 struct sockaddr_in socket_address; |
| 81 socklen_t size = sizeof(socket_address); | 80 socklen_t size = sizeof(socket_address); |
| 82 if (getsockname(fd, reinterpret_cast<struct sockaddr *>(&socket_address), | 81 if (getsockname(fd, reinterpret_cast<struct sockaddr *>(&socket_address), |
| 83 &size)) { | 82 &size)) { |
| 84 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); | 83 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 struct sockaddr clientaddr; | 133 struct sockaddr clientaddr; |
| 135 socklen_t addrlen = sizeof(clientaddr); | 134 socklen_t addrlen = sizeof(clientaddr); |
| 136 socket = accept(fd, &clientaddr, &addrlen); | 135 socket = accept(fd, &clientaddr, &addrlen); |
| 137 if (socket < 0) { | 136 if (socket < 0) { |
| 138 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); | 137 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); |
| 139 } else { | 138 } else { |
| 140 FDUtils::SetNonBlocking(socket); | 139 FDUtils::SetNonBlocking(socket); |
| 141 } | 140 } |
| 142 return socket; | 141 return socket; |
| 143 } | 142 } |
| OLD | NEW |