Index: src/utils/net/tcpBufferedSocket.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/net/tcpBufferedSocket.ml,v
retrieving revision 1.43
diff -u -r1.43 tcpBufferedSocket.ml
--- src/utils/net/tcpBufferedSocket.ml	3 Apr 2006 20:50:09 -0000	1.43
+++ src/utils/net/tcpBufferedSocket.ml	25 Oct 2006 22:31:29 -0000
@@ -804,12 +804,9 @@
     | Some bc ->
         if bc.total_bytes = 0 then
           can_write_handler t sock t.wbuf.len
-        else  begin
-(*                lprintf "DELAYED\n";  *)
-            if bc.remaining_bytes > 0 then begin
-                bc.connections <- t :: bc.connections;
-                bc.nconnections <- t.write_power + bc.nconnections
-              end
+        else begin
+            bc.connections <- t :: bc.connections;
+            bc.nconnections <- t.write_power + bc.nconnections
           end
   end
 
@@ -1749,7 +1746,7 @@
                         t.name (sock_num t.sock_out) (remaining_to_write t)
                     end
               ) bc.connections;
-(*          if bc.remaining_bytes > 0 then bc.allow_io := false; *)
+(*            if bc.remaining_bytes > 0 then bc.allow_io := false; *)
             end;
           if !verbose_bandwidth > 2 then begin
 
Index: src/utils/net/tcpBufferedSocket.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/net/tcpBufferedSocket.mli,v
retrieving revision 1.15
diff -u -r1.15 tcpBufferedSocket.mli
--- src/utils/net/tcpBufferedSocket.mli	28 Jun 2005 22:45:57 -0000	1.15
+++ src/utils/net/tcpBufferedSocket.mli	25 Oct 2006 22:31:29 -0000
@@ -79,6 +79,9 @@
 val set_max_output_buffer : t -> int -> unit  
 val can_write : t -> bool  
 val can_write_len : t -> int -> bool  
+val register_download : t -> int -> unit
+val register_upload : t -> int -> unit
+val register_bytes : bandwidth_controler option -> int -> unit
   
 val set_monitored : t -> bool -> unit
 val monitored : t -> bool
Index: src/utils/net/tcpClientSocket.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/net/tcpClientSocket.ml,v
retrieving revision 1.12
diff -u -r1.12 tcpClientSocket.ml
--- src/utils/net/tcpClientSocket.ml	6 Dec 2005 20:26:40 -0000	1.12
+++ src/utils/net/tcpClientSocket.ml	25 Oct 2006 22:31:29 -0000
@@ -527,7 +527,7 @@
   set_allow_write t.sock bc.allow_io;
   bandwidth_controler t t.sock
   
-let max_buffer_size = ref 1000000
+let max_buffer_size = ref 10000000
 
 let dump_socket t buf = 
   print_socket buf t.sock;
Index: src/utils/net/udpSocket.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/net/udpSocket.ml,v
retrieving revision 1.20
diff -u -r1.20 udpSocket.ml
--- src/utils/net/udpSocket.ml	14 Dec 2005 21:17:47 -0000	1.20
+++ src/utils/net/udpSocket.ml	25 Oct 2006 22:31:29 -0000
@@ -23,6 +23,14 @@
 open AnyEndian
 open LittleEndian
 
+let log_prefix = "[udpSock]"
+
+let lprintf_nl fmt =
+  lprintf_nl2 log_prefix fmt
+
+let lprintf_n fmt =
+  lprintf2 log_prefix fmt
+
 type event = 
   WRITE_DONE
 | CAN_REFILL
@@ -131,6 +139,7 @@
     mutable allow_io : bool ref;
     mutable count : int;
     mutable base_time : int;
+    mutable tcp_bc : TcpBufferedSocket.bandwidth_controler;
   }
   
 and handler = t -> event -> unit
@@ -190,10 +199,10 @@
         lprintf_nl "ADDR_UNIX (%s)" s;
   end
 
-let max_delayed_send = 30
+let max_delayed_send = 1
   
 let write t ping s ip port =
-(*  lprintf "UDP write to %s:%d\n" (Ip.to_string ip) port; *)
+(*  lprintf_nl "UDP write to %s:%d" (Ip.to_string ip) port; *)
   if not (closed t) && t.wlist_size < !max_wlist_size then 
     let s, addr = match t.socks_local with
       None -> s, Unix.ADDR_INET(Ip.to_inet_addr ip, port) 
@@ -219,16 +228,19 @@
               let _ =
                 try
                   if ping then declare_ping ip;
-                  ignore(Unix.sendto (fd sock) s 0 len [] addr)
+                  ignore(Unix.sendto (fd sock) s 0 len [] addr);
+                  if !verbose_bandwidth > 1 then begin
+                      lprintf_nl "[BW2] direct send udp %d bytes (write)" len;
+                    end;
                 with e ->
-                    lprintf "Exception in sendto %s:%d\n" (Ip.to_string ip) port;
+                    lprintf_nl "Exception in sendto %s:%d" (Ip.to_string ip) port;
                     raise e
                     in
               udp_uploaded_bytes := !udp_uploaded_bytes ++ (Int64.of_int len);
               ()
 (*
-lprintf "UDP sent [%s]" (String.escaped
-(String.sub s pos len)); lprint_newline ();
+lprintf_nl "UDP sent [%s]" (String.escaped
+(String.sub s pos len));
 *)
             with
               Unix.Unix_error ((Unix.EWOULDBLOCK | Unix.ENOBUFS), _, _) -> 
@@ -240,7 +252,7 @@
                 t.wlist_size <- t.wlist_size + String.length s;
                 must_write sock true;
             | e ->
-                lprintf "Exception %s in sendto\n"
+                lprintf_nl "Exception %s in sendto"
                   (Printexc2.to_string e);
                 print_addr addr;
                 raise e
@@ -265,6 +277,10 @@
           t.wlist_size <- t.wlist_size + String.length s;
           must_write t.sock true;
         end
+  else
+    if !debug then begin
+        lprintf_nl "UDP DROPPED in write";
+    end
     
 let dummy_sock = Obj.magic 0
 
@@ -278,11 +294,16 @@
   begin try
       ignore (local_sendto (fd sock) p);
       udp_uploaded_bytes := !udp_uploaded_bytes ++ (Int64.of_int len);
+      if !verbose_bandwidth > 1 then begin
+          lprintf_nl "[BW2] direct send udp %d bytes (iter_write_no_bc)" len;
+      end
     with
-      Unix.Unix_error ((Unix.EWOULDBLOCK | Unix.ENOBUFS), _, _) as e -> raise e
+      Unix.Unix_error ((Unix.EWOULDBLOCK | Unix.ENOBUFS), _, _) as e -> 
+        lprintf_nl "Exception %s in sendto next" (Printexc2.to_string e);
+        raise e
     | e ->
           if !debug then
-            lprintf "Exception %s in sendto next\n"
+            lprintf_nl "Exception %s in sendto next"
               (Printexc2.to_string e)
   end;
   iter_write_no_bc t sock
@@ -302,23 +323,27 @@
     t.wlist_size <- t.wlist_size - String.length p.udp_content;
     if time < bc.base_time then begin
         if !debug then begin
-            lprintf "[UDP DROPPED]"; 
+            lprintf_nl "UDP DROPPED in iter_write"; 
           end;
       iter_write t sock bc
       end else
     let len = String.length p.udp_content in
     begin try
-        
-
         ignore (local_sendto (fd sock) p);
         udp_uploaded_bytes := !udp_uploaded_bytes ++ (Int64.of_int len);
         bc.remaining_bytes <- bc.remaining_bytes - (len +
           !TcpBufferedSocket.ip_packet_size) ;
+        TcpBufferedSocket.register_bytes (Some bc.tcp_bc) len;
+        if !verbose_bandwidth > 1 then begin
+            lprintf_nl "[BW2] bc send udp %d bytes" len;
+          end;
       with
-        Unix.Unix_error ((Unix.EWOULDBLOCK | Unix.ENOBUFS), _, _) as e -> raise e
+        Unix.Unix_error ((Unix.EWOULDBLOCK | Unix.ENOBUFS), _, _) as e -> 
+          lprintf_nl "Exception %s in sendto next" (Printexc2.to_string e);
+          raise e
       | e ->
           if !debug then
-            lprintf "Exception %s in sendto next\n"
+            lprintf_nl "Exception %s in sendto next"
               (Printexc2.to_string e)
     end;
     iter_write t sock bc
@@ -418,26 +443,28 @@
       allow_io = ref false;
       count = 0;
       base_time = 0;
+      tcp_bc = tcp_bc;
     } in
   let udp_user total n =
-(*
-    if !BasicSocket.debug then  begin
-      lprintf "udp_user %d/%d" n total; lprint_newline ();
-      end; *)
+    if !verbose_bandwidth > 0 then
+      lprintf_nl "udp_user %d/%d" n total;
     let n = if total = 0 then 100000 else n in
     udp_bc.base_time <- udp_bc.base_time + 1;
     if udp_bc.count = 0 then begin
         udp_bc.count <- 10;
         TcpBufferedSocket.set_lost_bytes tcp_bc udp_bc.remaining_bytes 
           udp_bc.base_time;
-        udp_bc.remaining_bytes <- 0;
       end;
     udp_bc.count <- udp_bc.count - 1;
     udp_bc.total_bytes <- total;
-    udp_bc.remaining_bytes <- udp_bc.remaining_bytes + n;
+    udp_bc.remaining_bytes <- total / 2;
+(*    udp_bc.remaining_bytes <- udp_bc.remaining_bytes + n; *)
     if total <> 0 && udp_bc.remaining_bytes > total then
       udp_bc.remaining_bytes <- total;
     udp_bc.allow_io := udp_bc.remaining_bytes > 0;
+    if !verbose_bandwidth > 0 then
+      lprintf_nl "udp_bc count:%d total_bytes:%d remaining_bytes:%d" 
+      udp_bc.count udp_bc.total_bytes udp_bc.remaining_bytes;
   in
   TcpBufferedSocket.set_remaining_bytes_user tcp_bc udp_user;
   udp_bc
@@ -510,8 +537,8 @@
 
     MlUnix.set_nonblock fd;
   with e -> 
-    lprintf "[SOCKS] proxy error prevent creation of UDP socket: %s" 
-      (Printexc2.to_string e); lprint_newline ();
+    lprintf_nl "[SOCKS] proxy error prevent creation of UDP socket: %s" 
+      (Printexc2.to_string e);
     close t "socks proxy error"; raise e
 *)
 
@@ -524,7 +551,7 @@
   ) latencies;
   LittleEndian.buf_int b !counter;
   Hashtbl.iter (fun ip (latency, samples) ->
-      if !verbose then lprintf "   Latency UDP: %s -> %d (%d samples)\n" (Ip.to_string ip) !latency !samples;
+      if !verbose then lprintf_nl "   Latency UDP: %s -> %d (%d samples)" (Ip.to_string ip) !latency !samples;
       LittleEndian.buf_ip b ip;
       LittleEndian.buf_int16 b !latency;
       LittleEndian.buf_int16 b !samples;
