let try_finalize f x finally y = let res = try f x with exn -> finally y; raise exn in finally y; res;; (** Gestion d'une connexion *) let treat_connection f socket = let buffer_size = 4096 in let buffer = String.create buffer_size in let rec treat () = match read socket buffer 0 buffer_size with | 0 -> close socket | nb -> let v = f (String.sub buffer 0 nb) in ignore (write socket v 0 nb); treat () in try try_finalize treat () close socket with _ -> fprintf Pervasives.stderr "treatment error\n"; flush Pervasives.stderr;; |