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

Unified Diff: runtime/bin/socket.cc

Issue 3005663002: Revert "Fix for Flutter issue 11260 (https://github.com/flutter/flutter/issues/11260)" (Closed)
Patch Set: Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/isolate_data.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket.cc
diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc
index f6c01fba078a80fb8f36a6da967b7aba390a7128..e2e16778c3fb6179976d06a4e5ef4a384fbd1b0f 100644
--- a/runtime/bin/socket.cc
+++ b/runtime/bin/socket.cc
@@ -365,28 +365,18 @@ void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) {
Socket* socket =
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
- const intptr_t available = SocketBase::Available(socket->fd());
- if (available < 0) {
- Dart_SetReturnValue(args, DartUtils::NewDartOSError());
- return;
- }
- if (available == 0) {
- Dart_SetReturnValue(args, Dart_Null());
- return;
+ // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can
+ // handle 64k datagrams.
+ IsolateData* isolate_data =
+ reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
+ if (isolate_data->udp_receive_buffer == NULL) {
+ isolate_data->udp_receive_buffer =
+ reinterpret_cast<uint8_t*>(malloc(65536));
}
-
- // Allocate a buffer of the exact size into which data can be read.
- uint8_t* data_buffer = NULL;
- Dart_Handle data = IOBuffer::Allocate(available, &data_buffer);
- if (Dart_IsError(data)) {
- Dart_PropagateError(data);
- }
- ASSERT(data_buffer != NULL);
-
- // Read data into the buffer.
RawAddr addr;
- const intptr_t bytes_read = SocketBase::RecvFrom(
- socket->fd(), data_buffer, available, &addr, SocketBase::kAsync);
+ intptr_t bytes_read =
+ SocketBase::RecvFrom(socket->fd(), isolate_data->udp_receive_buffer,
+ 65536, &addr, SocketBase::kAsync);
if (bytes_read == 0) {
Dart_SetReturnValue(args, Dart_Null());
return;
@@ -396,6 +386,15 @@ void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) {
Dart_SetReturnValue(args, DartUtils::NewDartOSError());
return;
}
+ // Datagram data read. Copy into buffer of the exact size,
+ ASSERT(bytes_read > 0);
+ uint8_t* data_buffer = NULL;
+ Dart_Handle data = IOBuffer::Allocate(bytes_read, &data_buffer);
+ if (Dart_IsError(data)) {
+ Dart_PropagateError(data);
+ }
+ ASSERT(data_buffer != NULL);
+ memmove(data_buffer, isolate_data->udp_receive_buffer, bytes_read);
// Get the port and clear it in the sockaddr structure.
int port = SocketAddress::GetAddrPort(addr);
« 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