7
7
use Amp \ForbidSerialization ;
8
8
use Amp \Socket ;
9
9
use Amp \Socket \ResourceSocket ;
10
+ use Revolt \EventLoop ;
10
11
use const Amp \Process \IS_WINDOWS ;
11
12
12
13
final class LocalIpcHub implements IpcHub
@@ -40,6 +41,12 @@ public function __construct(
40
41
$ this ->delegate = new SocketIpcHub (Socket \listen ($ address ), $ keyReceiveTimeout , $ keyLength );
41
42
}
42
43
44
+ public function __destruct ()
45
+ {
46
+ EventLoop::queue ($ this ->delegate ->close (...));
47
+ $ this ->unlink ();
48
+ }
49
+
43
50
public function accept (string $ key , ?Cancellation $ cancellation = null ): ResourceSocket
44
51
{
45
52
return $ this ->delegate ->accept ($ key , $ cancellation );
@@ -53,22 +60,30 @@ public function isClosed(): bool
53
60
public function close (): void
54
61
{
55
62
$ this ->delegate ->close ();
56
- if ($ this ->toUnlink !== null ) {
57
- // Ignore errors when unlinking temp socket.
58
- \set_error_handler (static fn () => true );
59
- try {
60
- \unlink ($ this ->toUnlink );
61
- } finally {
62
- \restore_error_handler ();
63
- }
64
- }
63
+ $ this ->unlink ();
65
64
}
66
65
67
66
public function onClose (\Closure $ onClose ): void
68
67
{
69
68
$ this ->delegate ->onClose ($ onClose );
70
69
}
71
70
71
+ private function unlink (): void
72
+ {
73
+ if ($ this ->toUnlink === null ) {
74
+ return ;
75
+ }
76
+
77
+ // Ignore errors when unlinking temp socket.
78
+ \set_error_handler (static fn () => true );
79
+ try {
80
+ \unlink ($ this ->toUnlink );
81
+ } finally {
82
+ \restore_error_handler ();
83
+ $ this ->toUnlink = null ;
84
+ }
85
+ }
86
+
72
87
public function getUri (): string
73
88
{
74
89
return $ this ->delegate ->getUri ();
0 commit comments