Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PosixSignalRegistration.cs
Go to the documentation of this file.
2using System.IO;
4
6
8{
9 private sealed class Token
10 {
11 public PosixSignal Signal { get; }
12
14
16 {
17 Signal = signal;
18 Handler = handler;
19 }
20 }
21
22 private Token _token;
23
24 private static readonly HashSet<Token> s_registrations = new HashSet<Token>();
25
26 [UnsupportedOSPlatform("android")]
27 [UnsupportedOSPlatform("browser")]
29 [UnsupportedOSPlatform("tvos")]
31 {
32 if (handler == null)
33 {
34 throw new ArgumentNullException("handler");
35 }
36 return Register(signal, handler);
37 }
38
40 {
41 _token = token;
42 }
43
44 public void Dispose()
45 {
46 Unregister();
47 GC.SuppressFinalize(this);
48 }
49
54
56 {
57 if ((uint)(signal - -4) > 3u)
58 {
60 }
61 Token token = new Token(signal, handler);
64 {
66 {
68 }
69 s_registrations.Add(token);
70 return result;
71 }
72 }
73
74 private unsafe void Unregister()
75 {
77 {
78 Token token = _token;
79 if (token != null)
80 {
81 _token = null;
82 s_registrations.Remove(token);
84 {
86 }
87 }
88 }
89 }
90
93 {
95 switch (dwCtrlType)
96 {
97 case 0:
98 posixSignal = PosixSignal.SIGINT;
99 break;
100 case 1:
101 posixSignal = PosixSignal.SIGQUIT;
102 break;
103 case 6:
104 posixSignal = PosixSignal.SIGTERM;
105 break;
106 case 2:
107 posixSignal = PosixSignal.SIGHUP;
108 break;
109 default:
110 return Interop.BOOL.FALSE;
111 }
112 List<Token> list = null;
114 {
116 {
117 if (s_registration.Signal == posixSignal)
118 {
119 (list ?? (list = new List<Token>())).Add(s_registration);
120 }
121 }
122 }
123 if (list == null)
124 {
125 return Interop.BOOL.FALSE;
126 }
128 foreach (Token item in list)
129 {
130 item.Handler(posixSignalContext);
131 }
132 if (!posixSignalContext.Cancel)
133 {
134 return Interop.BOOL.FALSE;
135 }
136 return Interop.BOOL.TRUE;
137 }
138}
static unsafe bool SetConsoleCtrlHandler(delegate *unmanaged< int, BOOL > HandlerRoutine, bool Add)
void Add(TKey key, TValue value)
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static Exception GetExceptionForLastWin32Error(string path="")
Token(PosixSignal signal, Action< PosixSignalContext > handler)
static unsafe PosixSignalRegistration Register(PosixSignal signal, Action< PosixSignalContext > handler)
static PosixSignalRegistration Create(PosixSignal signal, Action< PosixSignalContext > handler)