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

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

Issue 9699017: Start better error reporting for sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added tests 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
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(fd); 137 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(fd);
138 ClientSocket* client_socket = listen_socket->Accept(); 138 ClientSocket* client_socket = listen_socket->Accept();
139 if (client_socket != NULL) { 139 if (client_socket != NULL) {
140 return reinterpret_cast<intptr_t>(client_socket); 140 return reinterpret_cast<intptr_t>(client_socket);
141 } else { 141 } else {
142 return -1; 142 return -1;
143 } 143 }
144 } 144 }
145 145
146 146
147 const char* Socket::LookupIPv4Address(char* host, OSError** os_error) {
148 // Perform a name lookup for an IPv4 address.
149 struct addrinfo hints;
150 memset(&hints, 0, sizeof(hints));
151 hints.ai_family = AF_INET;
152 hints.ai_socktype = SOCK_STREAM;
153 hints.ai_protocol = IPPROTO_TCP;
154 struct addrinfo* info = NULL;
155 int status = getaddrinfo(host, 0, &hints, &info);
156 if (status != 0) {
157 ASSERT(*os_error == NULL);
158 *os_error = new OSError(status,
159 gai_strerror(status),
160 OSError::kGetAddressInfo);
161 (*os_error)->set_code(status);
162 (*os_error)->SetMessage(gai_strerror(status));
163 return NULL;
164 }
165 // Convert the address into IPv4 dotted decomal notation.
Mads Ager (google) 2012/03/14 12:51:51 Ditto.
Søren Gjesse 2012/03/19 10:05:43 Done.
166 char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN));
167 sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr);
168 const char* result = inet_ntop(AF_INET,
169 reinterpret_cast<void *>(&sockaddr->sin_addr),
170 buffer,
171 INET_ADDRSTRLEN);
172 if (result == NULL) {
173 free(buffer);
174 return NULL;
175 }
176 ASSERT(result == buffer);
177 return buffer;
178 }
179
180
147 intptr_t ServerSocket::CreateBindListen(const char* host, 181 intptr_t ServerSocket::CreateBindListen(const char* host,
148 intptr_t port, 182 intptr_t port,
149 intptr_t backlog) { 183 intptr_t backlog) {
150 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 184 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
151 if (s == INVALID_SOCKET) { 185 if (s == INVALID_SOCKET) {
152 fprintf(stderr, "Error CreateBindListen: %d\n", WSAGetLastError()); 186 fprintf(stderr, "Error CreateBindListen: %d\n", WSAGetLastError());
153 return -1; 187 return -1;
154 } 188 }
155 189
156 BOOL optval = true; 190 BOOL optval = true;
(...skipping 25 matching lines...) Expand all
182 status = listen(s, backlog); 216 status = listen(s, backlog);
183 if (status == SOCKET_ERROR) { 217 if (status == SOCKET_ERROR) {
184 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError()); 218 fprintf(stderr, "Error socket listen: %d\n", WSAGetLastError());
185 closesocket(s); 219 closesocket(s);
186 return -1; 220 return -1;
187 } 221 }
188 222
189 ListenSocket* listen_socket = new ListenSocket(s); 223 ListenSocket* listen_socket = new ListenSocket(s);
190 return reinterpret_cast<intptr_t>(listen_socket); 224 return reinterpret_cast<intptr_t>(listen_socket);
191 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698