[svn] commit: r37 - in /experiments/graff-ccapi: msgq/msgq.c ruby/lib/cc.rb ruby/lib/cc/message.rb ruby/lib/cc/session.rb

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Sep 25 23:52:30 UTC 2009


Author: mgraff
Date: Fri Sep 25 23:52:30 2009
New Revision: 37

Log:
checkpoint; something is not working...  no messages are flowing

Modified:
    experiments/graff-ccapi/msgq/msgq.c
    experiments/graff-ccapi/ruby/lib/cc.rb
    experiments/graff-ccapi/ruby/lib/cc/message.rb
    experiments/graff-ccapi/ruby/lib/cc/session.rb

Modified: experiments/graff-ccapi/msgq/msgq.c
==============================================================================
--- experiments/graff-ccapi/msgq/msgq.c (original)
+++ experiments/graff-ccapi/msgq/msgq.c Fri Sep 25 23:52:30 2009
@@ -444,7 +444,7 @@
 	instance = cc_findtag(c, "instance", 8);
 	to = cc_findtag(c, "to", 2);
 
-	if (group == NULL || instance == NULL) {
+	if (group == NULL || instance == NULL || to == NULL) {
 		con_log(con, LOG_NOTICE,
 			"Bad send message, missing required args");
 		return;
@@ -456,12 +456,12 @@
 		return;
 	}
 
-	if (to && to->type != ITEM_DATA) {
+	if (to->type != ITEM_DATA) {
 		con_log(con, LOG_NOTICE, "Bad send, incorrect data types");
 		return;
 	}
 
-	con_log(con, LOG_DEBUG, "recv group %.*s instance %.*s to %.*s",
+	con_log(con, LOG_NOTICE, "recv group=%.*s instance=%.*s to=%.*s",
 		group->dlen, group->data,
 		instance->dlen, instance->data,
 		to->dlen, to->data);
@@ -505,7 +505,9 @@
 					continue;
 				con_enqueue(slcon, mb);
 				sendcnt++;
+				printf("To is NULL\n");
 			} else {
+				printf("To is %.*s\n", tlen, to);
 				if (slcon->lnamelen == tlen
 				    && slcon->lhash == lhash
 				    && memcmp(slcon->lname, to, tlen) == 0) {
@@ -517,6 +519,8 @@
 		sl = ISC_LIST_NEXT(sl, link);
 	}
 
+	printf("Sent message to %d destinations\n", sendcnt);
+
 	return (sendcnt);
 }
 
@@ -538,12 +542,21 @@
 		tlen = 0;
 	}
 
-	sub = sub_find(group, glen, instance, ilen, NULL, NULL);
-	if (sub != NULL)
-		send_messages(sub, con, mb, to, tlen);
-
-	if (ilen == 0)
-		return;
+	/*
+	 * First, send it to those specifically listening on this instance
+	 */
+	if (ilen > 0) {
+		printf("SENDING instance specific messages\n");
+		sub = sub_find(group, glen, instance, ilen, NULL, NULL);
+		if (sub != NULL)
+			send_messages(sub, con, mb, to, tlen);
+	}
+
+
+	/*
+	 * And now to wildcard subscribers
+	 */
+	printf("SENDING instance * messages\n");
 	sub = sub_find(group, glen, NULL, 0, NULL, NULL);
 	if (sub != NULL)
 		send_messages(sub, con, mb, to, tlen);
@@ -648,7 +661,9 @@
 {
 	msgq_t *mq;
 
-	con_log(con, LOG_DEBUG, "sending mb %p (refcnt %d)", mb, mb->ref);
+	con_log(con, LOG_NOTICE, "sending mb %p (refcnt %d)", mb, mb->ref);
+
+	hexdump(mb->r.base, mb->r.length);
 
 	if (con->out_pending + mb->r.length > SEND_MAXBUF) {
 		con_log(con, LOG_DEBUG,

Modified: experiments/graff-ccapi/ruby/lib/cc.rb
==============================================================================
--- experiments/graff-ccapi/ruby/lib/cc.rb (original)
+++ experiments/graff-ccapi/ruby/lib/cc.rb Fri Sep 25 23:52:30 2009
@@ -46,7 +46,20 @@
 if $0 == __FILE__
   cc = CC::Session.new
 
-  cc.sendmsg({ :type => :getlname })
+  puts "Our local name: #{cc.lname}"
 
-  puts "Our local name: #{cc.lname}"
+  cc.sendmsg({ :type => "subscribe",
+               :group => "test", :instance => "foo",
+               :subtype => "normal",
+             })
+  cc.sendmsg({ :type => "send",
+               :from => cc.lname,
+               :to => "*",
+               :group => "test",
+               :instance => "foo",
+               :seq => "1",
+               :data => { :one => :two },
+             })
+  puts cc.recvmsg.inspect
+  sleep 10
 end

Modified: experiments/graff-ccapi/ruby/lib/cc/message.rb
==============================================================================
--- experiments/graff-ccapi/ruby/lib/cc/message.rb (original)
+++ experiments/graff-ccapi/ruby/lib/cc/message.rb Fri Sep 25 23:52:30 2009
@@ -18,21 +18,6 @@
 end
 
 class CC
-  def self.set_utf8(str) #nodoc
-    if str.respond_to?('force_encoding')
-      str.force_encoding(Encoding::UTF_8)
-    end
-  end
-
-  def self.set_binary(str) #nodoc
-    if str.respond_to?('force_encoding')
-      str.force_encoding(Encoding::BINARY)
-    end
-  end
-end
-
-
-class CC
 class Message
   PROTOCOL_VERSION = 0x536b616e
 

Modified: experiments/graff-ccapi/ruby/lib/cc/session.rb
==============================================================================
--- experiments/graff-ccapi/ruby/lib/cc/session.rb (original)
+++ experiments/graff-ccapi/ruby/lib/cc/session.rb Fri Sep 25 23:52:30 2009
@@ -16,7 +16,7 @@
 require 'socket'
 
 class CC
-class SendError < Exception ; end
+class ProtocolError < Exception ; end
 end
 
 class CC
@@ -29,11 +29,11 @@
   # :port => port to connect to (defaults to 9913)
   #
   def initialize(args = {})
-    @socket = nil
-    @lname = nil
-    @recvbuffer = nil
-    @recvlength = nil
-    @sendbuffer = ""
+    @socket = nil      # TCP socket.
+    @lname = nil       # local name, or nil if not connected.
+    @recvbuffer = ""   # data buffer for partial reads.
+    @recvlength = nil  # if non-nil, we have a length to fill buffer to.
+    @sendbuffer = ""   # pending output data.
 
     options = {
       :host => "127.0.0.1",
@@ -84,22 +84,60 @@
   # Send as much data as we can.  
   def send_pending
     return false if @sendbuffer.length == 0
+    puts "Sending #{@sendbuffer.length} bytes"
     sent = @socket.send(@sendbuffer, 0)
     @sendbuffer = @sendbuffer[sent .. -1]
+    puts "Send left #{@sendbuffer.length} bytes"
     @sendbuffer.length == 0 ? true : false
   end
 
   def recvmsg
-    msg = receive_full_buffer
-    CC::Message::from_wire(msg)
+    data = receive_full_buffer
+    if data
+      CC::Message::from_wire(data)
+    else
+      nil
+    end
   end
 
   private
 
+  #
+  # A rather tricky function.  If we have something waiting in our buffer,
+  # and it will satisfy the current request, we will read it all in.  If
+  # not, we will read only what we need to satisfy a single message.
+  #
   def receive_full_buffer
-    lenbytes = @socket.recv(4)
-    length = lenbytes.unpack("N")
-    data = @socket.recv(length[0])
+    # read the length prefix if we need it still.
+    if @recvlength.nil?
+      puts "receiving length bytes"
+      length = 4
+      length -= @recvbuffer.length
+      data = @socket.recv(length)
+      return nil if data == 0
+      @recvbuffer += data
+      return nil if @recvbuffer.length < 4
+      @recvlength = @recvbuffer.unpack('N')[0]
+      @recvbuffer = ""
+      CC::set_binary(@recvbuffer)
+    end
+
+    #
+    # we have a length target.  Loop reading data until we get enough to
+    # fill our buffer.
+    #
+    length = @recvlength - @recvbuffer.length
+    while (length > 0) do
+      puts "receiving #{length} of #{@recvlength} bytes"
+      data = @socket.recv(length)
+      return nil if data == 0 # blocking I/O
+      @recvbuffer += data
+      length -= data.length
+    end
+
+    data = @recvbuffer
+    @recvbuffer = ""
+    @recvlength = nil
     data
   end
 




More information about the bind10-changes mailing list