beagle r4716 - trunk/beagle/beagled/NetworkServicesQueryable
- From: dbera svn gnome org
- To: svn-commits-list gnome org
- Subject: beagle r4716 - trunk/beagle/beagled/NetworkServicesQueryable
- Date: Fri, 18 Apr 2008 17:47:23 +0100 (BST)
Author: dbera
Date: Fri Apr 18 16:47:23 2008
New Revision: 4716
URL: http://svn.gnome.org/viewvc/beagle?rev=4716&view=rev
Log:
* HttpTransport.cs: Fix a bug in SendAsyncBlocking (check 0xff for end-of-message byte). Add an ENABLE_XML_DUMP debug block to HttpTransport.
* NetworkServicesQueryable.cs: Redo the querying remote beagled part using SendAsyncBlocking; the earlier way was at best hackish and led to all sorts of deadlocks.
Modified:
trunk/beagle/beagled/NetworkServicesQueryable/HttpTransport.cs
trunk/beagle/beagled/NetworkServicesQueryable/NetworkServicesQueryable.cs
Modified: trunk/beagle/beagled/NetworkServicesQueryable/HttpTransport.cs
==============================================================================
--- trunk/beagle/beagled/NetworkServicesQueryable/HttpTransport.cs (original)
+++ trunk/beagle/beagled/NetworkServicesQueryable/HttpTransport.cs Fri Apr 18 16:47:23 2008
@@ -104,7 +104,13 @@
} while (bytes_read > 0 && end_index == -1);
this.BufferStream.Seek (0, SeekOrigin.Begin);
-
+
+#if ENABLE_XML_DUMP
+ StreamReader dump_reader = new StreamReader (this.BufferStream);
+ Logger.Log.Debug ("Received response:\n{0}\n", dump_reader.ReadToEnd ());
+ this.BufferStream.Seek (0, SeekOrigin.Begin);
+#endif
+
ResponseMessage resp = null;
try {
@@ -263,7 +269,7 @@
break;
int end_index;
- end_index = ArrayFu.IndexOfByte (buffer, (byte) 0x00);
+ end_index = ArrayFu.IndexOfByte (buffer, (byte) 0xff);
if (end_index == -1) {
deserialize_stream.Write (buffer, 0, bytes_read);
@@ -271,6 +277,11 @@
deserialize_stream.Write (buffer, 0, end_index);
deserialize_stream.Seek (0, SeekOrigin.Begin);
+#if ENABLE_XML_DUMP
+ StreamReader r = new StreamReader (deserialize_stream);
+ Logger.Log.Debug ("Received response:\n{0}\n", r.ReadToEnd ());
+ deserialize_stream.Seek (0, SeekOrigin.Begin);
+#endif
ResponseMessage resp;
try {
ResponseWrapper wrapper;
@@ -291,4 +302,4 @@
}
}
}
-}
\ No newline at end of file
+}
Modified: trunk/beagle/beagled/NetworkServicesQueryable/NetworkServicesQueryable.cs
==============================================================================
--- trunk/beagle/beagled/NetworkServicesQueryable/NetworkServicesQueryable.cs (original)
+++ trunk/beagle/beagled/NetworkServicesQueryable/NetworkServicesQueryable.cs Fri Apr 18 16:47:23 2008
@@ -43,75 +43,40 @@
query.RegisterTransport (new HttpTransport (service [1]));
}
- // - Turn an async operation (query.SendAsync)
- // - to a sync operation (result.Add need to be called from this thread)
- // - to an async operation (result.Add sends an async response to the client)
-
- // To prevent FinishedResponse being sent before HitsAddedResponse
- Queue<ResponseMessage> response_queue = new Queue<ResponseMessage> (2);
-
// Anonymous delegates cannot be un-registered ... hence
Query.HitsAdded hits_added_handler;
hits_added_handler = delegate (HitsAddedResponse response) {
- lock (response_queue) {
- response_queue.Enqueue (response);
- Monitor.Pulse (response_queue);
- }
+ //Console.WriteLine ("Adding hits added response");
+ result.Add (response.Hits, response.NumMatches);
};
Query.HitsSubtracted hits_subtracted_handler;
hits_subtracted_handler = delegate (HitsSubtractedResponse response) {
- lock (response_queue) {
- response_queue.Enqueue (response);
- Monitor.Pulse (response_queue);
- }
+ // Console.WriteLine ("Adding hits subtracted response");
+ result.Subtract (response.Uris);
};
Query.Finished finished_handler;
finished_handler = delegate (FinishedResponse response) {
- lock (response_queue) {
- response_queue.Enqueue (response);
- Monitor.Pulse (response_queue);
- }
+ //Console.WriteLine ("Adding finished response");
+ // NO-OP
};
+ // FIXME: ClosedEvent ? Should be handled by HttpTransport but should we do something more
+
query.HitsAddedEvent += hits_added_handler;
query.HitsSubtractedEvent += hits_subtracted_handler;
query.FinishedEvent += finished_handler;
- // FIXME: Need a closed event handler ? In case the remote server is closed ?
- //query.ClosedEvent += delegate () { };
- bool done = false;
Exception throw_me = null;
try {
- query.SendAsync ();
+ query.SendAsyncBlocking ();
} catch (Exception ex) {
throw_me = ex;
- done = true;
}
- while (! done) {
- lock (response_queue) {
- Monitor.Wait (response_queue);
- while (response_queue.Count != 0) {
- //Console.WriteLine ("Time to handle response ({0})", response_queue.Count);
- ResponseMessage query_response = response_queue.Dequeue ();
- if (query_response is FinishedResponse) {
- //Console.WriteLine ("FinishedResponse. Do nothing");
- done = true;
- } else if (query_response is HitsAddedResponse) {
- HitsAddedResponse response = (HitsAddedResponse) query_response;
- //Console.WriteLine ("HitsAddedResponse. Adding {0} hits", response.NumMatches);
- result.Add (response.Hits, response.NumMatches);
- } else if (query_response is HitsSubtractedResponse) {
- HitsSubtractedResponse response = (HitsSubtractedResponse) query_response;
- //Console.WriteLine ("HitsAddedResponse. Removing {0} hits", response.Uris.Count);
- result.Subtract (response.Uris);
- }
- }
- }
- }
+ // FIXME FIXME FIXME: Live query does not work!
query.HitsAddedEvent -= hits_added_handler;
query.HitsSubtractedEvent -= hits_subtracted_handler;
@@ -120,8 +85,6 @@
if (throw_me != null)
throw throw_me;
- // FIXME FIXME FIXME: Live query does not work!
-
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]