* 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)
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 =
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
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, _, _)
(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)
)
);
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