OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/dartutils.h" |
5 #include "bin/io_buffer.h" | 6 #include "bin/io_buffer.h" |
6 #include "bin/isolate_data.h" | 7 #include "bin/isolate_data.h" |
7 #include "bin/dartutils.h" | 8 #include "bin/lockers.h" |
8 #include "bin/socket.h" | 9 #include "bin/socket.h" |
9 #include "bin/thread.h" | 10 #include "bin/thread.h" |
10 #include "bin/lockers.h" | |
11 #include "bin/utils.h" | 11 #include "bin/utils.h" |
12 | 12 |
13 #include "platform/globals.h" | 13 #include "platform/globals.h" |
14 #include "platform/utils.h" | 14 #include "platform/utils.h" |
15 | 15 |
16 #include "include/dart_api.h" | 16 #include "include/dart_api.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 namespace bin { | 19 namespace bin { |
20 | 20 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 SocketsIterator it = sockets_by_port_.find(port); | 53 SocketsIterator it = sockets_by_port_.find(port); |
54 OSSocket *first_os_socket = NULL; | 54 OSSocket *first_os_socket = NULL; |
55 if (it != sockets_by_port_.end()) { | 55 if (it != sockets_by_port_.end()) { |
56 first_os_socket = it->second; | 56 first_os_socket = it->second; |
57 } | 57 } |
58 | 58 |
59 if (first_os_socket != NULL) { | 59 if (first_os_socket != NULL) { |
60 // There is already a socket listening on this port. We need to ensure | 60 // There is already a socket listening on this port. We need to ensure |
61 // that if there is one also listening on the same address, it was created | 61 // that if there is one also listening on the same address, it was created |
62 // with `shared = true`, ... | 62 // with `shared = true`, ... |
63 | |
64 OSSocket *os_socket = it->second; | 63 OSSocket *os_socket = it->second; |
65 OSSocket *os_socket_same_addr = findOSSocketWithAddress(os_socket, addr); | 64 OSSocket *os_socket_same_addr = findOSSocketWithAddress(os_socket, addr); |
66 | 65 |
67 if (os_socket_same_addr != NULL) { | 66 if (os_socket_same_addr != NULL) { |
68 if (!os_socket_same_addr->shared || !shared) { | 67 if (!os_socket_same_addr->shared || !shared) { |
69 OSError os_error(-1, | 68 OSError os_error(-1, |
70 "The shared flag to bind() needs to be `true` if " | 69 "The shared flag to bind() needs to be `true` if " |
71 "binding multiple times on the same (address, port) " | 70 "binding multiple times on the same (address, port) " |
72 "combination.", | 71 "combination.", |
73 OSError::kUnknown); | 72 OSError::kUnknown); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 sockets_by_fd_.erase(socketfd); | 138 sockets_by_fd_.erase(socketfd); |
140 | 139 |
141 OSSocket *prev = NULL; | 140 OSSocket *prev = NULL; |
142 OSSocket *current = sockets_by_port_[os_socket->port]; | 141 OSSocket *current = sockets_by_port_[os_socket->port]; |
143 while (current != os_socket) { | 142 while (current != os_socket) { |
144 ASSERT(current != NULL); | 143 ASSERT(current != NULL); |
145 prev = current; | 144 prev = current; |
146 current = current->next; | 145 current = current->next; |
147 } | 146 } |
148 | 147 |
149 if (prev == NULL && current->next == NULL) { | 148 if ((prev == NULL) && (current->next == NULL)) { |
150 // Remove last element from the list. | 149 // Remove last element from the list. |
151 sockets_by_port_.erase(os_socket->port); | 150 sockets_by_port_.erase(os_socket->port); |
152 } else if (prev == NULL) { | 151 } else if (prev == NULL) { |
153 // Remove first element of the list. | 152 // Remove first element of the list. |
154 sockets_by_port_[os_socket->port] = current->next; | 153 sockets_by_port_[os_socket->port] = current->next; |
155 } else { | 154 } else { |
156 // Remove element from the list which is not the first one. | 155 // Remove element from the list which is not the first one. |
157 prev->next = os_socket->next; | 156 prev->next = os_socket->next; |
158 } | 157 } |
159 | 158 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 static bool short_socket_reads = Dart_IsVMFlagSet("short_socket_read"); | 263 static bool short_socket_reads = Dart_IsVMFlagSet("short_socket_read"); |
265 intptr_t socket = | 264 intptr_t socket = |
266 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 265 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
267 int64_t length = 0; | 266 int64_t length = 0; |
268 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { | 267 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { |
269 if (short_socket_reads) { | 268 if (short_socket_reads) { |
270 length = (length + 1) / 2; | 269 length = (length + 1) / 2; |
271 } | 270 } |
272 uint8_t* buffer = NULL; | 271 uint8_t* buffer = NULL; |
273 Dart_Handle result = IOBuffer::Allocate(length, &buffer); | 272 Dart_Handle result = IOBuffer::Allocate(length, &buffer); |
274 if (Dart_IsError(result)) Dart_PropagateError(result); | 273 if (Dart_IsError(result)) { |
| 274 Dart_PropagateError(result); |
| 275 } |
275 ASSERT(buffer != NULL); | 276 ASSERT(buffer != NULL); |
276 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 277 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
277 if (bytes_read == length) { | 278 if (bytes_read == length) { |
278 Dart_SetReturnValue(args, result); | 279 Dart_SetReturnValue(args, result); |
279 } else if (bytes_read > 0) { | 280 } else if (bytes_read > 0) { |
280 uint8_t* new_buffer = NULL; | 281 uint8_t* new_buffer = NULL; |
281 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); | 282 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); |
282 if (Dart_IsError(new_result)) Dart_PropagateError(new_result); | 283 if (Dart_IsError(new_result)) { |
| 284 Dart_PropagateError(new_result); |
| 285 } |
283 ASSERT(new_buffer != NULL); | 286 ASSERT(new_buffer != NULL); |
284 memmove(new_buffer, buffer, bytes_read); | 287 memmove(new_buffer, buffer, bytes_read); |
285 Dart_SetReturnValue(args, new_result); | 288 Dart_SetReturnValue(args, new_result); |
286 } else if (bytes_read == 0) { | 289 } else if (bytes_read == 0) { |
287 // On MacOS when reading from a tty Ctrl-D will result in reading one | 290 // On MacOS when reading from a tty Ctrl-D will result in reading one |
288 // less byte then reported as available. | 291 // less byte then reported as available. |
289 Dart_SetReturnValue(args, Dart_Null()); | 292 Dart_SetReturnValue(args, Dart_Null()); |
290 } else { | 293 } else { |
291 ASSERT(bytes_read == -1); | 294 ASSERT(bytes_read == -1); |
292 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 295 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
(...skipping 26 matching lines...) Expand all Loading... |
319 } | 322 } |
320 if (bytes_read < 0) { | 323 if (bytes_read < 0) { |
321 ASSERT(bytes_read == -1); | 324 ASSERT(bytes_read == -1); |
322 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 325 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
323 return; | 326 return; |
324 } | 327 } |
325 // Datagram data read. Copy into buffer of the exact size, | 328 // Datagram data read. Copy into buffer of the exact size, |
326 ASSERT(bytes_read > 0); | 329 ASSERT(bytes_read > 0); |
327 uint8_t* data_buffer = NULL; | 330 uint8_t* data_buffer = NULL; |
328 Dart_Handle data = IOBuffer::Allocate(bytes_read, &data_buffer); | 331 Dart_Handle data = IOBuffer::Allocate(bytes_read, &data_buffer); |
329 if (Dart_IsError(data)) Dart_PropagateError(data); | 332 if (Dart_IsError(data)) { |
| 333 Dart_PropagateError(data); |
| 334 } |
330 ASSERT(data_buffer != NULL); | 335 ASSERT(data_buffer != NULL); |
331 memmove(data_buffer, isolate_data->udp_receive_buffer, bytes_read); | 336 memmove(data_buffer, isolate_data->udp_receive_buffer, bytes_read); |
332 | 337 |
333 // Get the port and clear it in the sockaddr structure. | 338 // Get the port and clear it in the sockaddr structure. |
334 int port = SocketAddress::GetAddrPort(addr); | 339 int port = SocketAddress::GetAddrPort(addr); |
335 if (addr.addr.sa_family == AF_INET) { | 340 if (addr.addr.sa_family == AF_INET) { |
336 addr.in.sin_port = 0; | 341 addr.in.sin_port = 0; |
337 } else { | 342 } else { |
338 ASSERT(addr.addr.sa_family == AF_INET6); | 343 ASSERT(addr.addr.sa_family == AF_INET6); |
339 addr.in6.sin6_port = 0; | 344 addr.in6.sin6_port = 0; |
340 } | 345 } |
341 // Format the address to a string using the numeric format. | 346 // Format the address to a string using the numeric format. |
342 char numeric_address[INET6_ADDRSTRLEN]; | 347 char numeric_address[INET6_ADDRSTRLEN]; |
343 Socket::FormatNumericAddress(addr, numeric_address, INET6_ADDRSTRLEN); | 348 Socket::FormatNumericAddress(addr, numeric_address, INET6_ADDRSTRLEN); |
344 | 349 |
345 // Create a Datagram object with the data and sender address and port. | 350 // Create a Datagram object with the data and sender address and port. |
346 const int kNumArgs = 4; | 351 const int kNumArgs = 4; |
347 Dart_Handle dart_args[kNumArgs]; | 352 Dart_Handle dart_args[kNumArgs]; |
348 dart_args[0] = data; | 353 dart_args[0] = data; |
349 dart_args[1] = Dart_NewStringFromCString(numeric_address); | 354 dart_args[1] = Dart_NewStringFromCString(numeric_address); |
350 if (Dart_IsError(dart_args[1])) Dart_PropagateError(dart_args[1]); | 355 if (Dart_IsError(dart_args[1])) { |
| 356 Dart_PropagateError(dart_args[1]); |
| 357 } |
351 dart_args[2] = SocketAddress::ToTypedData(addr); | 358 dart_args[2] = SocketAddress::ToTypedData(addr); |
352 dart_args[3] = Dart_NewInteger(port); | 359 dart_args[3] = Dart_NewInteger(port); |
353 if (Dart_IsError(dart_args[3])) Dart_PropagateError(dart_args[3]); | 360 if (Dart_IsError(dart_args[3])) { |
| 361 Dart_PropagateError(dart_args[3]); |
| 362 } |
354 // TODO(sgjesse): Cache the _makeDatagram function somewhere. | 363 // TODO(sgjesse): Cache the _makeDatagram function somewhere. |
355 Dart_Handle io_lib = | 364 Dart_Handle io_lib = |
356 Dart_LookupLibrary(DartUtils::NewString("dart:io")); | 365 Dart_LookupLibrary(DartUtils::NewString("dart:io")); |
357 if (Dart_IsError(io_lib)) Dart_PropagateError(io_lib); | 366 if (Dart_IsError(io_lib)) { |
| 367 Dart_PropagateError(io_lib); |
| 368 } |
358 Dart_Handle result = | 369 Dart_Handle result = |
359 Dart_Invoke(io_lib, | 370 Dart_Invoke(io_lib, |
360 DartUtils::NewString("_makeDatagram"), | 371 DartUtils::NewString("_makeDatagram"), |
361 kNumArgs, | 372 kNumArgs, |
362 dart_args); | 373 dart_args); |
363 Dart_SetReturnValue(args, result); | 374 Dart_SetReturnValue(args, result); |
364 } | 375 } |
365 | 376 |
366 | 377 |
367 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { | 378 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { |
368 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); | 379 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); |
369 intptr_t socket = | 380 intptr_t socket = |
370 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 381 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
371 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 382 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
372 ASSERT(Dart_IsList(buffer_obj)); | 383 ASSERT(Dart_IsList(buffer_obj)); |
373 intptr_t offset = | 384 intptr_t offset = |
374 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 385 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
375 intptr_t length = | 386 intptr_t length = |
376 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | 387 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); |
377 bool short_write = false; | 388 bool short_write = false; |
378 if (short_socket_writes) { | 389 if (short_socket_writes) { |
379 if (length > 1) short_write = true; | 390 if (length > 1) { |
| 391 short_write = true; |
| 392 } |
380 length = (length + 1) / 2; | 393 length = (length + 1) / 2; |
381 } | 394 } |
382 Dart_TypedData_Type type; | 395 Dart_TypedData_Type type; |
383 uint8_t* buffer = NULL; | 396 uint8_t* buffer = NULL; |
384 intptr_t len; | 397 intptr_t len; |
385 Dart_Handle result = Dart_TypedDataAcquireData( | 398 Dart_Handle result = Dart_TypedDataAcquireData( |
386 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); | 399 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); |
387 if (Dart_IsError(result)) Dart_PropagateError(result); | 400 if (Dart_IsError(result)) { |
| 401 Dart_PropagateError(result); |
| 402 } |
388 ASSERT((offset + length) <= len); | 403 ASSERT((offset + length) <= len); |
389 buffer += offset; | 404 buffer += offset; |
390 intptr_t bytes_written = Socket::Write(socket, buffer, length); | 405 intptr_t bytes_written = Socket::Write(socket, buffer, length); |
391 if (bytes_written >= 0) { | 406 if (bytes_written >= 0) { |
392 Dart_TypedDataReleaseData(buffer_obj); | 407 Dart_TypedDataReleaseData(buffer_obj); |
393 if (short_write) { | 408 if (short_write) { |
394 // If the write was forced 'short', indicate by returning the negative | 409 // If the write was forced 'short', indicate by returning the negative |
395 // number of bytes. A forced short write may not trigger a write event. | 410 // number of bytes. A forced short write may not trigger a write event. |
396 Dart_SetReturnValue(args, Dart_NewInteger(-bytes_written)); | 411 Dart_SetReturnValue(args, Dart_NewInteger(-bytes_written)); |
397 } else { | 412 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
421 int64_t port = DartUtils::GetInt64ValueCheckRange( | 436 int64_t port = DartUtils::GetInt64ValueCheckRange( |
422 Dart_GetNativeArgument(args, 5), | 437 Dart_GetNativeArgument(args, 5), |
423 0, | 438 0, |
424 65535); | 439 65535); |
425 SocketAddress::SetAddrPort(&addr, port); | 440 SocketAddress::SetAddrPort(&addr, port); |
426 Dart_TypedData_Type type; | 441 Dart_TypedData_Type type; |
427 uint8_t* buffer = NULL; | 442 uint8_t* buffer = NULL; |
428 intptr_t len; | 443 intptr_t len; |
429 Dart_Handle result = Dart_TypedDataAcquireData( | 444 Dart_Handle result = Dart_TypedDataAcquireData( |
430 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); | 445 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); |
431 if (Dart_IsError(result)) Dart_PropagateError(result); | 446 if (Dart_IsError(result)) { |
| 447 Dart_PropagateError(result); |
| 448 } |
432 ASSERT((offset + length) <= len); | 449 ASSERT((offset + length) <= len); |
433 buffer += offset; | 450 buffer += offset; |
434 intptr_t bytes_written = Socket::SendTo(socket, buffer, length, addr); | 451 intptr_t bytes_written = Socket::SendTo(socket, buffer, length, addr); |
435 if (bytes_written >= 0) { | 452 if (bytes_written >= 0) { |
436 Dart_TypedDataReleaseData(buffer_obj); | 453 Dart_TypedDataReleaseData(buffer_obj); |
437 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 454 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
438 } else { | 455 } else { |
439 // Extract OSError before we release data, as it may override the error. | 456 // Extract OSError before we release data, as it may override the error. |
440 OSError os_error; | 457 OSError os_error; |
441 Dart_TypedDataReleaseData(buffer_obj); | 458 Dart_TypedDataReleaseData(buffer_obj); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) { | 528 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) { |
512 int64_t num = DartUtils::GetInt64ValueCheckRange( | 529 int64_t num = DartUtils::GetInt64ValueCheckRange( |
513 Dart_GetNativeArgument(args, 1), 0, 2); | 530 Dart_GetNativeArgument(args, 1), 0, 2); |
514 intptr_t socket = Socket::GetStdioHandle(num); | 531 intptr_t socket = Socket::GetStdioHandle(num); |
515 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket); | 532 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket); |
516 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); | 533 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); |
517 } | 534 } |
518 | 535 |
519 | 536 |
520 void FUNCTION_NAME(Socket_GetSocketId)(Dart_NativeArguments args) { | 537 void FUNCTION_NAME(Socket_GetSocketId)(Dart_NativeArguments args) { |
521 intptr_t id = | 538 intptr_t id = Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
522 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | |
523 Dart_SetReturnValue(args, Dart_NewInteger(id)); | 539 Dart_SetReturnValue(args, Dart_NewInteger(id)); |
524 } | 540 } |
525 | 541 |
526 | 542 |
527 void FUNCTION_NAME(Socket_SetSocketId)(Dart_NativeArguments args) { | 543 void FUNCTION_NAME(Socket_SetSocketId)(Dart_NativeArguments args) { |
528 intptr_t id = | 544 intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
529 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); | |
530 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), id); | 545 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), id); |
531 } | 546 } |
532 | 547 |
533 | 548 |
534 void FUNCTION_NAME(ServerSocket_CreateBindListen)(Dart_NativeArguments args) { | 549 void FUNCTION_NAME(ServerSocket_CreateBindListen)(Dart_NativeArguments args) { |
535 RawAddr addr; | 550 RawAddr addr; |
536 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); | 551 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); |
537 int64_t port = DartUtils::GetInt64ValueCheckRange( | 552 int64_t port = DartUtils::GetInt64ValueCheckRange( |
538 Dart_GetNativeArgument(args, 2), | 553 Dart_GetNativeArgument(args, 2), |
539 0, | 554 0, |
(...skipping 22 matching lines...) Expand all Loading... |
562 Dart_SetReturnValue(args, Dart_True()); | 577 Dart_SetReturnValue(args, Dart_True()); |
563 } else if (new_socket == ServerSocket::kTemporaryFailure) { | 578 } else if (new_socket == ServerSocket::kTemporaryFailure) { |
564 Dart_SetReturnValue(args, Dart_False()); | 579 Dart_SetReturnValue(args, Dart_False()); |
565 } else { | 580 } else { |
566 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 581 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
567 } | 582 } |
568 } | 583 } |
569 | 584 |
570 | 585 |
571 CObject* Socket::LookupRequest(const CObjectArray& request) { | 586 CObject* Socket::LookupRequest(const CObjectArray& request) { |
572 if (request.Length() == 2 && | 587 if ((request.Length() == 2) && |
573 request[0]->IsString() && | 588 request[0]->IsString() && |
574 request[1]->IsInt32()) { | 589 request[1]->IsInt32()) { |
575 CObjectString host(request[0]); | 590 CObjectString host(request[0]); |
576 CObjectInt32 type(request[1]); | 591 CObjectInt32 type(request[1]); |
577 CObject* result = NULL; | 592 CObject* result = NULL; |
578 OSError* os_error = NULL; | 593 OSError* os_error = NULL; |
579 AddressList<SocketAddress>* addresses = | 594 AddressList<SocketAddress>* addresses = |
580 Socket::LookupAddress(host.CString(), type.Value(), &os_error); | 595 Socket::LookupAddress(host.CString(), type.Value(), &os_error); |
581 if (addresses != NULL) { | 596 if (addresses != NULL) { |
582 CObjectArray* array = new CObjectArray( | 597 CObjectArray* array = new CObjectArray( |
(...skipping 23 matching lines...) Expand all Loading... |
606 result = CObject::NewOSError(os_error); | 621 result = CObject::NewOSError(os_error); |
607 delete os_error; | 622 delete os_error; |
608 } | 623 } |
609 return result; | 624 return result; |
610 } | 625 } |
611 return CObject::IllegalArgumentError(); | 626 return CObject::IllegalArgumentError(); |
612 } | 627 } |
613 | 628 |
614 | 629 |
615 CObject* Socket::ReverseLookupRequest(const CObjectArray& request) { | 630 CObject* Socket::ReverseLookupRequest(const CObjectArray& request) { |
616 if (request.Length() == 1 && | 631 if ((request.Length() == 1) && |
617 request[0]->IsTypedData()) { | 632 request[0]->IsTypedData()) { |
618 CObjectUint8Array addr_object(request[0]); | 633 CObjectUint8Array addr_object(request[0]); |
619 RawAddr addr; | 634 RawAddr addr; |
620 int len = addr_object.Length(); | 635 int len = addr_object.Length(); |
621 memset(reinterpret_cast<void*>(&addr), 0, sizeof(RawAddr)); | 636 memset(reinterpret_cast<void*>(&addr), 0, sizeof(RawAddr)); |
622 if (len == sizeof(in_addr)) { | 637 if (len == sizeof(in_addr)) { |
623 addr.in.sin_family = AF_INET; | 638 addr.in.sin_family = AF_INET; |
624 memmove(reinterpret_cast<void*>(&addr.in.sin_addr), | 639 memmove(reinterpret_cast<void*>(&addr.in.sin_addr), |
625 addr_object.Buffer(), | 640 addr_object.Buffer(), |
626 len); | 641 len); |
(...skipping 14 matching lines...) Expand all Loading... |
641 CObject* result = CObject::NewOSError(os_error); | 656 CObject* result = CObject::NewOSError(os_error); |
642 delete os_error; | 657 delete os_error; |
643 return result; | 658 return result; |
644 } | 659 } |
645 } | 660 } |
646 return CObject::IllegalArgumentError(); | 661 return CObject::IllegalArgumentError(); |
647 } | 662 } |
648 | 663 |
649 | 664 |
650 CObject* Socket::ListInterfacesRequest(const CObjectArray& request) { | 665 CObject* Socket::ListInterfacesRequest(const CObjectArray& request) { |
651 if (request.Length() == 1 && | 666 if ((request.Length() == 1) && |
652 request[0]->IsInt32()) { | 667 request[0]->IsInt32()) { |
653 CObjectInt32 type(request[0]); | 668 CObjectInt32 type(request[0]); |
654 CObject* result = NULL; | 669 CObject* result = NULL; |
655 OSError* os_error = NULL; | 670 OSError* os_error = NULL; |
656 AddressList<InterfaceSocketAddress>* addresses = Socket::ListInterfaces( | 671 AddressList<InterfaceSocketAddress>* addresses = Socket::ListInterfaces( |
657 type.Value(), &os_error); | 672 type.Value(), &os_error); |
658 if (addresses != NULL) { | 673 if (addresses != NULL) { |
659 CObjectArray* array = new CObjectArray( | 674 CObjectArray* array = new CObjectArray( |
660 CObject::NewArray(addresses->count() + 1)); | 675 CObject::NewArray(addresses->count() + 1)); |
661 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); | 676 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 Dart_SetReturnValue(args, Dart_Null()); | 849 Dart_SetReturnValue(args, Dart_Null()); |
835 } else { | 850 } else { |
836 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 851 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
837 } | 852 } |
838 } | 853 } |
839 | 854 |
840 | 855 |
841 void Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { | 856 void Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { |
842 Dart_Handle err = | 857 Dart_Handle err = |
843 Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); | 858 Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); |
844 if (Dart_IsError(err)) Dart_PropagateError(err); | 859 if (Dart_IsError(err)) { |
| 860 Dart_PropagateError(err); |
| 861 } |
845 } | 862 } |
846 | 863 |
847 | 864 |
848 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { | 865 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { |
849 intptr_t socket = 0; | 866 intptr_t socket = 0; |
850 Dart_Handle err = | 867 Dart_Handle err = |
851 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); | 868 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); |
852 if (Dart_IsError(err)) Dart_PropagateError(err); | 869 if (Dart_IsError(err)) { |
| 870 Dart_PropagateError(err); |
| 871 } |
853 return socket; | 872 return socket; |
854 } | 873 } |
855 | 874 |
856 } // namespace bin | 875 } // namespace bin |
857 } // namespace dart | 876 } // namespace dart |
OLD | NEW |