Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Side by Side Diff: runtime/bin/socket_win.cc

Issue 11567010: Complete the transition to unicode APIs on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/log.h" 7 #include "bin/log.h"
8 #include "bin/socket.h" 8 #include "bin/socket.h"
9 9
10 bool Socket::Initialize() { 10 bool Socket::Initialize() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (getpeername(socket_handle->socket(), 59 if (getpeername(socket_handle->socket(),
60 reinterpret_cast<struct sockaddr *>(&socket_address), 60 reinterpret_cast<struct sockaddr *>(&socket_address),
61 &size)) { 61 &size)) {
62 Log::PrintErr("Error getpeername: %s\n", strerror(errno)); 62 Log::PrintErr("Error getpeername: %s\n", strerror(errno));
63 return false; 63 return false;
64 } 64 }
65 *port = ntohs(socket_address.sin_port); 65 *port = ntohs(socket_address.sin_port);
66 // Clear the port before calling WSAAddressToString as WSAAddressToString 66 // Clear the port before calling WSAAddressToString as WSAAddressToString
67 // includes the port in the formatted string. 67 // includes the port in the formatted string.
68 socket_address.sin_port = 0; 68 socket_address.sin_port = 0;
69 wchar_t* unicode_host = StringUtils::Utf8ToWide(host);
69 DWORD len = INET_ADDRSTRLEN; 70 DWORD len = INET_ADDRSTRLEN;
70 int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(&socket_address), 71 int err = WSAAddressToStringW(reinterpret_cast<LPSOCKADDR>(&socket_address),
71 sizeof(socket_address), 72 sizeof(socket_address),
72 NULL, 73 NULL,
73 host, 74 unicode_host,
74 &len); 75 &len);
76 free(unicode_host);
75 if (err != 0) { 77 if (err != 0) {
76 Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError()); 78 Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError());
77 return false; 79 return false;
78 } 80 }
79 return true; 81 return true;
80 } 82 }
81 83
82 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { 84 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
83 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); 85 SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
84 if (s == INVALID_SOCKET) { 86 if (s == INVALID_SOCKET) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 SetLastError(error_code); 190 SetLastError(error_code);
189 *os_error = new OSError(); 191 *os_error = new OSError();
190 return NULL; 192 return NULL;
191 } 193 }
192 // Convert the address into IPv4 dotted decimal notation. 194 // Convert the address into IPv4 dotted decimal notation.
193 char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN)); 195 char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN));
194 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr); 196 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr);
195 197
196 // Clear the port before calling WSAAddressToString as WSAAddressToString 198 // Clear the port before calling WSAAddressToString as WSAAddressToString
197 // includes the port in the formatted string. 199 // includes the port in the formatted string.
200 wchar_t* unicode_buffer = StringUtils::Utf8ToWide(buffer);
198 DWORD len = INET_ADDRSTRLEN; 201 DWORD len = INET_ADDRSTRLEN;
199 int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(sockaddr), 202 int err = WSAAddressToStringW(reinterpret_cast<LPSOCKADDR>(sockaddr),
200 sizeof(sockaddr_in), 203 sizeof(sockaddr_in),
201 NULL, 204 NULL,
202 buffer, 205 unicode_buffer,
203 &len); 206 &len);
207 free(unicode_buffer);
204 if (err != 0) { 208 if (err != 0) {
205 free(buffer); 209 free(buffer);
206 return NULL; 210 return NULL;
207 } 211 }
208 return buffer; 212 return buffer;
209 } 213 }
210 214
211 215
212 intptr_t ServerSocket::CreateBindListen(const char* host, 216 intptr_t ServerSocket::CreateBindListen(const char* host,
213 intptr_t port, 217 intptr_t port,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (status == SOCKET_ERROR) { 258 if (status == SOCKET_ERROR) {
255 DWORD rc = WSAGetLastError(); 259 DWORD rc = WSAGetLastError();
256 closesocket(s); 260 closesocket(s);
257 SetLastError(rc); 261 SetLastError(rc);
258 return -1; 262 return -1;
259 } 263 }
260 264
261 ListenSocket* listen_socket = new ListenSocket(s); 265 ListenSocket* listen_socket = new ListenSocket(s);
262 return reinterpret_cast<intptr_t>(listen_socket); 266 return reinterpret_cast<intptr_t>(listen_socket);
263 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698