File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed
Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 1212namespace OTDIPC
1313{
1414 [ PluginName ( "OpenKneeboard (OTD-IPC)" ) ]
15- public class OTDIPC : IPositionedPipelineElement < IDeviceReport > , IDriver
15+ public sealed class OTDIPC : IPositionedPipelineElement < IDeviceReport > , IDriver , IDisposable
1616 {
1717 State _state = new ( ) ;
1818 private DeviceInfo ? _deviceInfo ;
@@ -46,6 +46,14 @@ public OTDIPC()
4646 }
4747 }
4848
49+ public void Dispose ( )
50+ {
51+ foreach ( var server in _servers )
52+ {
53+ server . Dispose ( ) ;
54+ }
55+ }
56+
4957 public void Consume ( IDeviceReport deviceReport )
5058 {
5159 if ( ! _servers . Any ( s => s . HaveClient ) )
Original file line number Diff line number Diff line change 1111
1212namespace OTDIPC ;
1313
14- public abstract class ServerBase : IDisposable , IServer
14+ public abstract class ServerBase : IServer
1515{
1616 protected readonly IDriver _driver ;
1717 protected Timer ? _timer ;
@@ -31,6 +31,7 @@ protected ServerBase(IDriver driver)
3131
3232 public virtual void Dispose ( )
3333 {
34+ GC . SuppressFinalize ( this ) ;
3435 _timer ? . Dispose ( ) ;
3536 _driver . TabletChanged -= Driver_TabletChanged ;
3637 _driver . StateChanged -= Driver_StateChanged ;
Original file line number Diff line number Diff line change @@ -115,7 +115,17 @@ protected override async void RunServerAsync()
115115 _connection = pipe ;
116116
117117 Log . Write ( "otd-ipc" , "Waiting for connection" ) ;
118- await pipe . WaitForConnectionAsync ( ) ;
118+ try
119+ {
120+ await pipe . WaitForConnectionAsync ( ) ;
121+ }
122+ catch ( IOException e )
123+ {
124+ _waitingForConnection = false ;
125+ Log . Write ( "otd-ipc" , "Waiting for connection failed: " + e . Message ) ;
126+ return ;
127+ }
128+
119129 Log . Write ( "otd-ipc" , "Client connected" ) ;
120130 _waitingForConnection = false ;
121131 _connected = true ;
@@ -129,6 +139,15 @@ void OnClientConnected()
129139 this . SendMessage ( _deviceInfo ) ;
130140 }
131141
142+ public override void Dispose ( )
143+ {
144+ var conn = Interlocked . Exchange ( ref _connection , null ) ;
145+ conn ? . Dispose ( ) ;
146+
147+ base . Dispose ( ) ;
148+ Log . Write ( "otd-ipc" , "V1 server disposed" ) ;
149+ }
150+
132151 protected override void Ping ( )
133152 {
134153 if ( _waitingForConnection )
You can’t perform that action at this time.
0 commit comments