From 63fe242f593f9e35fd9c22cbe2b13ffea2e432bd Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 1 Oct 2008 18:59:01 -0400 Subject: [PATCH] Remove the cookie from VxBufferStream. It was only around because C# 1.0-style delegates were so crappy. --- versaplexd/versaplexd.cs | 16 ++++------------ versaplexd/vxbufferstream.cs | 19 +++++-------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/versaplexd/versaplexd.cs b/versaplexd/versaplexd.cs index 15458a1..4af75b4 100644 --- a/versaplexd/versaplexd.cs +++ b/versaplexd/versaplexd.cs @@ -19,15 +19,11 @@ public static class VersaMain public static Connection conn; - private static void DataReady(object sender, object cookie) + private static void DataReady(VxBufferStream vxbs, Connection conn) { // FIXME: This may require special handling for padding between // messages: it hasn't been a problem so far, but should be addressed - VxBufferStream vxbs = (VxBufferStream)sender; - - Connection conn = (Connection)cookie; - if (vxbs.BufferPending == 0) { log.print("??? DataReady but nothing to read\n"); return; @@ -40,16 +36,13 @@ public static class VersaMain wv.printerr("Now need: {0}\n", vxbs.BufferAmount); } - private static void NoMoreData(object sender, object cookie) + private static void NoMoreData(VxBufferStream vxbs) { log.print( "***********************************************************\n"+ "************ D-bus connection closed by server ************\n"+ "***********************************************************\n"); - - VxBufferStream vxbs = (VxBufferStream)sender; vxbs.Close(); - VxEventLoop.Shutdown(); } @@ -201,9 +194,8 @@ public static class VersaMain VxBufferStream vxbs = new VxBufferStream(trans.Socket); trans.stream = vxbs; - vxbs.Cookie = conn; - vxbs.DataReady += DataReady; - vxbs.NoMoreData += NoMoreData; + vxbs.DataReady = () => { DataReady(vxbs, conn); }; + vxbs.NoMoreData = () => { NoMoreData(vxbs); }; vxbs.BufferAmount = 16; oldhandler = conn.OnMessage; diff --git a/versaplexd/vxbufferstream.cs b/versaplexd/vxbufferstream.cs index d4c8f3b..db7c56c 100644 --- a/versaplexd/vxbufferstream.cs +++ b/versaplexd/vxbufferstream.cs @@ -30,15 +30,8 @@ public class VxBufferStream : Stream set { throw new NotSupportedException(); } } - private object cookie = null; - public object Cookie { - get { return cookie; } - set { cookie = value; } - } - - public delegate void DataReadyHandler(object sender, object cookie); - public event DataReadyHandler DataReady; - public event DataReadyHandler NoMoreData; + public Action DataReady; + public Action NoMoreData; protected VxNotifySocket sock; @@ -75,7 +68,7 @@ public class VxBufferStream : Stream if (rbuf.Size > 0) { VxEventLoop.AddAction(new VxEvent( delegate() { - DataReady(this, cookie); + DataReady(); })); } } else { @@ -107,8 +100,6 @@ public class VxBufferStream : Stream sock.Close(); sock = null; } - - cookie = null; } closed = true; @@ -253,11 +244,11 @@ public class VxBufferStream : Stream } if (rbuf.Size >= rbuf_size) { - DataReady(this, cookie); + DataReady(); } if (eof) { - NoMoreData(this, cookie); + NoMoreData(); } // Don't use ReadWaiting to change this since the return value will -- 2.11.4.GIT