-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm/sendports] Introduce an api that can be safely used to rebuild Se…
…ndPort. Existing api is not aware of origin_id, which leads to problems when a port gets closed, origin_id can't be properly restored. Fixes #55605 TEST=vm/dart/sendport_api_test Change-Id: Ia8a5978a968f6ea643d7921c64146cebf17d2e0e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365120 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Aprelev <aam@google.com>
- Loading branch information
Showing
6 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:isolate'; | ||
import 'dart:ffi'; | ||
|
||
import 'package:async_helper/async_helper.dart' show asyncEnd, asyncStart; | ||
import 'package:expect/expect.dart'; | ||
import 'package:ffi/ffi.dart'; | ||
|
||
@Native<Handle Function(Int64 port)>(symbol: 'Dart_NewSendPort') | ||
external SendPort newSendPort(int obj); | ||
|
||
@Native<Handle Function(Handle, Pointer<Int64>)>(symbol: 'Dart_SendPortGetId') | ||
external Object sendPortGetId(Object sendPort, Pointer<Int64> outId); | ||
|
||
final class PortEx extends Struct { | ||
@Int64() | ||
external int portId; | ||
@Int64() | ||
external int originId; | ||
} | ||
|
||
@Native<Handle Function(PortEx portex)>(symbol: 'Dart_NewSendPortEx') | ||
external SendPort newSendPortEx(PortEx portEx); | ||
|
||
@Native<Handle Function(Handle, Pointer<PortEx>)>( | ||
symbol: 'Dart_SendPortGetIdEx') | ||
external Object sendPortGetIdEx(Object sendPort, Pointer<PortEx> outPortExId); | ||
|
||
class A {} | ||
|
||
main() async { | ||
asyncStart(); | ||
|
||
final rp = ReceivePort(); | ||
rp.close(); | ||
|
||
{ | ||
Pointer<Int64> portId = calloc(); | ||
sendPortGetId(rp.sendPort, portId); | ||
final sendPortThroughAPI = newSendPort(portId.value); | ||
sendPortThroughAPI.send('A'); | ||
Expect.throwsArgumentError(() { | ||
sendPortThroughAPI.send(A()); | ||
}); | ||
calloc.free(portId); | ||
} | ||
|
||
{ | ||
Pointer<PortEx> portExId = calloc(); | ||
sendPortGetIdEx(rp.sendPort, portExId); | ||
final sendPortThroughAPI = newSendPortEx(portExId[0]); | ||
sendPortThroughAPI.send('A'); | ||
sendPortThroughAPI.send(A()); | ||
calloc.free(portExId); | ||
} | ||
|
||
asyncEnd(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters