Skip to content

Commit 067385a

Browse files
XmlRpc*: Deprecate destructors used on things that implement IDisposable (Dispose function of superclass calls children's Close())
1 parent d992188 commit 067385a

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

ROS_Comm/XmlRpcManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ public CachedXmlRpcClient(string host, int port, string uri)
456456
private CachedXmlRpcClient(XmlRpcClient c)
457457
{
458458
client = c;
459+
client.Disposed += () =>
460+
{
461+
client = null;
462+
};
459463
}
460464

461465
/// <summary>

XmlRpc_Wrapper/XmlRpcClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace XmlRpc_Wrapper
2828
[DebuggerStepThrough]
2929
#endif
3030

31-
public class XmlRpcClient : XmlRpcSource //: IDisposable
31+
public class XmlRpcClient : XmlRpcSource
3232
{
3333
// Static data
3434
private static string REQUEST_BEGIN = "<?xml version=\"1.0\"?>\r\n<methodCall><methodName>";
@@ -60,6 +60,8 @@ public class XmlRpcClient : XmlRpcSource //: IDisposable
6060
private string _uri;
6161
private HTTPHeader header;
6262
private TcpClient socket;
63+
public delegate void DisposedEvent();
64+
public event DisposedEvent Disposed;
6365

6466
public XmlRpcClient(string HostName, int Port, string Uri)
6567
{
@@ -289,6 +291,9 @@ private int getPort()
289291
public override void Close()
290292
{
291293
XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcClient::Close()");
294+
close();
295+
if (Disposed != null)
296+
Disposed();
292297
}
293298

294299
public override Socket getSocket()
@@ -326,7 +331,7 @@ public void close()
326331
{
327332
XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcClient::close.");
328333
_connectionState = ConnectionState.NO_CONNECTION;
329-
334+
_disp.RemoveSource(this);
330335
_disp.Exit();
331336
//_disp.removeSource(this);
332337
//XmlRpcSource::close();

XmlRpc_Wrapper/XmlRpcServerConnection.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ public override NetworkStream getStream()
6060
return stream;
6161
}
6262

63-
64-
~XmlRpcServerConnection()
65-
{
66-
XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcServerConnection dtor.");
67-
server.removeConnection(this);
68-
}
69-
7063
// Handle input on the server socket by accepting the connection
7164
// and reading the rpc request. Return true to continue to monitor
7265
// the socket for events, false to remove it from the dispatcher.
@@ -108,6 +101,7 @@ public override void Close()
108101
socket.Close(100);
109102
socket = null;
110103
}
104+
server.removeConnection(this);
111105
}
112106

113107
private bool readRequest()

0 commit comments

Comments
 (0)