]> xenbits.xensource.com Git - xenclient/toolstack.git/commitdiff
Fixed eventloop.listen, flush debugging output.
authorPrashanth Mundkur <prashanth.mundkur@citrix.com>
Fri, 5 Jun 2009 01:24:09 +0000 (18:24 -0700)
committerPrashanth Mundkur <prashanth.mundkur@citrix.com>
Tue, 23 Jun 2009 16:25:41 +0000 (09:25 -0700)
libs/stdext/eventloop.ml

index 33d98cd140317095ab3147b5a02512b3be32dd56..ec2a3d9e59e380a5491675aaf1d559dd5beb6543 100644 (file)
  * GNU Lesser General Public License for more details.
  *)
 
-let verbose = ref true
+let verbose = ref false
 
 let dbg fmt =
-       let logger s = if !verbose then Printf.printf "%s\n" s in
+       let logger s = if !verbose then Printf.printf "%s\n%!" s in
        Printf.ksprintf logger fmt
 
 module ConnMap = Map.Make (struct type t = Unix.file_descr let compare = compare end)
@@ -148,6 +148,13 @@ let create () =
        excepts = Unixext.Fdset.create ();
 }
 
+let num_connections t =
+       let cnt = ref 0 in
+       ConnMap.iter (fun _ _ -> incr cnt) t.conns;
+       !cnt
+
+let num_timers t = Timers.num_timers t.timers
+
 (* connections *)
 
 let register_conn t fd ?(enable_send_done=false) ?(enable_recv=true) callbacks =
@@ -187,6 +194,7 @@ let connect t handle addr =
 
 let listen t handle =
        let conn_state = ConnMap.find handle t.conns in
+       Unix.listen handle 5;
        Unixext.Fdset.set t.readers handle;
        conn_state.recv_enabled <- true;
        conn_state.status <- Listening
@@ -270,8 +278,10 @@ let dispatch_read t fd cs =
                                let read_bytes = Unix.read fd buf 0 buflen in
                                if read_bytes = 0 then
                                        cs.callbacks.shutdown_callback t fd
-                               else
+                               else begin
+                                       debug "<- %s" (String.sub buf 0 read_bytes);
                                        cs.callbacks.recv_callback t fd buf 0 read_bytes
+                               end
                        with
                        | Unix.Unix_error (Unix.EWOULDBLOCK, _, _)
                        | Unix.Unix_error (Unix.EAGAIN, _, _)
@@ -288,6 +298,7 @@ let do_send t fd cs =
                (match Unix.write fd payload 0 payload_len with
                 | 0 -> ()
                 | sent ->
+                       debug "-> %s" (String.sub payload 0 sent);
                        Buffer.clear cs.send_buf;
                        Buffer.add_substring cs.send_buf payload sent (payload_len - sent)
                )
@@ -371,10 +382,3 @@ let dispatch t interval =
        );
 
        dispatch_timers t ctime
-
-let num_connections t =
-       let cnt = ref 0 in
-       ConnMap.iter (fun _ _ -> incr cnt) t.conns;
-       !cnt
-
-let num_timers t = Timers.num_timers t.timers