Chromium Code Reviews| 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "bin/socket.h" | 7 #include "bin/socket.h" |
| 8 | 8 |
| 9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
| 10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
| 11 #include "bin/io_buffer.h" | 11 #include "bin/io_buffer.h" |
| 12 #include "bin/isolate_data.h" | 12 #include "bin/isolate_data.h" |
| 13 #include "bin/lockers.h" | 13 #include "bin/lockers.h" |
| 14 #include "bin/thread.h" | 14 #include "bin/thread.h" |
| 15 #include "bin/utils.h" | 15 #include "bin/utils.h" |
| 16 | 16 |
| 17 #include "include/dart_api.h" | 17 #include "include/dart_api.h" |
| 18 | 18 |
| 19 #include "platform/globals.h" | 19 #include "platform/globals.h" |
| 20 #include "platform/utils.h" | 20 #include "platform/utils.h" |
| 21 | 21 |
| 22 namespace dart { | 22 namespace dart { |
| 23 namespace bin { | 23 namespace bin { |
| 24 | 24 |
| 25 static const int kSocketIdNativeField = 0; | 25 static const int kSocketIdNativeField = 0; |
| 26 | 26 |
| 27 ListeningSocketRegistry* globalTcpListeningSocketRegistry = NULL; | |
| 28 | |
| 29 bool short_socket_read = false; | 27 bool short_socket_read = false; |
| 30 | 28 |
| 31 bool short_socket_write = false; | 29 bool short_socket_write = false; |
| 32 | 30 |
| 31 ListeningSocketRegistry* globalTcpListeningSocketRegistry = NULL; | |
|
zra
2017/03/30 19:59:44
Why move this?
bkonyi
2017/04/01 23:41:18
I had moved it before I had decided to refactor, m
| |
| 32 | |
| 33 void ListeningSocketRegistry::Initialize() { | 33 void ListeningSocketRegistry::Initialize() { |
| 34 ASSERT(globalTcpListeningSocketRegistry == NULL); | 34 ASSERT(globalTcpListeningSocketRegistry == NULL); |
| 35 globalTcpListeningSocketRegistry = new ListeningSocketRegistry(); | 35 globalTcpListeningSocketRegistry = new ListeningSocketRegistry(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 ListeningSocketRegistry* ListeningSocketRegistry::Instance() { | 39 ListeningSocketRegistry* ListeningSocketRegistry::Instance() { |
| 40 return globalTcpListeningSocketRegistry; | 40 return globalTcpListeningSocketRegistry; |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 // the file descriptor. | 141 // the file descriptor. |
| 142 os_socket->ref_count++; | 142 os_socket->ref_count++; |
| 143 | 143 |
| 144 // The same Socket is used by a second Dart _NativeSocket object. | 144 // The same Socket is used by a second Dart _NativeSocket object. |
| 145 // It Retains a reference. | 145 // It Retains a reference. |
| 146 os_socket->socketfd->Retain(); | 146 os_socket->socketfd->Retain(); |
| 147 // We set as a side-effect the file descriptor on the dart | 147 // We set as a side-effect the file descriptor on the dart |
| 148 // socket_object. | 148 // socket_object. |
| 149 Socket::ReuseSocketIdNativeField(socket_object, os_socket->socketfd, | 149 Socket::ReuseSocketIdNativeField(socket_object, os_socket->socketfd, |
| 150 true); | 150 true); |
| 151 | |
| 152 return Dart_True(); | 151 return Dart_True(); |
| 153 } | 152 } |
| 154 } | 153 } |
| 155 } | 154 } |
| 156 | 155 |
| 157 // There is no socket listening on that (address, port), so we create new one. | 156 // There is no socket listening on that (address, port), so we create new one. |
| 158 intptr_t fd = ServerSocket::CreateBindListen(addr, backlog, v6_only); | 157 intptr_t fd = ServerSocket::CreateBindListen(addr, backlog, v6_only); |
| 159 if (fd == -5) { | 158 if (fd == -5) { |
| 160 OSError os_error(-1, "Invalid host", OSError::kUnknown); | 159 OSError os_error(-1, "Invalid host", OSError::kUnknown); |
| 161 return DartUtils::NewDartOSError(&os_error); | 160 return DartUtils::NewDartOSError(&os_error); |
| 162 } | 161 } |
| 163 if (fd < 0) { | 162 if (fd < 0) { |
| 164 OSError error; | 163 OSError error; |
| 165 return DartUtils::NewDartOSError(&error); | 164 return DartUtils::NewDartOSError(&error); |
| 166 } | 165 } |
| 167 if (!ServerSocket::StartAccept(fd)) { | 166 if (!ServerSocket::StartAccept(fd)) { |
| 168 OSError os_error(-1, "Failed to start accept", OSError::kUnknown); | 167 OSError os_error(-1, "Failed to start accept", OSError::kUnknown); |
| 169 return DartUtils::NewDartOSError(&os_error); | 168 return DartUtils::NewDartOSError(&os_error); |
| 170 } | 169 } |
| 171 intptr_t allocated_port = Socket::GetPort(fd); | 170 intptr_t allocated_port = BaseSocket::GetPort(fd); |
| 172 ASSERT(allocated_port > 0); | 171 ASSERT(allocated_port > 0); |
| 173 | 172 |
| 174 if (allocated_port != port) { | 173 if (allocated_port != port) { |
| 175 // There are two cases to consider: | 174 // There are two cases to consider: |
| 176 // | 175 // |
| 177 // a) The user requested (address, port) where port != 0 which means | 176 // a) The user requested (address, port) where port != 0 which means |
| 178 // we re-use an existing socket if available (and it is shared) or we | 177 // we re-use an existing socket if available (and it is shared) or we |
| 179 // create a new one. The new socket is guaranteed to have that | 178 // create a new one. The new socket is guaranteed to have that |
| 180 // selected port. | 179 // selected port. |
| 181 // | 180 // |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 return CloseOneSafe(os_socket, true); | 260 return CloseOneSafe(os_socket, true); |
| 262 } else { | 261 } else { |
| 263 // A finalizer may direct the event handler to close a listening socket | 262 // A finalizer may direct the event handler to close a listening socket |
| 264 // that it has never seen before. In this case, we return true to direct | 263 // that it has never seen before. In this case, we return true to direct |
| 265 // the eventhandler to clean up the socket. | 264 // the eventhandler to clean up the socket. |
| 266 return true; | 265 return true; |
| 267 } | 266 } |
| 268 } | 267 } |
| 269 | 268 |
| 270 | 269 |
| 271 void FUNCTION_NAME(InternetAddress_Parse)(Dart_NativeArguments args) { | |
| 272 const char* address = | |
| 273 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); | |
| 274 ASSERT(address != NULL); | |
| 275 RawAddr raw; | |
| 276 memset(&raw, 0, sizeof(raw)); | |
| 277 int type = strchr(address, ':') == NULL ? SocketAddress::TYPE_IPV4 | |
| 278 : SocketAddress::TYPE_IPV6; | |
| 279 if (type == SocketAddress::TYPE_IPV4) { | |
| 280 raw.addr.sa_family = AF_INET; | |
| 281 } else { | |
| 282 raw.addr.sa_family = AF_INET6; | |
| 283 } | |
| 284 bool ok = Socket::ParseAddress(type, address, &raw); | |
| 285 if (!ok) { | |
| 286 Dart_SetReturnValue(args, Dart_Null()); | |
| 287 } else { | |
| 288 Dart_SetReturnValue(args, SocketAddress::ToTypedData(raw)); | |
| 289 } | |
| 290 } | |
| 291 | |
| 292 | |
| 293 void FUNCTION_NAME(NetworkInterface_ListSupported)(Dart_NativeArguments args) { | |
| 294 Dart_SetReturnValue(args, Dart_NewBoolean(Socket::ListInterfacesSupported())); | |
| 295 } | |
| 296 | |
| 297 | |
| 298 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { | 270 void FUNCTION_NAME(Socket_CreateConnect)(Dart_NativeArguments args) { |
| 299 RawAddr addr; | 271 RawAddr addr; |
| 300 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); | 272 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); |
| 301 Dart_Handle port_arg = Dart_GetNativeArgument(args, 2); | 273 Dart_Handle port_arg = Dart_GetNativeArgument(args, 2); |
| 302 int64_t port = DartUtils::GetInt64ValueCheckRange(port_arg, 0, 65535); | 274 int64_t port = DartUtils::GetInt64ValueCheckRange(port_arg, 0, 65535); |
| 303 SocketAddress::SetAddrPort(&addr, static_cast<intptr_t>(port)); | 275 SocketAddress::SetAddrPort(&addr, static_cast<intptr_t>(port)); |
| 304 intptr_t socket = Socket::CreateConnect(addr); | 276 intptr_t socket = Socket::CreateConnect(addr); |
| 305 OSError error; | 277 OSError error; |
| 306 if (socket >= 0) { | 278 if (socket >= 0) { |
| 307 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, | 279 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 325 OSError error; | 297 OSError error; |
| 326 if (socket >= 0) { | 298 if (socket >= 0) { |
| 327 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, | 299 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, |
| 328 false); | 300 false); |
| 329 Dart_SetReturnValue(args, Dart_True()); | 301 Dart_SetReturnValue(args, Dart_True()); |
| 330 } else { | 302 } else { |
| 331 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); | 303 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
| 332 } | 304 } |
| 333 } | 305 } |
| 334 | 306 |
| 335 void FUNCTION_NAME(Socket_IsBindError)(Dart_NativeArguments args) { | |
| 336 intptr_t error_number = | |
| 337 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); | |
| 338 bool is_bind_error = Socket::IsBindError(error_number); | |
| 339 Dart_SetReturnValue(args, is_bind_error ? Dart_True() : Dart_False()); | |
| 340 } | |
| 341 | 307 |
| 342 void FUNCTION_NAME(Socket_CreateBindDatagram)(Dart_NativeArguments args) { | 308 void FUNCTION_NAME(Socket_CreateBindDatagram)(Dart_NativeArguments args) { |
| 343 RawAddr addr; | 309 RawAddr addr; |
| 344 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); | 310 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); |
| 345 Dart_Handle port_arg = Dart_GetNativeArgument(args, 2); | 311 Dart_Handle port_arg = Dart_GetNativeArgument(args, 2); |
| 346 int64_t port = DartUtils::GetInt64ValueCheckRange(port_arg, 0, 65535); | 312 int64_t port = DartUtils::GetInt64ValueCheckRange(port_arg, 0, 65535); |
| 347 SocketAddress::SetAddrPort(&addr, port); | 313 SocketAddress::SetAddrPort(&addr, port); |
| 348 bool reuse_addr = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3)); | 314 bool reuse_addr = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3)); |
| 349 intptr_t socket = Socket::CreateBindDatagram(addr, reuse_addr); | 315 intptr_t socket = Socket::CreateBindDatagram(addr, reuse_addr); |
| 350 if (socket >= 0) { | 316 if (socket >= 0) { |
| 351 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, | 317 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, |
| 352 false); | 318 false); |
| 353 Dart_SetReturnValue(args, Dart_True()); | 319 Dart_SetReturnValue(args, Dart_True()); |
| 354 } else { | 320 } else { |
| 355 OSError error; | 321 OSError error; |
| 356 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); | 322 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
| 357 } | 323 } |
| 358 } | 324 } |
| 359 | 325 |
| 360 | 326 |
| 361 void FUNCTION_NAME(Socket_Available)(Dart_NativeArguments args) { | 327 void FUNCTION_NAME(Socket_Available)(Dart_NativeArguments args) { |
| 362 Socket* socket = | 328 Socket* socket = |
| 363 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 329 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 364 intptr_t available = Socket::Available(socket->fd()); | 330 intptr_t available = BaseSocket::Available(socket->fd()); |
| 365 if (available >= 0) { | 331 if (available >= 0) { |
| 366 Dart_SetReturnValue(args, Dart_NewInteger(available)); | 332 Dart_SetReturnValue(args, Dart_NewInteger(available)); |
| 367 } else { | 333 } else { |
| 368 // Available failed. Mark socket as having data, to trigger a future read | 334 // Available failed. Mark socket as having data, to trigger a future read |
| 369 // event where the actual error can be reported. | 335 // event where the actual error can be reported. |
| 370 Dart_SetReturnValue(args, Dart_NewInteger(1)); | 336 Dart_SetReturnValue(args, Dart_NewInteger(1)); |
| 371 } | 337 } |
| 372 } | 338 } |
| 373 | 339 |
| 374 | 340 |
| 375 void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) { | 341 void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) { |
| 376 Socket* socket = | 342 Socket* socket = |
| 377 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 343 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 378 int64_t length = 0; | 344 int64_t length = 0; |
| 379 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { | 345 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &length)) { |
| 380 if (short_socket_read) { | 346 if (short_socket_read) { |
| 381 length = (length + 1) / 2; | 347 length = (length + 1) / 2; |
| 382 } | 348 } |
| 383 uint8_t* buffer = NULL; | 349 uint8_t* buffer = NULL; |
| 384 Dart_Handle result = IOBuffer::Allocate(length, &buffer); | 350 Dart_Handle result = IOBuffer::Allocate(length, &buffer); |
| 385 if (Dart_IsError(result)) { | 351 if (Dart_IsError(result)) { |
| 386 Dart_PropagateError(result); | 352 Dart_PropagateError(result); |
| 387 } | 353 } |
| 388 ASSERT(buffer != NULL); | 354 ASSERT(buffer != NULL); |
| 389 intptr_t bytes_read = Socket::Read(socket->fd(), buffer, length); | 355 intptr_t bytes_read = BaseSocket::Read(socket->fd(), buffer, length); |
| 390 if (bytes_read == length) { | 356 if (bytes_read == length) { |
| 391 Dart_SetReturnValue(args, result); | 357 Dart_SetReturnValue(args, result); |
| 392 } else if (bytes_read > 0) { | 358 } else if (bytes_read > 0) { |
| 393 uint8_t* new_buffer = NULL; | 359 uint8_t* new_buffer = NULL; |
| 394 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); | 360 Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer); |
| 395 if (Dart_IsError(new_result)) { | 361 if (Dart_IsError(new_result)) { |
| 396 Dart_PropagateError(new_result); | 362 Dart_PropagateError(new_result); |
| 397 } | 363 } |
| 398 ASSERT(new_buffer != NULL); | 364 ASSERT(new_buffer != NULL); |
| 399 memmove(new_buffer, buffer, bytes_read); | 365 memmove(new_buffer, buffer, bytes_read); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 419 | 385 |
| 420 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can | 386 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can |
| 421 // handle 64k datagrams. | 387 // handle 64k datagrams. |
| 422 IsolateData* isolate_data = | 388 IsolateData* isolate_data = |
| 423 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 389 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
| 424 if (isolate_data->udp_receive_buffer == NULL) { | 390 if (isolate_data->udp_receive_buffer == NULL) { |
| 425 isolate_data->udp_receive_buffer = | 391 isolate_data->udp_receive_buffer = |
| 426 reinterpret_cast<uint8_t*>(malloc(65536)); | 392 reinterpret_cast<uint8_t*>(malloc(65536)); |
| 427 } | 393 } |
| 428 RawAddr addr; | 394 RawAddr addr; |
| 429 intptr_t bytes_read = Socket::RecvFrom( | 395 intptr_t bytes_read = BaseSocket::RecvFrom( |
| 430 socket->fd(), isolate_data->udp_receive_buffer, 65536, &addr); | 396 socket->fd(), isolate_data->udp_receive_buffer, 65536, &addr); |
| 431 if (bytes_read == 0) { | 397 if (bytes_read == 0) { |
| 432 Dart_SetReturnValue(args, Dart_Null()); | 398 Dart_SetReturnValue(args, Dart_Null()); |
| 433 return; | 399 return; |
| 434 } | 400 } |
| 435 if (bytes_read < 0) { | 401 if (bytes_read < 0) { |
| 436 ASSERT(bytes_read == -1); | 402 ASSERT(bytes_read == -1); |
| 437 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 403 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 438 return; | 404 return; |
| 439 } | 405 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 450 // Get the port and clear it in the sockaddr structure. | 416 // Get the port and clear it in the sockaddr structure. |
| 451 int port = SocketAddress::GetAddrPort(addr); | 417 int port = SocketAddress::GetAddrPort(addr); |
| 452 if (addr.addr.sa_family == AF_INET) { | 418 if (addr.addr.sa_family == AF_INET) { |
| 453 addr.in.sin_port = 0; | 419 addr.in.sin_port = 0; |
| 454 } else { | 420 } else { |
| 455 ASSERT(addr.addr.sa_family == AF_INET6); | 421 ASSERT(addr.addr.sa_family == AF_INET6); |
| 456 addr.in6.sin6_port = 0; | 422 addr.in6.sin6_port = 0; |
| 457 } | 423 } |
| 458 // Format the address to a string using the numeric format. | 424 // Format the address to a string using the numeric format. |
| 459 char numeric_address[INET6_ADDRSTRLEN]; | 425 char numeric_address[INET6_ADDRSTRLEN]; |
| 460 Socket::FormatNumericAddress(addr, numeric_address, INET6_ADDRSTRLEN); | 426 BaseSocket::FormatNumericAddress(addr, numeric_address, INET6_ADDRSTRLEN); |
| 461 | 427 |
| 462 // Create a Datagram object with the data and sender address and port. | 428 // Create a Datagram object with the data and sender address and port. |
| 463 const int kNumArgs = 4; | 429 const int kNumArgs = 4; |
| 464 Dart_Handle dart_args[kNumArgs]; | 430 Dart_Handle dart_args[kNumArgs]; |
| 465 dart_args[0] = data; | 431 dart_args[0] = data; |
| 466 dart_args[1] = Dart_NewStringFromCString(numeric_address); | 432 dart_args[1] = Dart_NewStringFromCString(numeric_address); |
| 467 if (Dart_IsError(dart_args[1])) { | 433 if (Dart_IsError(dart_args[1])) { |
| 468 Dart_PropagateError(dart_args[1]); | 434 Dart_PropagateError(dart_args[1]); |
| 469 } | 435 } |
| 470 dart_args[2] = SocketAddress::ToTypedData(addr); | 436 dart_args[2] = SocketAddress::ToTypedData(addr); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 500 Dart_TypedData_Type type; | 466 Dart_TypedData_Type type; |
| 501 uint8_t* buffer = NULL; | 467 uint8_t* buffer = NULL; |
| 502 intptr_t len; | 468 intptr_t len; |
| 503 Dart_Handle result = Dart_TypedDataAcquireData( | 469 Dart_Handle result = Dart_TypedDataAcquireData( |
| 504 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); | 470 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); |
| 505 if (Dart_IsError(result)) { | 471 if (Dart_IsError(result)) { |
| 506 Dart_PropagateError(result); | 472 Dart_PropagateError(result); |
| 507 } | 473 } |
| 508 ASSERT((offset + length) <= len); | 474 ASSERT((offset + length) <= len); |
| 509 buffer += offset; | 475 buffer += offset; |
| 510 intptr_t bytes_written = Socket::Write(socket->fd(), buffer, length); | 476 intptr_t bytes_written = BaseSocket::Write(socket->fd(), buffer, length); |
| 511 if (bytes_written >= 0) { | 477 if (bytes_written >= 0) { |
| 512 Dart_TypedDataReleaseData(buffer_obj); | 478 Dart_TypedDataReleaseData(buffer_obj); |
| 513 if (short_write) { | 479 if (short_write) { |
| 514 // If the write was forced 'short', indicate by returning the negative | 480 // If the write was forced 'short', indicate by returning the negative |
| 515 // number of bytes. A forced short write may not trigger a write event. | 481 // number of bytes. A forced short write may not trigger a write event. |
| 516 Dart_SetReturnValue(args, Dart_NewInteger(-bytes_written)); | 482 Dart_SetReturnValue(args, Dart_NewInteger(-bytes_written)); |
| 517 } else { | 483 } else { |
| 518 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 484 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 519 } | 485 } |
| 520 } else { | 486 } else { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 542 Dart_TypedData_Type type; | 508 Dart_TypedData_Type type; |
| 543 uint8_t* buffer = NULL; | 509 uint8_t* buffer = NULL; |
| 544 intptr_t len; | 510 intptr_t len; |
| 545 Dart_Handle result = Dart_TypedDataAcquireData( | 511 Dart_Handle result = Dart_TypedDataAcquireData( |
| 546 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); | 512 buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len); |
| 547 if (Dart_IsError(result)) { | 513 if (Dart_IsError(result)) { |
| 548 Dart_PropagateError(result); | 514 Dart_PropagateError(result); |
| 549 } | 515 } |
| 550 ASSERT((offset + length) <= len); | 516 ASSERT((offset + length) <= len); |
| 551 buffer += offset; | 517 buffer += offset; |
| 552 intptr_t bytes_written = Socket::SendTo(socket->fd(), buffer, length, addr); | 518 intptr_t bytes_written = |
| 519 BaseSocket::SendTo(socket->fd(), buffer, length, addr); | |
| 553 if (bytes_written >= 0) { | 520 if (bytes_written >= 0) { |
| 554 Dart_TypedDataReleaseData(buffer_obj); | 521 Dart_TypedDataReleaseData(buffer_obj); |
| 555 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 522 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
| 556 } else { | 523 } else { |
| 557 // Extract OSError before we release data, as it may override the error. | 524 // Extract OSError before we release data, as it may override the error. |
| 558 OSError os_error; | 525 OSError os_error; |
| 559 Dart_TypedDataReleaseData(buffer_obj); | 526 Dart_TypedDataReleaseData(buffer_obj); |
| 560 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 527 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
| 561 } | 528 } |
| 562 } | 529 } |
| 563 | 530 |
| 564 | 531 |
| 565 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { | 532 void FUNCTION_NAME(Socket_GetPort)(Dart_NativeArguments args) { |
| 566 Socket* socket = | 533 Socket* socket = |
| 567 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 534 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 568 OSError os_error; | 535 OSError os_error; |
| 569 intptr_t port = Socket::GetPort(socket->fd()); | 536 intptr_t port = BaseSocket::GetPort(socket->fd()); |
| 570 if (port > 0) { | 537 if (port > 0) { |
| 571 Dart_SetReturnValue(args, Dart_NewInteger(port)); | 538 Dart_SetReturnValue(args, Dart_NewInteger(port)); |
| 572 } else { | 539 } else { |
| 573 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 540 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 574 } | 541 } |
| 575 } | 542 } |
| 576 | 543 |
| 577 | 544 |
| 578 void FUNCTION_NAME(Socket_GetRemotePeer)(Dart_NativeArguments args) { | 545 void FUNCTION_NAME(Socket_GetRemotePeer)(Dart_NativeArguments args) { |
| 579 Socket* socket = | 546 Socket* socket = |
| 580 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 547 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 581 OSError os_error; | 548 OSError os_error; |
| 582 intptr_t port = 0; | 549 intptr_t port = 0; |
| 583 SocketAddress* addr = Socket::GetRemotePeer(socket->fd(), &port); | 550 SocketAddress* addr = BaseSocket::GetRemotePeer(socket->fd(), &port); |
| 584 if (addr != NULL) { | 551 if (addr != NULL) { |
| 585 Dart_Handle list = Dart_NewList(2); | 552 Dart_Handle list = Dart_NewList(2); |
| 586 | 553 |
| 587 Dart_Handle entry = Dart_NewList(3); | 554 Dart_Handle entry = Dart_NewList(3); |
| 588 Dart_ListSetAt(entry, 0, Dart_NewInteger(addr->GetType())); | 555 Dart_ListSetAt(entry, 0, Dart_NewInteger(addr->GetType())); |
| 589 Dart_ListSetAt(entry, 1, Dart_NewStringFromCString(addr->as_string())); | 556 Dart_ListSetAt(entry, 1, Dart_NewStringFromCString(addr->as_string())); |
| 590 | 557 |
| 591 RawAddr raw = addr->addr(); | 558 RawAddr raw = addr->addr(); |
| 592 Dart_ListSetAt(entry, 2, SocketAddress::ToTypedData(raw)); | 559 Dart_ListSetAt(entry, 2, SocketAddress::ToTypedData(raw)); |
| 593 | 560 |
| 594 Dart_ListSetAt(list, 0, entry); | 561 Dart_ListSetAt(list, 0, entry); |
| 595 Dart_ListSetAt(list, 1, Dart_NewInteger(port)); | 562 Dart_ListSetAt(list, 1, Dart_NewInteger(port)); |
| 596 Dart_SetReturnValue(args, list); | 563 Dart_SetReturnValue(args, list); |
| 597 delete addr; | 564 delete addr; |
| 598 } else { | 565 } else { |
| 599 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 566 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 600 } | 567 } |
| 601 } | 568 } |
| 602 | 569 |
| 603 | 570 |
| 604 void FUNCTION_NAME(Socket_GetError)(Dart_NativeArguments args) { | 571 void FUNCTION_NAME(Socket_GetError)(Dart_NativeArguments args) { |
| 605 Socket* socket = | 572 Socket* socket = |
| 606 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 573 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 607 OSError os_error; | 574 OSError os_error; |
| 608 Socket::GetError(socket->fd(), &os_error); | 575 BaseSocket::GetError(socket->fd(), &os_error); |
| 609 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 576 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
| 610 } | 577 } |
| 611 | 578 |
| 612 | 579 |
| 613 void FUNCTION_NAME(Socket_GetType)(Dart_NativeArguments args) { | 580 void FUNCTION_NAME(Socket_GetType)(Dart_NativeArguments args) { |
| 614 Socket* socket = | 581 Socket* socket = |
| 615 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 582 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 616 OSError os_error; | 583 OSError os_error; |
| 617 intptr_t type = Socket::GetType(socket->fd()); | 584 intptr_t type = BaseSocket::GetType(socket->fd()); |
| 618 if (type >= 0) { | 585 if (type >= 0) { |
| 619 Dart_SetReturnValue(args, Dart_NewInteger(type)); | 586 Dart_SetReturnValue(args, Dart_NewInteger(type)); |
| 620 } else { | 587 } else { |
| 621 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 588 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 622 } | 589 } |
| 623 } | 590 } |
| 624 | 591 |
| 625 | 592 |
| 626 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) { | 593 void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) { |
| 627 int64_t num = | 594 int64_t num = |
| 628 DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 1), 0, 2); | 595 DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 1), 0, 2); |
| 629 intptr_t socket = Socket::GetStdioHandle(num); | 596 intptr_t socket = BaseSocket::GetStdioHandle(num); |
| 630 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, | 597 Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), socket, |
| 631 false); | 598 false); |
| 632 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); | 599 Dart_SetReturnValue(args, Dart_NewBoolean(socket >= 0)); |
| 633 } | 600 } |
| 634 | 601 |
| 635 | 602 |
| 636 void FUNCTION_NAME(Socket_GetSocketId)(Dart_NativeArguments args) { | 603 void FUNCTION_NAME(Socket_GetSocketId)(Dart_NativeArguments args) { |
| 637 Socket* socket = | 604 Socket* socket = |
| 638 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 605 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 639 intptr_t id = reinterpret_cast<intptr_t>(socket); | 606 intptr_t id = reinterpret_cast<intptr_t>(socket); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 | 649 |
| 683 | 650 |
| 684 CObject* Socket::LookupRequest(const CObjectArray& request) { | 651 CObject* Socket::LookupRequest(const CObjectArray& request) { |
| 685 if ((request.Length() == 2) && request[0]->IsString() && | 652 if ((request.Length() == 2) && request[0]->IsString() && |
| 686 request[1]->IsInt32()) { | 653 request[1]->IsInt32()) { |
| 687 CObjectString host(request[0]); | 654 CObjectString host(request[0]); |
| 688 CObjectInt32 type(request[1]); | 655 CObjectInt32 type(request[1]); |
| 689 CObject* result = NULL; | 656 CObject* result = NULL; |
| 690 OSError* os_error = NULL; | 657 OSError* os_error = NULL; |
| 691 AddressList<SocketAddress>* addresses = | 658 AddressList<SocketAddress>* addresses = |
| 692 Socket::LookupAddress(host.CString(), type.Value(), &os_error); | 659 BaseSocket::LookupAddress(host.CString(), type.Value(), &os_error); |
| 693 if (addresses != NULL) { | 660 if (addresses != NULL) { |
| 694 CObjectArray* array = | 661 CObjectArray* array = |
| 695 new CObjectArray(CObject::NewArray(addresses->count() + 1)); | 662 new CObjectArray(CObject::NewArray(addresses->count() + 1)); |
| 696 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); | 663 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); |
| 697 for (intptr_t i = 0; i < addresses->count(); i++) { | 664 for (intptr_t i = 0; i < addresses->count(); i++) { |
| 698 SocketAddress* addr = addresses->GetAt(i); | 665 SocketAddress* addr = addresses->GetAt(i); |
| 699 CObjectArray* entry = new CObjectArray(CObject::NewArray(3)); | 666 CObjectArray* entry = new CObjectArray(CObject::NewArray(3)); |
| 700 | 667 |
| 701 CObjectInt32* type = | 668 CObjectInt32* type = |
| 702 new CObjectInt32(CObject::NewInt32(addr->GetType())); | 669 new CObjectInt32(CObject::NewInt32(addr->GetType())); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 } else { | 704 } else { |
| 738 ASSERT(len == sizeof(in6_addr)); | 705 ASSERT(len == sizeof(in6_addr)); |
| 739 addr.in6.sin6_family = AF_INET6; | 706 addr.in6.sin6_family = AF_INET6; |
| 740 memmove(reinterpret_cast<void*>(&addr.in6.sin6_addr), | 707 memmove(reinterpret_cast<void*>(&addr.in6.sin6_addr), |
| 741 addr_object.Buffer(), len); | 708 addr_object.Buffer(), len); |
| 742 } | 709 } |
| 743 | 710 |
| 744 OSError* os_error = NULL; | 711 OSError* os_error = NULL; |
| 745 const intptr_t kMaxHostLength = 1025; | 712 const intptr_t kMaxHostLength = 1025; |
| 746 char host[kMaxHostLength]; | 713 char host[kMaxHostLength]; |
| 747 if (Socket::ReverseLookup(addr, host, kMaxHostLength, &os_error)) { | 714 if (BaseSocket::ReverseLookup(addr, host, kMaxHostLength, &os_error)) { |
| 748 return new CObjectString(CObject::NewString(host)); | 715 return new CObjectString(CObject::NewString(host)); |
| 749 } else { | 716 } else { |
| 750 CObject* result = CObject::NewOSError(os_error); | 717 CObject* result = CObject::NewOSError(os_error); |
| 751 delete os_error; | 718 delete os_error; |
| 752 return result; | 719 return result; |
| 753 } | 720 } |
| 754 } | 721 } |
| 755 return CObject::IllegalArgumentError(); | 722 return CObject::IllegalArgumentError(); |
| 756 } | 723 } |
| 757 | 724 |
| 758 | 725 |
| 759 CObject* Socket::ListInterfacesRequest(const CObjectArray& request) { | 726 CObject* Socket::ListInterfacesRequest(const CObjectArray& request) { |
| 760 if ((request.Length() == 1) && request[0]->IsInt32()) { | 727 if ((request.Length() == 1) && request[0]->IsInt32()) { |
| 761 CObjectInt32 type(request[0]); | 728 CObjectInt32 type(request[0]); |
| 762 CObject* result = NULL; | 729 CObject* result = NULL; |
| 763 OSError* os_error = NULL; | 730 OSError* os_error = NULL; |
| 764 AddressList<InterfaceSocketAddress>* addresses = | 731 AddressList<InterfaceSocketAddress>* addresses = |
| 765 Socket::ListInterfaces(type.Value(), &os_error); | 732 BaseSocket::ListInterfaces(type.Value(), &os_error); |
| 766 if (addresses != NULL) { | 733 if (addresses != NULL) { |
| 767 CObjectArray* array = | 734 CObjectArray* array = |
| 768 new CObjectArray(CObject::NewArray(addresses->count() + 1)); | 735 new CObjectArray(CObject::NewArray(addresses->count() + 1)); |
| 769 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); | 736 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0))); |
| 770 for (intptr_t i = 0; i < addresses->count(); i++) { | 737 for (intptr_t i = 0; i < addresses->count(); i++) { |
| 771 InterfaceSocketAddress* interface = addresses->GetAt(i); | 738 InterfaceSocketAddress* interface = addresses->GetAt(i); |
| 772 SocketAddress* addr = interface->socket_address(); | 739 SocketAddress* addr = interface->socket_address(); |
| 773 CObjectArray* entry = new CObjectArray(CObject::NewArray(5)); | 740 CObjectArray* entry = new CObjectArray(CObject::NewArray(5)); |
| 774 | 741 |
| 775 CObjectInt32* type = | 742 CObjectInt32* type = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 void FUNCTION_NAME(Socket_GetOption)(Dart_NativeArguments args) { | 776 void FUNCTION_NAME(Socket_GetOption)(Dart_NativeArguments args) { |
| 810 Socket* socket = | 777 Socket* socket = |
| 811 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 778 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 812 int64_t option = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 779 int64_t option = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 813 intptr_t protocol = static_cast<intptr_t>( | 780 intptr_t protocol = static_cast<intptr_t>( |
| 814 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2))); | 781 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2))); |
| 815 bool ok = false; | 782 bool ok = false; |
| 816 switch (option) { | 783 switch (option) { |
| 817 case 0: { // TCP_NODELAY. | 784 case 0: { // TCP_NODELAY. |
| 818 bool enabled; | 785 bool enabled; |
| 819 ok = Socket::GetNoDelay(socket->fd(), &enabled); | 786 ok = BaseSocket::GetNoDelay(socket->fd(), &enabled); |
| 820 if (ok) { | 787 if (ok) { |
| 821 Dart_SetReturnValue(args, enabled ? Dart_True() : Dart_False()); | 788 Dart_SetReturnValue(args, enabled ? Dart_True() : Dart_False()); |
| 822 } | 789 } |
| 823 break; | 790 break; |
| 824 } | 791 } |
| 825 case 1: { // IP_MULTICAST_LOOP. | 792 case 1: { // IP_MULTICAST_LOOP. |
| 826 bool enabled; | 793 bool enabled; |
| 827 ok = Socket::GetMulticastLoop(socket->fd(), protocol, &enabled); | 794 ok = BaseSocket::GetMulticastLoop(socket->fd(), protocol, &enabled); |
| 828 if (ok) { | 795 if (ok) { |
| 829 Dart_SetReturnValue(args, enabled ? Dart_True() : Dart_False()); | 796 Dart_SetReturnValue(args, enabled ? Dart_True() : Dart_False()); |
| 830 } | 797 } |
| 831 break; | 798 break; |
| 832 } | 799 } |
| 833 case 2: { // IP_MULTICAST_TTL. | 800 case 2: { // IP_MULTICAST_TTL. |
| 834 int value; | 801 int value; |
| 835 ok = Socket::GetMulticastHops(socket->fd(), protocol, &value); | 802 ok = BaseSocket::GetMulticastHops(socket->fd(), protocol, &value); |
| 836 if (ok) { | 803 if (ok) { |
| 837 Dart_SetReturnValue(args, Dart_NewInteger(value)); | 804 Dart_SetReturnValue(args, Dart_NewInteger(value)); |
| 838 } | 805 } |
| 839 break; | 806 break; |
| 840 } | 807 } |
| 841 case 3: { // IP_MULTICAST_IF. | 808 case 3: { // IP_MULTICAST_IF. |
| 842 UNIMPLEMENTED(); | 809 UNIMPLEMENTED(); |
| 843 break; | 810 break; |
| 844 } | 811 } |
| 845 case 4: { // IP_BROADCAST. | 812 case 4: { // IP_BROADCAST. |
| 846 bool enabled; | 813 bool enabled; |
| 847 ok = Socket::GetBroadcast(socket->fd(), &enabled); | 814 ok = BaseSocket::GetBroadcast(socket->fd(), &enabled); |
| 848 if (ok) { | 815 if (ok) { |
| 849 Dart_SetReturnValue(args, enabled ? Dart_True() : Dart_False()); | 816 Dart_SetReturnValue(args, enabled ? Dart_True() : Dart_False()); |
| 850 } | 817 } |
| 851 break; | 818 break; |
| 852 } | 819 } |
| 853 default: | 820 default: |
| 854 UNREACHABLE(); | 821 UNREACHABLE(); |
| 855 break; | 822 break; |
| 856 } | 823 } |
| 857 // In case of failure the return value is not set above. | 824 // In case of failure the return value is not set above. |
| 858 if (!ok) { | 825 if (!ok) { |
| 859 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 826 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 860 } | 827 } |
| 861 } | 828 } |
| 862 | 829 |
| 863 | 830 |
| 864 void FUNCTION_NAME(Socket_SetOption)(Dart_NativeArguments args) { | 831 void FUNCTION_NAME(Socket_SetOption)(Dart_NativeArguments args) { |
| 865 bool result = false; | 832 bool result = false; |
| 866 Socket* socket = | 833 Socket* socket = |
| 867 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 834 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 868 int64_t option = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 835 int64_t option = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); |
| 869 int64_t protocol = DartUtils::GetInt64ValueCheckRange( | 836 int64_t protocol = DartUtils::GetInt64ValueCheckRange( |
| 870 Dart_GetNativeArgument(args, 2), SocketAddress::TYPE_IPV4, | 837 Dart_GetNativeArgument(args, 2), SocketAddress::TYPE_IPV4, |
| 871 SocketAddress::TYPE_IPV6); | 838 SocketAddress::TYPE_IPV6); |
| 872 switch (option) { | 839 switch (option) { |
| 873 case 0: // TCP_NODELAY. | 840 case 0: // TCP_NODELAY. |
| 874 result = Socket::SetNoDelay( | 841 result = BaseSocket::SetNoDelay( |
| 875 socket->fd(), | 842 socket->fd(), |
| 876 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3))); | 843 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3))); |
| 877 break; | 844 break; |
| 878 case 1: // IP_MULTICAST_LOOP. | 845 case 1: // IP_MULTICAST_LOOP. |
| 879 result = Socket::SetMulticastLoop( | 846 result = BaseSocket::SetMulticastLoop( |
| 880 socket->fd(), protocol, | 847 socket->fd(), protocol, |
| 881 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3))); | 848 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3))); |
| 882 break; | 849 break; |
| 883 case 2: // IP_MULTICAST_TTL. | 850 case 2: // IP_MULTICAST_TTL. |
| 884 result = Socket::SetMulticastHops( | 851 result = BaseSocket::SetMulticastHops( |
| 885 socket->fd(), protocol, | 852 socket->fd(), protocol, |
| 886 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3))); | 853 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3))); |
| 887 break; | 854 break; |
| 888 case 3: { // IP_MULTICAST_IF. | 855 case 3: { // IP_MULTICAST_IF. |
| 889 UNIMPLEMENTED(); | 856 UNIMPLEMENTED(); |
| 890 break; | 857 break; |
| 891 } | 858 } |
| 892 case 4: // IP_BROADCAST. | 859 case 4: // IP_BROADCAST. |
| 893 result = Socket::SetBroadcast( | 860 result = BaseSocket::SetBroadcast( |
| 894 socket->fd(), | 861 socket->fd(), |
| 895 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3))); | 862 DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 3))); |
| 896 break; | 863 break; |
| 897 default: | 864 default: |
| 898 Dart_PropagateError(Dart_NewApiError("Value outside expected range")); | 865 Dart_PropagateError(Dart_NewApiError("Value outside expected range")); |
| 899 break; | 866 break; |
| 900 } | 867 } |
| 901 if (result) { | 868 if (result) { |
| 902 Dart_SetReturnValue(args, Dart_Null()); | 869 Dart_SetReturnValue(args, Dart_Null()); |
| 903 } else { | 870 } else { |
| 904 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 871 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 905 } | 872 } |
| 906 } | 873 } |
| 907 | 874 |
| 908 | 875 |
| 909 void FUNCTION_NAME(Socket_JoinMulticast)(Dart_NativeArguments args) { | 876 void FUNCTION_NAME(Socket_JoinMulticast)(Dart_NativeArguments args) { |
| 910 Socket* socket = | 877 Socket* socket = |
| 911 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 878 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 912 RawAddr addr; | 879 RawAddr addr; |
| 913 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); | 880 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); |
| 914 RawAddr interface; | 881 RawAddr interface; |
| 915 if (Dart_GetNativeArgument(args, 2) != Dart_Null()) { | 882 if (Dart_GetNativeArgument(args, 2) != Dart_Null()) { |
| 916 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 2), &interface); | 883 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 2), &interface); |
| 917 } | 884 } |
| 918 int interfaceIndex = | 885 int interfaceIndex = |
| 919 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 886 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 920 if (Socket::JoinMulticast(socket->fd(), addr, interface, interfaceIndex)) { | 887 if (BaseSocket::JoinMulticast(socket->fd(), addr, interface, |
| 888 interfaceIndex)) { | |
| 921 Dart_SetReturnValue(args, Dart_Null()); | 889 Dart_SetReturnValue(args, Dart_Null()); |
| 922 } else { | 890 } else { |
| 923 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 891 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 924 } | 892 } |
| 925 } | 893 } |
| 926 | 894 |
| 927 | 895 |
| 928 void FUNCTION_NAME(Socket_LeaveMulticast)(Dart_NativeArguments args) { | 896 void FUNCTION_NAME(Socket_LeaveMulticast)(Dart_NativeArguments args) { |
| 929 Socket* socket = | 897 Socket* socket = |
| 930 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); | 898 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); |
| 931 RawAddr addr; | 899 RawAddr addr; |
| 932 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); | 900 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 1), &addr); |
| 933 RawAddr interface; | 901 RawAddr interface; |
| 934 if (Dart_GetNativeArgument(args, 2) != Dart_Null()) { | 902 if (Dart_GetNativeArgument(args, 2) != Dart_Null()) { |
| 935 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 2), &interface); | 903 SocketAddress::GetSockAddr(Dart_GetNativeArgument(args, 2), &interface); |
| 936 } | 904 } |
| 937 int interfaceIndex = | 905 int interfaceIndex = |
| 938 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 906 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 939 if (Socket::LeaveMulticast(socket->fd(), addr, interface, interfaceIndex)) { | 907 if (BaseSocket::LeaveMulticast(socket->fd(), addr, interface, |
| 908 interfaceIndex)) { | |
| 940 Dart_SetReturnValue(args, Dart_Null()); | 909 Dart_SetReturnValue(args, Dart_Null()); |
| 941 } else { | 910 } else { |
| 942 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 911 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
| 943 } | 912 } |
| 944 } | 913 } |
| 945 | 914 |
| 946 | 915 |
| 947 static void SocketFinalizer(void* isolate_data, | 916 static void SocketFinalizer(void* isolate_data, |
| 948 Dart_WeakPersistentHandle handle, | 917 Dart_WeakPersistentHandle handle, |
| 949 void* data) { | 918 void* data) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 Dart_PropagateError(err); | 975 Dart_PropagateError(err); |
| 1007 } | 976 } |
| 1008 Socket* socket = reinterpret_cast<Socket*>(id); | 977 Socket* socket = reinterpret_cast<Socket*>(id); |
| 1009 return socket; | 978 return socket; |
| 1010 } | 979 } |
| 1011 | 980 |
| 1012 } // namespace bin | 981 } // namespace bin |
| 1013 } // namespace dart | 982 } // namespace dart |
| 1014 | 983 |
| 1015 #endif // !defined(DART_IO_DISABLED) | 984 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |