[Unison-hackers] Unix.sleep insufficient for -repeat! Need half seconds.
Ryan Newton
rrnewton at gmail.com
Sat Apr 21 21:27:12 EDT 2007
That couldn't have been easier. (Although it would be nice if Caml
had a variant of "external" which would do the simple type
conversions for you (for ints, floats, chars) -- then this wouldn't
require C code at all!)
The below works for MacOS (intel + ppc) and linux. If the powers
that be are interested in this change, I can look into a solution
that works for windows as well.
-Ryan
usleep.c:
===============================================
#include <caml/mlvalues.h>
#include <unistd.h>
value unison_usleep( value msecs ) {
return Val_int( usleep( Int_val(msecs)));
}
uitext.ml:
===============================================
(* Defined in usleep.c *)
external usleep : int -> int = "unison_usleep"
let rec synchronizeUntilDone () =
let repeatinterval =
if Prefs.read Uicommon.repeat = "" then -1.0 else
try float_of_string (Prefs.read Uicommon.repeat)
with Failure "float_of_string" ->
(* If the 'repeat' pref is not a number, switch modes... *)
synchronizePathsFromFilesystemWatcher() in
let exitStatus = synchronizeUntilNoFailures() in
if repeatinterval < 0.0 then
exitStatus
else begin
(* Do it again *)
Trace.status (Printf.sprintf "\nSleeping for %f seconds...\n"
repeatinterval);
let seconds = int_of_float repeatinterval in
let millisec = (int_of_float (1000000. *. repeatinterval)) -
(seconds * 1000000) in
(* In some implementations usleep can only sleep up to 1
second. *)
(if seconds > 0 then Unix.sleep seconds);
(if millisec > 0 then let _ = usleep millisec in ());
synchronizeUntilDone ()
end
On Apr 20, 2007, at 10:54 AM, Ryan Newton wrote:
> Hello all,
>
> I use the -repeat option *extensively* to establish a relatively
> low-bandwidth, poor man's distributed file system. Basically, if
> my connection is good enough, I do development by running emacs
> over X11 forwarding from the server. If it's not good enough, I
> run emacs locally, use unison -repeat, and compile/run the program
> on the server over a simple ssh terminal.
More information about the Unison-hackers
mailing list