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/io_buffer.h" | 5 #include "bin/io_buffer.h" |
6 #include "bin/socket.h" | 6 #include "bin/socket.h" |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "bin/thread.h" | 8 #include "bin/thread.h" |
9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
10 | 10 |
11 #include "platform/globals.h" | 11 #include "platform/globals.h" |
12 #include "platform/thread.h" | 12 #include "platform/thread.h" |
13 #include "platform/utils.h" | 13 #include "platform/utils.h" |
14 | 14 |
15 #include "include/dart_api.h" | 15 #include "include/dart_api.h" |
16 | 16 #include "include/dart_native_api.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 namespace bin { | 19 namespace bin { |
20 | 20 |
21 static const int kSocketIdNativeField = 0; | 21 static const int kSocketIdNativeField = 0; |
22 | 22 |
23 dart::Mutex* Socket::mutex_ = new dart::Mutex(); | 23 dart::Mutex* Socket::mutex_ = new dart::Mutex(); |
24 int Socket::service_ports_size_ = 0; | 24 int Socket::service_ports_size_ = 0; |
25 Dart_Port* Socket::service_ports_ = NULL; | 25 Dart_Port* Socket::service_ports_ = NULL; |
26 int Socket::service_ports_index_ = 0; | 26 int Socket::service_ports_index_ = 0; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 if (length == -1 || available < length) { | 141 if (length == -1 || available < length) { |
142 length = available; | 142 length = available; |
143 } | 143 } |
144 if (short_socket_reads) { | 144 if (short_socket_reads) { |
145 length = (length + 1) / 2; | 145 length = (length + 1) / 2; |
146 } | 146 } |
147 uint8_t* buffer = NULL; | 147 uint8_t* buffer = NULL; |
148 Dart_Handle result = IOBuffer::Allocate(length, &buffer); | 148 Dart_Handle result = IOBuffer::Allocate(length, &buffer); |
149 if (Dart_IsError(result)) Dart_PropagateError(result); | 149 if (Dart_IsError(result)) Dart_PropagateError(result); |
150 ASSERT(buffer != NULL); | 150 ASSERT(buffer != NULL); |
| 151 Dart_DisableThreadInterrupter(); |
151 intptr_t bytes_read = Socket::Read(socket, buffer, length); | 152 intptr_t bytes_read = Socket::Read(socket, buffer, length); |
| 153 Dart_EnableThreadInterrupter(); |
152 if (bytes_read == length) { | 154 if (bytes_read == length) { |
153 Dart_SetReturnValue(args, result); | 155 Dart_SetReturnValue(args, result); |
154 } else if (bytes_read < length) { | 156 } else if (bytes_read < length) { |
155 // On MacOS when reading from a tty Ctrl-D will result in reading one | 157 // On MacOS when reading from a tty Ctrl-D will result in reading one |
156 // less byte then reported as available. | 158 // less byte then reported as available. |
157 if (bytes_read == 0) { | 159 if (bytes_read == 0) { |
158 Dart_SetReturnValue(args, Dart_Null()); | 160 Dart_SetReturnValue(args, Dart_Null()); |
159 } else { | 161 } else { |
160 uint8_t* new_buffer = NULL; | 162 uint8_t* new_buffer = NULL; |
161 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); | 163 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 length = (length + 1) / 2; | 198 length = (length + 1) / 2; |
197 } | 199 } |
198 Dart_TypedData_Type type; | 200 Dart_TypedData_Type type; |
199 uint8_t* buffer = NULL; | 201 uint8_t* buffer = NULL; |
200 intptr_t len; | 202 intptr_t len; |
201 Dart_Handle result = Dart_TypedDataAcquireData( | 203 Dart_Handle result = Dart_TypedDataAcquireData( |
202 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); | 204 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); |
203 if (Dart_IsError(result)) Dart_PropagateError(result); | 205 if (Dart_IsError(result)) Dart_PropagateError(result); |
204 ASSERT((offset + length) <= len); | 206 ASSERT((offset + length) <= len); |
205 buffer += offset; | 207 buffer += offset; |
| 208 Dart_DisableThreadInterrupter(); |
206 intptr_t bytes_written = Socket::Write(socket, buffer, length); | 209 intptr_t bytes_written = Socket::Write(socket, buffer, length); |
| 210 Dart_EnableThreadInterrupter(); |
207 if (bytes_written >= 0) { | 211 if (bytes_written >= 0) { |
208 Dart_TypedDataReleaseData(buffer_obj); | 212 Dart_TypedDataReleaseData(buffer_obj); |
209 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 213 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
210 } else { | 214 } else { |
211 // Extract OSError before we release data, as it may override the error. | 215 // Extract OSError before we release data, as it may override the error. |
212 OSError os_error; | 216 OSError os_error; |
213 Dart_TypedDataReleaseData(buffer_obj); | 217 Dart_TypedDataReleaseData(buffer_obj); |
214 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 218 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
215 } | 219 } |
216 } | 220 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { | 504 intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) { |
501 intptr_t socket = 0; | 505 intptr_t socket = 0; |
502 Dart_Handle err = | 506 Dart_Handle err = |
503 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); | 507 Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket); |
504 if (Dart_IsError(err)) Dart_PropagateError(err); | 508 if (Dart_IsError(err)) Dart_PropagateError(err); |
505 return socket; | 509 return socket; |
506 } | 510 } |
507 | 511 |
508 } // namespace bin | 512 } // namespace bin |
509 } // namespace dart | 513 } // namespace dart |
OLD | NEW |