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

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

Issue 9624005: Fix hostname lookup on Windows (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes Created 8 years, 9 months 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 | « no previous file | tests/standalone/src/io/HttpClientTest.dart » ('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 <winsock2.h> 5 #include <winsock2.h>
6 #include <ws2tcpip.h> 6 #include <ws2tcpip.h>
7 #include <mswsock.h> 7 #include <mswsock.h>
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/eventhandler.h" 10 #include "bin/eventhandler.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 l.l_linger = 10; 66 l.l_linger = 10;
67 int status = setsockopt(s, 67 int status = setsockopt(s,
68 SOL_SOCKET, 68 SOL_SOCKET,
69 SO_LINGER, 69 SO_LINGER,
70 reinterpret_cast<char*>(&l), 70 reinterpret_cast<char*>(&l),
71 sizeof(l)); 71 sizeof(l));
72 if (status != NO_ERROR) { 72 if (status != NO_ERROR) {
73 FATAL("Failed setting SO_LINGER on socket"); 73 FATAL("Failed setting SO_LINGER on socket");
74 } 74 }
75 75
76 struct hostent* server = gethostbyname(host); 76 // Perform a name lookup for an IPv4 address.
77 if (server == NULL) { 77 struct addrinfo hints;
78 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError()); 78 memset(&hints, 0, sizeof(hints));
79 closesocket(s); 79 hints.ai_family = AF_INET;
80 hints.ai_socktype = SOCK_STREAM;
81 hints.ai_protocol = IPPROTO_TCP;
82 struct addrinfo* result = NULL;
83 status = getaddrinfo(host, 0, &hints, &result);
84 if (status != NO_ERROR) {
85 fprintf(stderr, "getaddrinfo failed with error: %d\n", status);
80 return -1; 86 return -1;
81 } 87 }
82 88
89 // Copy IPv4 address and set the port.
83 struct sockaddr_in server_address; 90 struct sockaddr_in server_address;
84 server_address.sin_family = AF_INET; 91 memcpy(&server_address,
92 reinterpret_cast<sockaddr_in *>(result->ai_addr),
93 sizeof(server_address));
85 server_address.sin_port = htons(port); 94 server_address.sin_port = htons(port);
86 server_address.sin_addr.s_addr = inet_addr(host); 95 freeaddrinfo(result); // Free data allocated by getaddrinfo.
87 status = connect( 96 status = connect(
88 s, 97 s,
89 reinterpret_cast<struct sockaddr *>(&server_address), 98 reinterpret_cast<struct sockaddr*>(&server_address),
90 sizeof(server_address)); 99 sizeof(server_address));
91 if (status == SOCKET_ERROR) { 100 if (status == SOCKET_ERROR) {
92 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError()); 101 fprintf(stderr, "Error CreateConnect: %d\n", WSAGetLastError());
93 closesocket(s); 102 closesocket(s);
94 return -1; 103 return -1;
95 } 104 }
96 105
97 ClientSocket* client_socket = new ClientSocket(s); 106 ClientSocket* client_socket = new ClientSocket(s);
98 return reinterpret_cast<intptr_t>(client_socket); 107 return reinterpret_cast<intptr_t>(client_socket);
99 } 108 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 status = listen(s, backlog); 182 status = listen(s, backlog);
174 if (status == SOCKET_ERROR) { 183 if (status == SOCKET_ERROR) {
175 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError()); 184 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError());
176 closesocket(s); 185 closesocket(s);
177 return -1; 186 return -1;
178 } 187 }
179 188
180 ListenSocket* listen_socket = new ListenSocket(s); 189 ListenSocket* listen_socket = new ListenSocket(s);
181 return reinterpret_cast<intptr_t>(listen_socket); 190 return reinterpret_cast<intptr_t>(listen_socket);
182 } 191 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/src/io/HttpClientTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698