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

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

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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/secure_socket_patch.dart ('k') | runtime/bin/socket_linux.cc » ('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) 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
(...skipping 11 matching lines...) Expand all
22 int Socket::service_ports_index_ = 0; 22 int Socket::service_ports_index_ = 0;
23 23
24 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { 24 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) {
25 Dart_EnterScope(); 25 Dart_EnterScope();
26 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 26 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
27 const char* host = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1)); 27 const char* host = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
28 int64_t port = 0; 28 int64_t port = 0;
29 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) { 29 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &port)) {
30 intptr_t socket = Socket::CreateConnect(host, port); 30 intptr_t socket = Socket::CreateConnect(host, port);
31 if (socket >= 0) { 31 if (socket >= 0) {
32 Socket::SetSocketIdNativeField(socket_obj, socket); 32 Dart_Handle err = Socket::SetSocketIdNativeField(socket_obj, socket);
33 if (Dart_IsError(err)) Dart_PropagateError(err);
33 Dart_SetReturnValue(args, Dart_True()); 34 Dart_SetReturnValue(args, Dart_True());
34 } else { 35 } else {
35 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 36 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
36 } 37 }
37 } else { 38 } else {
38 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 39 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
39 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 40 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
40 if (Dart_IsError(err)) Dart_PropagateError(err); 41 if (Dart_IsError(err)) Dart_PropagateError(err);
41 Dart_SetReturnValue(args, err); 42 Dart_SetReturnValue(args, err);
42 } 43 }
43 Dart_ExitScope(); 44 Dart_ExitScope();
44 } 45 }
45 46
46 47
47 void FUNCTION_NAME(Socket_Available)(Dart_NativeArguments args) { 48 void FUNCTION_NAME(Socket_Available)(Dart_NativeArguments args) {
48 Dart_EnterScope(); 49 Dart_EnterScope();
49 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 50 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
50 intptr_t socket = 0; 51 intptr_t socket = 0;
51 Socket::GetSocketIdNativeField(socket_obj, &socket); 52 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
53 if (Dart_IsError(err)) Dart_PropagateError(err);
52 intptr_t available = Socket::Available(socket); 54 intptr_t available = Socket::Available(socket);
53 if (available >= 0) { 55 if (available >= 0) {
54 Dart_SetReturnValue(args, Dart_NewInteger(available)); 56 Dart_SetReturnValue(args, Dart_NewInteger(available));
55 } else { 57 } else {
56 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 58 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
57 } 59 }
58 Dart_ExitScope(); 60 Dart_ExitScope();
59 } 61 }
60 62
61 63
62 void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) { 64 void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) {
63 Dart_EnterScope(); 65 Dart_EnterScope();
64 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 66 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
65 intptr_t socket = 0; 67 intptr_t socket = 0;
66 Socket::GetSocketIdNativeField(socket_obj, &socket); 68 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
69 if (Dart_IsError(err)) Dart_PropagateError(err);
67 intptr_t available = Socket::Available(socket); 70 intptr_t available = Socket::Available(socket);
68 if (available > 0) { 71 if (available > 0) {
69 int64_t length = 0; 72 int64_t length = 0;
70 Dart_Handle length_obj = Dart_GetNativeArgument(args, 1); 73 Dart_Handle length_obj = Dart_GetNativeArgument(args, 1);
71 if (DartUtils::GetInt64Value(length_obj, &length)) { 74 if (DartUtils::GetInt64Value(length_obj, &length)) {
72 if (length == -1 || available < length) { 75 if (length == -1 || available < length) {
73 length = available; 76 length = available;
74 } 77 }
75 uint8_t* buffer = NULL; 78 uint8_t* buffer = NULL;
76 Dart_Handle result = IOBuffer::Allocate(length, &buffer); 79 Dart_Handle result = IOBuffer::Allocate(length, &buffer);
(...skipping 26 matching lines...) Expand all
103 106
104 Dart_ExitScope(); 107 Dart_ExitScope();
105 } 108 }
106 109
107 110
108 void FUNCTION_NAME(Socket_ReadList)(Dart_NativeArguments args) { 111 void FUNCTION_NAME(Socket_ReadList)(Dart_NativeArguments args) {
109 Dart_EnterScope(); 112 Dart_EnterScope();
110 static bool short_socket_reads = Dart_IsVMFlagSet("short_socket_read"); 113 static bool short_socket_reads = Dart_IsVMFlagSet("short_socket_read");
111 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 114 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
112 intptr_t socket = 0; 115 intptr_t socket = 0;
113 Socket::GetSocketIdNativeField(socket_obj, &socket); 116 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
117 if (Dart_IsError(err)) Dart_PropagateError(err);
114 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 118 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
115 int64_t offset = 0; 119 int64_t offset = 0;
116 int64_t length = 0; 120 int64_t length = 0;
117 Dart_Handle offset_obj = Dart_GetNativeArgument(args, 2); 121 Dart_Handle offset_obj = Dart_GetNativeArgument(args, 2);
118 Dart_Handle length_obj = Dart_GetNativeArgument(args, 3); 122 Dart_Handle length_obj = Dart_GetNativeArgument(args, 3);
119 if (Dart_IsList(buffer_obj) && 123 if (Dart_IsList(buffer_obj) &&
120 DartUtils::GetInt64Value(offset_obj, &offset) && 124 DartUtils::GetInt64Value(offset_obj, &offset) &&
121 DartUtils::GetInt64Value(length_obj, &length)) { 125 DartUtils::GetInt64Value(length_obj, &length)) {
122 intptr_t buffer_len = 0; 126 intptr_t buffer_len = 0;
123 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); 127 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
(...skipping 29 matching lines...) Expand all
153 157
154 Dart_ExitScope(); 158 Dart_ExitScope();
155 } 159 }
156 160
157 161
158 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { 162 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
159 Dart_EnterScope(); 163 Dart_EnterScope();
160 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write"); 164 static bool short_socket_writes = Dart_IsVMFlagSet("short_socket_write");
161 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 165 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
162 intptr_t socket = 0; 166 intptr_t socket = 0;
163 Socket::GetSocketIdNativeField(socket_obj, &socket); 167 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
168 if (Dart_IsError(err)) Dart_PropagateError(err);
164 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 169 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
165 ASSERT(Dart_IsList(buffer_obj)); 170 ASSERT(Dart_IsList(buffer_obj));
166 intptr_t offset = 171 intptr_t offset =
167 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 172 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
168 intptr_t length = 173 intptr_t length =
169 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 174 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
170 intptr_t buffer_len = 0; 175 intptr_t buffer_len = 0;
171 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); 176 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
172 if (Dart_IsError(result)) { 177 if (Dart_IsError(result)) {
173 Dart_PropagateError(result); 178 Dart_PropagateError(result);
174 } 179 }
175 ASSERT((offset + length) <= buffer_len); 180 ASSERT((offset + length) <= buffer_len);
176 181
177 if (short_socket_writes) { 182 if (short_socket_writes) {
178 length = (length + 1) / 2; 183 length = (length + 1) / 2;
179 } 184 }
180 185
181 intptr_t total_bytes_written = 0; 186 intptr_t total_bytes_written = 0;
182 intptr_t bytes_written = 0; 187 intptr_t bytes_written = 0;
183 if (Dart_IsByteArrayExternal(buffer_obj)) { 188 if (Dart_IsByteArrayExternal(buffer_obj)) {
184 void* buffer = NULL; 189 void* buffer = NULL;
185 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer); 190 result = Dart_ExternalByteArrayGetData(buffer_obj, &buffer);
186 if (Dart_IsError(result)) { 191 if (Dart_IsError(result)) {
187 Dart_PropagateError(result); 192 Dart_PropagateError(result);
188 } 193 }
189 buffer = static_cast<void*>((static_cast<uint8_t*>(buffer) + offset)); 194 buffer = static_cast<void*>(static_cast<uint8_t*>(buffer) + offset);
190 bytes_written = Socket::Write(socket, buffer, length); 195 bytes_written = Socket::Write(socket, buffer, length);
191 if (bytes_written > 0) total_bytes_written = bytes_written; 196 if (bytes_written > 0) total_bytes_written = bytes_written;
192 } else { 197 } else {
193 // Send data in chunks of maximum 16KB. 198 // Send data in chunks of maximum 16KB.
194 const intptr_t max_chunk_length = 199 const intptr_t max_chunk_length =
195 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB)); 200 dart::Utils::Minimum(length, static_cast<intptr_t>(16 * KB));
196 uint8_t* buffer = new uint8_t[max_chunk_length]; 201 uint8_t* buffer = new uint8_t[max_chunk_length];
197 do { 202 do {
198 intptr_t chunk_length = 203 intptr_t chunk_length =
199 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written); 204 dart::Utils::Minimum(max_chunk_length, length - total_bytes_written);
(...skipping 17 matching lines...) Expand all
217 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 222 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
218 } 223 }
219 Dart_ExitScope(); 224 Dart_ExitScope();
220 } 225 }
221 226
222 227
223 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { 228 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) {
224 Dart_EnterScope(); 229 Dart_EnterScope();
225 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 230 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
226 intptr_t socket = 0; 231 intptr_t socket = 0;
227 Socket::GetSocketIdNativeField(socket_obj, &socket); 232 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
233 if (Dart_IsError(err)) Dart_PropagateError(err);
228 OSError os_error; 234 OSError os_error;
229 intptr_t port = Socket::GetPort(socket); 235 intptr_t port = Socket::GetPort(socket);
230 if (port > 0) { 236 if (port > 0) {
231 Dart_SetReturnValue(args, Dart_NewInteger(port)); 237 Dart_SetReturnValue(args, Dart_NewInteger(port));
232 } else { 238 } else {
233 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 239 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
234 } 240 }
235 Dart_ExitScope(); 241 Dart_ExitScope();
236 } 242 }
237 243
238 244
239 void FUNCTION_NAME(Socket_GetRemotePeer)(Dart_NativeArguments args) { 245 void FUNCTION_NAME(Socket_GetRemotePeer)(Dart_NativeArguments args) {
240 Dart_EnterScope(); 246 Dart_EnterScope();
241 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 247 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
242 intptr_t socket = 0; 248 intptr_t socket = 0;
243 Socket::GetSocketIdNativeField(socket_obj, &socket); 249 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
250 if (Dart_IsError(err)) Dart_PropagateError(err);
244 OSError os_error; 251 OSError os_error;
245 intptr_t port = 0; 252 intptr_t port = 0;
246 char host[INET_ADDRSTRLEN]; 253 char host[INET_ADDRSTRLEN];
247 if (Socket::GetRemotePeer(socket, host, &port)) { 254 if (Socket::GetRemotePeer(socket, host, &port)) {
248 Dart_Handle list = Dart_NewList(2); 255 Dart_Handle list = Dart_NewList(2);
249 Dart_ListSetAt(list, 0, Dart_NewStringFromCString(host)); 256 Dart_ListSetAt(list, 0, Dart_NewStringFromCString(host));
250 Dart_ListSetAt(list, 1, Dart_NewInteger(port)); 257 Dart_ListSetAt(list, 1, Dart_NewInteger(port));
251 Dart_SetReturnValue(args, list); 258 Dart_SetReturnValue(args, list);
252 } else { 259 } else {
253 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 260 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
254 } 261 }
255 Dart_ExitScope(); 262 Dart_ExitScope();
256 } 263 }
257 264
258 265
259 void FUNCTION_NAME(Socket_GetError)(Dart_NativeArguments args) { 266 void FUNCTION_NAME(Socket_GetError)(Dart_NativeArguments args) {
260 Dart_EnterScope(); 267 Dart_EnterScope();
261 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 268 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
262 intptr_t socket = 0; 269 intptr_t socket = 0;
263 Socket::GetSocketIdNativeField(socket_obj, &socket); 270 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
271 if (Dart_IsError(err)) Dart_PropagateError(err);
264 OSError os_error; 272 OSError os_error;
265 Socket::GetError(socket, &os_error); 273 Socket::GetError(socket, &os_error);
266 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); 274 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
267 Dart_ExitScope(); 275 Dart_ExitScope();
268 } 276 }
269 277
270 278
271 void FUNCTION_NAME(Socket_GetType)(Dart_NativeArguments args) { 279 void FUNCTION_NAME(Socket_GetType)(Dart_NativeArguments args) {
272 Dart_EnterScope(); 280 Dart_EnterScope();
273 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 281 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
(...skipping 10 matching lines...) Expand all
284 } 292 }
285 293
286 294
287 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) { 295 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) {
288 Dart_EnterScope(); 296 Dart_EnterScope();
289 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 297 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
290 intptr_t num = 298 intptr_t num =
291 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); 299 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
292 ASSERT(num == 0 || num == 1 || num == 2); 300 ASSERT(num == 0 || num == 1 || num == 2);
293 intptr_t socket = Socket::GetStdioHandle(num); 301 intptr_t socket = Socket::GetStdioHandle(num);
294 Socket::SetSocketIdNativeField(socket_obj, socket); 302 Dart_Handle err = Socket::SetSocketIdNativeField(socket_obj, socket);
303 if (Dart_IsError(err)) Dart_PropagateError(err);
295 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); 304 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0));
296 Dart_ExitScope(); 305 Dart_ExitScope();
297 } 306 }
298 307
299 308
300 void FUNCTION_NAME(ServerSocket_CreateBindListen)(Dart_NativeArguments args) { 309 void FUNCTION_NAME(ServerSocket_CreateBindListen)(Dart_NativeArguments args) {
301 Dart_EnterScope(); 310 Dart_EnterScope();
302 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 311 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
303 Dart_Handle bind_address_obj = Dart_GetNativeArgument(args, 1); 312 Dart_Handle bind_address_obj = Dart_GetNativeArgument(args, 1);
304 Dart_Handle port_obj = Dart_GetNativeArgument(args, 2); 313 Dart_Handle port_obj = Dart_GetNativeArgument(args, 2);
305 Dart_Handle backlog_obj = Dart_GetNativeArgument(args, 3); 314 Dart_Handle backlog_obj = Dart_GetNativeArgument(args, 3);
306 int64_t port = 0; 315 int64_t port = 0;
307 int64_t backlog = 0; 316 int64_t backlog = 0;
308 if (Dart_IsString(bind_address_obj) && 317 if (Dart_IsString(bind_address_obj) &&
309 DartUtils::GetInt64Value(port_obj, &port) && 318 DartUtils::GetInt64Value(port_obj, &port) &&
310 DartUtils::GetInt64Value(backlog_obj, &backlog)) { 319 DartUtils::GetInt64Value(backlog_obj, &backlog)) {
311 const char* bind_address = DartUtils::GetStringValue(bind_address_obj); 320 const char* bind_address = DartUtils::GetStringValue(bind_address_obj);
312 intptr_t socket = 321 intptr_t socket =
313 ServerSocket::CreateBindListen(bind_address, port, backlog); 322 ServerSocket::CreateBindListen(bind_address, port, backlog);
314 if (socket >= 0) { 323 if (socket >= 0) {
315 Socket::SetSocketIdNativeField(socket_obj, socket); 324 Dart_Handle err = Socket::SetSocketIdNativeField(socket_obj, socket);
325 if (Dart_IsError(err)) Dart_PropagateError(err);
316 Dart_SetReturnValue(args, Dart_True()); 326 Dart_SetReturnValue(args, Dart_True());
317 } else { 327 } else {
318 if (socket == -5) { 328 if (socket == -5) {
319 OSError os_error(-1, "Invalid host", OSError::kUnknown); 329 OSError os_error(-1, "Invalid host", OSError::kUnknown);
320 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); 330 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error));
321 } else { 331 } else {
322 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 332 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
323 } 333 }
324 } 334 }
325 } else { 335 } else {
326 OSError os_error(-1, "Invalid argument", OSError::kUnknown); 336 OSError os_error(-1, "Invalid argument", OSError::kUnknown);
327 Dart_Handle err = DartUtils::NewDartOSError(&os_error); 337 Dart_Handle err = DartUtils::NewDartOSError(&os_error);
328 if (Dart_IsError(err)) Dart_PropagateError(err); 338 if (Dart_IsError(err)) Dart_PropagateError(err);
329 Dart_SetReturnValue(args, err); 339 Dart_SetReturnValue(args, err);
330 } 340 }
331 Dart_ExitScope(); 341 Dart_ExitScope();
332 } 342 }
333 343
334 344
335 void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) { 345 void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) {
336 Dart_EnterScope(); 346 Dart_EnterScope();
337 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0); 347 Dart_Handle socket_obj = Dart_GetNativeArgument(args, 0);
338 intptr_t socket = 0; 348 intptr_t socket = 0;
339 Socket::GetSocketIdNativeField(socket_obj, &socket); 349 Dart_Handle err = Socket::GetSocketIdNativeField(socket_obj, &socket);
350 if (Dart_IsError(err)) Dart_PropagateError(err);
340 Dart_Handle result_socket_obj = Dart_GetNativeArgument(args, 1); 351 Dart_Handle result_socket_obj = Dart_GetNativeArgument(args, 1);
341 intptr_t new_socket = ServerSocket::Accept(socket); 352 intptr_t new_socket = ServerSocket::Accept(socket);
342 if (new_socket >= 0) { 353 if (new_socket >= 0) {
343 Socket::SetSocketIdNativeField(result_socket_obj, new_socket); 354 Dart_Handle err = Socket::SetSocketIdNativeField(result_socket_obj,
355 new_socket);
356 if (Dart_IsError(err)) Dart_PropagateError(err);
344 Dart_SetReturnValue(args, Dart_True()); 357 Dart_SetReturnValue(args, Dart_True());
345 } else if (new_socket == ServerSocket::kTemporaryFailure) { 358 } else if (new_socket == ServerSocket::kTemporaryFailure) {
346 Dart_SetReturnValue(args, Dart_False()); 359 Dart_SetReturnValue(args, Dart_False());
347 } else { 360 } else {
348 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); 361 Dart_SetReturnValue(args, DartUtils::NewDartOSError());
349 } 362 }
350 Dart_ExitScope(); 363 Dart_ExitScope();
351 } 364 }
352 365
353 366
(...skipping 13 matching lines...) Expand all
367 } 380 }
368 return result; 381 return result;
369 } 382 }
370 return CObject::IllegalArgumentError(); 383 return CObject::IllegalArgumentError();
371 } 384 }
372 385
373 386
374 void SocketService(Dart_Port dest_port_id, 387 void SocketService(Dart_Port dest_port_id,
375 Dart_Port reply_port_id, 388 Dart_Port reply_port_id,
376 Dart_CObject* message) { 389 Dart_CObject* message) {
377 CObject* response = CObject::False(); 390 CObject* response = CObject::IllegalArgumentError();
378 CObjectArray request(message); 391 CObjectArray request(message);
379 if (message->type == Dart_CObject::kArray) { 392 if (message->type == Dart_CObject::kArray) {
380 if (request.Length() > 1 && request[0]->IsInt32()) { 393 if (request.Length() > 1 && request[0]->IsInt32()) {
381 CObjectInt32 request_type(request[0]); 394 CObjectInt32 request_type(request[0]);
382 switch (request_type.Value()) { 395 switch (request_type.Value()) {
383 case Socket::kLookupRequest: 396 case Socket::kLookupRequest:
384 response = LookupRequest(request); 397 response = LookupRequest(request);
385 break; 398 break;
386 default: 399 default:
387 UNREACHABLE(); 400 UNREACHABLE();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 445
433 446
434 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) { 447 Dart_Handle Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) {
435 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id); 448 return Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id);
436 } 449 }
437 450
438 451
439 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) { 452 Dart_Handle Socket::GetSocketIdNativeField(Dart_Handle socket, intptr_t* id) {
440 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id); 453 return Dart_GetNativeInstanceField(socket, kSocketIdNativeField, id);
441 } 454 }
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket_patch.dart ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698