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

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

Issue 3009643002: Fix for Flutter issue 11260 (https://github.com/flutter/flutter/issues/11260) (Closed)
Patch Set: Created 3 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
« no previous file with comments | « runtime/bin/isolate_data.cc ('k') | no next file » | 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) 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/socket.h" 5 #include "bin/socket.h"
6 6
7 #include "bin/dartutils.h" 7 #include "bin/dartutils.h"
8 #include "bin/eventhandler.h" 8 #include "bin/eventhandler.h"
9 #include "bin/io_buffer.h" 9 #include "bin/io_buffer.h"
10 #include "bin/isolate_data.h" 10 #include "bin/isolate_data.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } else { 358 } else {
359 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 359 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
360 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); 360 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
361 } 361 }
362 } 362 }
363 363
364 void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) { 364 void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) {
365 Socket* socket = 365 Socket* socket =
366 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); 366 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
367 367
368 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can 368 intptr_t available = SocketBase::Available(socket->fd());
zra 2017/08/25 20:33:31 const
siva 2017/08/25 22:07:28 Done.
369 // handle 64k datagrams. 369 if (available < 0) {
370 IsolateData* isolate_data = 370 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
371 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); 371 return;
372 if (isolate_data->udp_receive_buffer == NULL) {
373 isolate_data->udp_receive_buffer =
374 reinterpret_cast<uint8_t*>(malloc(65536));
375 } 372 }
373
374 // Allocate a buffer of the exact size into which data can be read.
375 uint8_t* data_buffer = NULL;
376 Dart_Handle data = IOBuffer::Allocate(available, &data_buffer);
377 if (Dart_IsError(data)) {
378 Dart_PropagateError(data);
379 }
380 ASSERT(data_buffer != NULL);
381
382 // Read data into the buffer.
376 RawAddr addr; 383 RawAddr addr;
377 intptr_t bytes_read = 384 intptr_t bytes_read = SocketBase::RecvFrom(
zra 2017/08/25 20:33:31 const
siva 2017/08/25 22:07:28 Done.
378 SocketBase::RecvFrom(socket->fd(), isolate_data->udp_receive_buffer, 385 socket->fd(), data_buffer, available, &addr, SocketBase::kAsync);
379 65536, &addr, SocketBase::kAsync);
380 if (bytes_read == 0) { 386 if (bytes_read == 0) {
381 Dart_SetReturnValue(args, Dart_Null()); 387 Dart_SetReturnValue(args, Dart_Null());
zra 2017/08/25 20:33:31 It looks like SocketBase:Available() can return 0.
siva 2017/08/25 22:07:27 Added a 0 check above.
382 return; 388 return;
383 } 389 }
384 if (bytes_read < 0) { 390 if (bytes_read < 0) {
385 ASSERT(bytes_read == -1); 391 ASSERT(bytes_read == -1);
386 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 392 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
387 return; 393 return;
388 } 394 }
389 // Datagram data read. Copy into buffer of the exact size,
390 ASSERT(bytes_read > 0);
391 uint8_t* data_buffer = NULL;
392 Dart_Handle data = IOBuffer::Allocate(bytes_read, &data_buffer);
393 if (Dart_IsError(data)) {
394 Dart_PropagateError(data);
395 }
396 ASSERT(data_buffer != NULL);
397 memmove(data_buffer, isolate_data->udp_receive_buffer, bytes_read);
398 395
399 // Get the port and clear it in the sockaddr structure. 396 // Get the port and clear it in the sockaddr structure.
400 int port = SocketAddress::GetAddrPort(addr); 397 int port = SocketAddress::GetAddrPort(addr);
401 if (addr.addr.sa_family == AF_INET) { 398 if (addr.addr.sa_family == AF_INET) {
402 addr.in.sin_port = 0; 399 addr.in.sin_port = 0;
403 } else { 400 } else {
404 ASSERT(addr.addr.sa_family == AF_INET6); 401 ASSERT(addr.addr.sa_family == AF_INET6);
405 addr.in6.sin6_port = 0; 402 addr.in6.sin6_port = 0;
406 } 403 }
407 // Format the address to a string using the numeric format. 404 // Format the address to a string using the numeric format.
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &id); 955 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &id);
959 if (Dart_IsError(err)) { 956 if (Dart_IsError(err)) {
960 Dart_PropagateError(err); 957 Dart_PropagateError(err);
961 } 958 }
962 Socket* socket = reinterpret_cast<Socket*>(id); 959 Socket* socket = reinterpret_cast<Socket*>(id);
963 return socket; 960 return socket;
964 } 961 }
965 962
966 } // namespace bin 963 } // namespace bin
967 } // namespace dart 964 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/isolate_data.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698