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

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

Issue 11564017: 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
« no previous file with comments | « runtime/bin/process_win.cc ('k') | runtime/platform/globals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DWORD len = INET_ADDRSTRLEN; 69 DWORD len = INET_ADDRSTRLEN;
70 int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(&socket_address), 70 int err = WSAAddressToStringA(reinterpret_cast<LPSOCKADDR>(&socket_address),
71 sizeof(socket_address), 71 sizeof(socket_address),
72 NULL, 72 NULL,
73 host, 73 host,
74 &len); 74 &len);
75 if (err != 0) { 75 if (err != 0) {
76 Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError()); 76 Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError());
77 return false; 77 return false;
78 } 78 }
79 return true; 79 return true;
80 } 80 }
81 81
82 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { 82 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
83 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); 83 SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
84 if (s == INVALID_SOCKET) { 84 if (s == INVALID_SOCKET) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 *os_error = new OSError(); 189 *os_error = new OSError();
190 return NULL; 190 return NULL;
191 } 191 }
192 // Convert the address into IPv4 dotted decimal notation. 192 // Convert the address into IPv4 dotted decimal notation.
193 char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN)); 193 char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN));
194 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr); 194 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr);
195 195
196 // Clear the port before calling WSAAddressToString as WSAAddressToString 196 // Clear the port before calling WSAAddressToString as WSAAddressToString
197 // includes the port in the formatted string. 197 // includes the port in the formatted string.
198 DWORD len = INET_ADDRSTRLEN; 198 DWORD len = INET_ADDRSTRLEN;
199 int err = WSAAddressToString(reinterpret_cast<LPSOCKADDR>(sockaddr), 199 int err = WSAAddressToStringA(reinterpret_cast<LPSOCKADDR>(sockaddr),
200 sizeof(sockaddr_in), 200 sizeof(sockaddr_in),
201 NULL, 201 NULL,
202 buffer, 202 buffer,
203 &len); 203 &len);
204 if (err != 0) { 204 if (err != 0) {
205 free(buffer); 205 free(buffer);
206 return NULL; 206 return NULL;
207 } 207 }
208 return buffer; 208 return buffer;
209 } 209 }
210 210
211 211
212 intptr_t ServerSocket::CreateBindListen(const char* host, 212 intptr_t ServerSocket::CreateBindListen(const char* host,
213 intptr_t port, 213 intptr_t port,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (status == SOCKET_ERROR) { 254 if (status == SOCKET_ERROR) {
255 DWORD rc = WSAGetLastError(); 255 DWORD rc = WSAGetLastError();
256 closesocket(s); 256 closesocket(s);
257 SetLastError(rc); 257 SetLastError(rc);
258 return -1; 258 return -1;
259 } 259 }
260 260
261 ListenSocket* listen_socket = new ListenSocket(s); 261 ListenSocket* listen_socket = new ListenSocket(s);
262 return reinterpret_cast<intptr_t>(listen_socket); 262 return reinterpret_cast<intptr_t>(listen_socket);
263 } 263 }
OLDNEW
« no previous file with comments | « runtime/bin/process_win.cc ('k') | runtime/platform/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698