| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 90 | 90 |
| 91 intptr_t Socket::GetStdioHandle(int num) { |
| 92 return static_cast<intptr_t>(num); |
| 93 } |
| 94 |
| 95 |
| 91 intptr_t ServerSocket::CreateBindListen(const char* host, | 96 intptr_t ServerSocket::CreateBindListen(const char* host, |
| 92 intptr_t port, | 97 intptr_t port, |
| 93 intptr_t backlog) { | 98 intptr_t backlog) { |
| 94 intptr_t fd; | 99 intptr_t fd; |
| 95 struct sockaddr_in server_address; | 100 struct sockaddr_in server_address; |
| 96 | 101 |
| 97 fd = socket(AF_INET, SOCK_STREAM, 0); | 102 fd = socket(AF_INET, SOCK_STREAM, 0); |
| 98 if (fd < 0) { | 103 if (fd < 0) { |
| 99 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); | 104 fprintf(stderr, "Error CreateBind: %s\n", strerror(errno)); |
| 100 return -1; | 105 return -1; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 129 struct sockaddr clientaddr; | 134 struct sockaddr clientaddr; |
| 130 socklen_t addrlen = sizeof(clientaddr); | 135 socklen_t addrlen = sizeof(clientaddr); |
| 131 socket = accept(fd, &clientaddr, &addrlen); | 136 socket = accept(fd, &clientaddr, &addrlen); |
| 132 if (socket < 0) { | 137 if (socket < 0) { |
| 133 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); | 138 fprintf(stderr, "Error Accept: %s\n", strerror(errno)); |
| 134 } else { | 139 } else { |
| 135 FDUtils::SetNonBlocking(socket); | 140 FDUtils::SetNonBlocking(socket); |
| 136 } | 141 } |
| 137 return socket; | 142 return socket; |
| 138 } | 143 } |
| OLD | NEW |