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

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

Issue 10917064: Throw an error if the ServerSocket host argument is invalid. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check exception. Created 8 years, 3 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 | « runtime/bin/socket_macos.cc ('k') | tests/standalone/io/socket_exception_test.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 "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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 free(buffer); 204 free(buffer);
205 return NULL; 205 return NULL;
206 } 206 }
207 return buffer; 207 return buffer;
208 } 208 }
209 209
210 210
211 intptr_t ServerSocket::CreateBindListen(const char* host, 211 intptr_t ServerSocket::CreateBindListen(const char* host,
212 intptr_t port, 212 intptr_t port,
213 intptr_t backlog) { 213 intptr_t backlog) {
214 in_addr_t s_addr = TEMP_FAILURE_RETRY(inet_addr(host));
215 if (s_addr == INADDR_NONE) {
216 return -5;
217 }
218
214 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 219 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
215 if (s == INVALID_SOCKET) { 220 if (s == INVALID_SOCKET) {
216 return -1; 221 return -1;
217 } 222 }
218 223
219 BOOL optval = true; 224 BOOL optval = true;
220 int status = setsockopt(s, 225 int status = setsockopt(s,
221 SOL_SOCKET, 226 SOL_SOCKET,
222 SO_REUSEADDR, 227 SO_REUSEADDR,
223 reinterpret_cast<const char*>(&optval), 228 reinterpret_cast<const char*>(&optval),
224 sizeof(optval)); 229 sizeof(optval));
225 if (status == SOCKET_ERROR) { 230 if (status == SOCKET_ERROR) {
226 DWORD rc = WSAGetLastError(); 231 DWORD rc = WSAGetLastError();
227 closesocket(s); 232 closesocket(s);
228 SetLastError(rc); 233 SetLastError(rc);
229 return -1; 234 return -1;
230 } 235 }
231 236
232 sockaddr_in addr; 237 sockaddr_in addr;
233 memset(&addr, 0, sizeof(addr)); 238 memset(&addr, 0, sizeof(addr));
234 addr.sin_family = AF_INET; 239 addr.sin_family = AF_INET;
235 addr.sin_addr.s_addr = inet_addr(host); 240 addr.sin_addr.s_addr = s_addr;
236 addr.sin_port = htons(port); 241 addr.sin_port = htons(port);
237 status = bind(s, 242 status = bind(s,
238 reinterpret_cast<struct sockaddr *>(&addr), 243 reinterpret_cast<struct sockaddr *>(&addr),
239 sizeof(addr)); 244 sizeof(addr));
240 if (status == SOCKET_ERROR) { 245 if (status == SOCKET_ERROR) {
241 DWORD rc = WSAGetLastError(); 246 DWORD rc = WSAGetLastError();
242 closesocket(s); 247 closesocket(s);
243 SetLastError(rc); 248 SetLastError(rc);
244 return -1; 249 return -1;
245 } 250 }
246 251
247 status = listen(s, backlog); 252 status = listen(s, backlog);
248 if (status == SOCKET_ERROR) { 253 if (status == SOCKET_ERROR) {
249 DWORD rc = WSAGetLastError(); 254 DWORD rc = WSAGetLastError();
250 closesocket(s); 255 closesocket(s);
251 SetLastError(rc); 256 SetLastError(rc);
252 return -1; 257 return -1;
253 } 258 }
254 259
255 ListenSocket* listen_socket = new ListenSocket(s); 260 ListenSocket* listen_socket = new ListenSocket(s);
256 return reinterpret_cast<intptr_t>(listen_socket); 261 return reinterpret_cast<intptr_t>(listen_socket);
257 } 262 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | tests/standalone/io/socket_exception_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698