| 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 intptr_t Socket::Read(intptr_t fd, | 63 intptr_t Socket::Read(intptr_t fd, |
| 64 void* buffer, | 64 void* buffer, |
| 65 intptr_t num_bytes) { | 65 intptr_t num_bytes) { |
| 66 assert(fd >= 0); | 66 ASSERT(fd >= 0); |
| 67 intptr_t read_bytes = read(fd, buffer, num_bytes); | 67 intptr_t read_bytes = read(fd, buffer, num_bytes); |
| 68 return read_bytes; | 68 return read_bytes; |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { | 72 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { |
| 73 assert(fd >= 0); | 73 ASSERT(fd >= 0); |
| 74 return write(fd, buffer, num_bytes); | 74 return write(fd, buffer, num_bytes); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 intptr_t Socket::GetPort(intptr_t fd) { | 78 intptr_t Socket::GetPort(intptr_t fd) { |
| 79 assert(fd >= 0); | 79 ASSERT(fd >= 0); |
| 80 struct sockaddr_in socket_address; | 80 struct sockaddr_in socket_address; |
| 81 socklen_t size = sizeof(socket_address); | 81 socklen_t size = sizeof(socket_address); |
| 82 if (getsockname(fd, reinterpret_cast<struct sockaddr *>(&socket_address), | 82 if (getsockname(fd, reinterpret_cast<struct sockaddr *>(&socket_address), |
| 83 &size)) { | 83 &size)) { |
| 84 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); | 84 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); |
| 85 return 0; | 85 return 0; |
| 86 } | 86 } |
| 87 return ntohs(socket_address.sin_port); | 87 return ntohs(socket_address.sin_port); |
| 88 } | 88 } |
| 89 | 89 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 struct sockaddr clientaddr; | 129 struct sockaddr clientaddr; |
| 130 socklen_t addrlen = sizeof(clientaddr); | 130 socklen_t addrlen = sizeof(clientaddr); |
| 131 socket = accept(fd, &clientaddr, &addrlen); | 131 socket = accept(fd, &clientaddr, &addrlen); |
| 132 if (socket < 0) { | 132 if (socket < 0) { |
| 133 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); | 133 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); |
| 134 } else { | 134 } else { |
| 135 FDUtils::SetNonBlocking(socket); | 135 FDUtils::SetNonBlocking(socket); |
| 136 } | 136 } |
| 137 return socket; | 137 return socket; |
| 138 } | 138 } |
| OLD | NEW |