| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "bin/eventhandler.h" | 6 #include "bin/eventhandler.h" |
| 7 #include "bin/socket.h" | 7 #include "bin/socket.h" |
| 8 | 8 |
| 9 bool Socket::Initialize() { | 9 bool Socket::Initialize() { |
| 10 int err; | 10 int err; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (status != 0) { | 184 if (status != 0) { |
| 185 ASSERT(*os_error == NULL); | 185 ASSERT(*os_error == NULL); |
| 186 *os_error = new OSError(status, | 186 *os_error = new OSError(status, |
| 187 gai_strerror(status), | 187 gai_strerror(status), |
| 188 OSError::kGetAddressInfo); | 188 OSError::kGetAddressInfo); |
| 189 return NULL; | 189 return NULL; |
| 190 } | 190 } |
| 191 // Convert the address into IPv4 dotted decimal notation. | 191 // Convert the address into IPv4 dotted decimal notation. |
| 192 char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN)); | 192 char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN)); |
| 193 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr); | 193 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr); |
| 194 const char* result = inet_ntop(AF_INET, | 194 |
| 195 reinterpret_cast<void *>(&sockaddr->sin_addr), | 195 // Clear the port before calling WSAAddressToString as WSAAddressToString |
| 196 buffer, | 196 // includes the port in the formatted string. |
| 197 INET_ADDRSTRLEN); | 197 DWORD len = INET_ADDRSTRLEN; |
| 198 if (result == NULL) { | 198 int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(sockaddr), |
| 199 sizeof(sockaddr_in), |
| 200 NULL, |
| 201 buffer, |
| 202 &len); |
| 203 if (err != 0) { |
| 199 free(buffer); | 204 free(buffer); |
| 200 return NULL; | 205 return NULL; |
| 201 } | 206 } |
| 202 ASSERT(result == buffer); | |
| 203 return buffer; | 207 return buffer; |
| 204 } | 208 } |
| 205 | 209 |
| 206 | 210 |
| 207 intptr_t ServerSocket::CreateBindListen(const char* host, | 211 intptr_t ServerSocket::CreateBindListen(const char* host, |
| 208 intptr_t port, | 212 intptr_t port, |
| 209 intptr_t backlog) { | 213 intptr_t backlog) { |
| 210 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 214 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 211 if (s == INVALID_SOCKET) { | 215 if (s == INVALID_SOCKET) { |
| 212 return -1; | 216 return -1; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (status == SOCKET_ERROR) { | 248 if (status == SOCKET_ERROR) { |
| 245 DWORD rc = WSAGetLastError(); | 249 DWORD rc = WSAGetLastError(); |
| 246 closesocket(s); | 250 closesocket(s); |
| 247 SetLastError(rc); | 251 SetLastError(rc); |
| 248 return -1; | 252 return -1; |
| 249 } | 253 } |
| 250 | 254 |
| 251 ListenSocket* listen_socket = new ListenSocket(s); | 255 ListenSocket* listen_socket = new ListenSocket(s); |
| 252 return reinterpret_cast<intptr_t>(listen_socket); | 256 return reinterpret_cast<intptr_t>(listen_socket); |
| 253 } | 257 } |
| OLD | NEW |