text stringlengths 12 786k |
|---|
module Parser = struct let header_size = 16 let xenstore_payload_max = 4096 let allow_oversize_packets = ref true type state = | Unknown_operation of int32 | Parser_failed of string | Need_more_data of int | Packet of t type parse = | ReadingHeader of int * string | ReadingBody of t | Finished of state ... |
module type IO = sig type ' a t val return : ' a -> ' a t val ( >>= ) : ' a t -> ( ' a -> ' b t ) -> ' b t type channel val read : channel -> string -> int -> int -> int t val write : channel -> string -> int -> int -> unit t end |
type ( ' a , ' b ) result = |
module PacketStream = functor ( IO : IO ) -> struct let ( >>= ) = IO . ( >>= ) let return = IO . return type stream = { channel : IO . channel ; mutable incoming_pkt : Parser . parse ; } let make t = { channel = t ; incoming_pkt = Parser . start ( ) ; } let rec rec... |
let is_valid_path path = let result = ref true in let bad = " " // in for offset = 0 to String . length path - ( String . length bad ) do if String . sub path offset ( String . length bad ) = bad then result := false done ; if path <> " " / && path <> " " && path . [ Stri... |
let is_valid_watch_path path = ( path <> " " && path . [ 0 ] = ' ' ) @ || ( is_valid_path path ) |
module Token = struct type t = string let to_user_string x = Scanf . sscanf x " % d :% s " ( fun _ x -> x ) let to_debug_string x = x let of_string x = x let to_string x = x end |
let data_concat ls = ( String . concat " \ 000 " ls ) ^ " \ 000 " |
let create tid rid ty data = let len = String . length data in let b = Buffer . create len in Buffer . add_string b data ; { tid = tid ; rid = rid ; ty = ty ; len = len ; data = b ; } |
let set_data pkt ( data : string ) = let len = String . length data in let b = Buffer . create len in Buffer . add_string b data ; { pkt with len = len ; data = b } |
module Response = struct type payload = | Read of string | Directory of string list | Getperms of ACL . t | Getdomainpath of string | Transaction_start of int32 | Write | Mkdir | Rm | Setperms | Watch | Unwatch | Transaction_end | Debug of string list | Introduce | Resume | Release | Set_target | ... |
module Request = struct do done ; ! v end try ] create rid end |
module Unmarshal = struct let some x = Some x let int_of_string_opt x = try Some ( int_of_string x ) with _ -> None let int32_of_string_opt x = try Some ( Int32 . of_string x ) with _ -> None let unit_of_string_opt x = if x = " " then Some ( ) else None let ok x = if x = " OK " then So... |
let response hint sent received f = match get_ty sent , get_ty received with | _ , Op . Error -> begin match get_data received with | " ENOENT " -> raise ( Enoent hint ) | " EAGAIN " -> raise Eagain | " EINVAL " -> raise Invalid | " EEXIST " -> raise Eexist | s -> raise ( Error... |
let ( |> ) a b = b a |
let ( ++ ) f g x = f ( g x ) |
let debug fmt = Logging . debug " xs_server " fmt |
let error fmt = Logging . error " xs_server " fmt |
let store = List . iter store |
module type TRANSPORT = sig type ' a t = ' a Lwt . t val return : ' a -> ' a Lwt . t val ( >>= ) : ' a t -> ( ' a -> ' b Lwt . t ) -> ' b Lwt . t type server val listen : unit -> server Lwt . t type channel val read : channel -> string -> int -> int -> int Lwt . t val... |
module Server = functor ( T : TRANSPORT ) -> struct Lwt_list . iter_s ) try_lwt ) end |
let ( |> ) a b = b a |
let id x = x |
let op_ids _ = let open Xs_protocol . Op in for i = 0 to 100 do let i ' = Int32 . of_int i in match of_int32 i ' with | None -> ( ) | Some x -> assert ( to_int32 x = i ' ) done |
let example_acl = { owner = 5 ; other = READ ; acl = [ 2 , WRITE ; 3 , RDWR ] } |
let acl_parser _ = let open Xs_protocol . ACL in let ts = [ { owner = 5 ; other = READ ; acl = [ 2 , WRITE ; 3 , RDWR ] } ; { owner = 1 ; other = WRITE ; acl = [ ] } ; ] in let ss = List . map to_string ts in let ts ' = List . map of_string ss in let printer ... |
let test_packet_parser choose pkt ( ) = let open Xs_protocol in let p = ref ( Parser . start ( ) ) in let s = to_string pkt in let i = ref 0 in let finished = ref false in while not ! finished do match Parser . state ! p with done |
let test _ = let t = return ( ) in Lwt_main . run t |
type example_packet = { } |
let make_example_request op payload tid wire_fmt = { } |
let example_request_packets = " \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x05 \ x00 \ x00 \ x00 \ x13 \ x00 \ x00 \ x00 \ x2f \ x77 \ x68 \ x61 \ x74 \ x65 \ x76 \ x65 \ x72 \ x2f \ x77 \ x68 \ x65 \ x6e \ x65 \ x76 \ x65 \ x72 \ x00 " ; " \ x02 \ x00 \ x00 \ x00 ... |
let make_example_response op response wire_fmt = } |
let example_response_packets = " \ x02 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x06 \ x00 \ x00 \ x00 \ x09 \ x00 \ x00 \ x00 \ x74 \ x68 \ x65 \ x72 \ x65 \ x73 \ x75 \ x6c \ x74 " ; " \ x02 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x06 \ x00 \ x00 \ x00 \ x00 \ x00... |
let example_packets = example_request_packets @ example_response_packets |
let rec ints first last = |
let hexstring x = " " " ; \ " " " ; \ ] ) |
let _ = let verbose = ref false in Arg . parse [ " - verbose " , Arg . Unit ( fun _ -> verbose := true ) , " Run in verbose mode " ; ] ( fun x -> Printf . fprintf stderr " Ignoring argument : % s " x ) " Test xenstore protocol code " ; let packet_parsing choose = let... |
let create ( ) = ( match Xs_transport . choose_xenstore_path ( ) with | None -> Printf . fprintf stderr " Failed to find xenstore socket . I tried the following :\ n " ; List . iter ( fun x -> Printf . fprintf stderr " % s \ n " x ) ( Xs_transport . get_xenstore_paths ( ) ... |
let write fd bufs ofs len = Lwt_unix . write fd bufs ofs len >>= fun n -> if n <> len then fail End_of_file else return ( ) |
type ' a t = ' a Lwt . t |
let ( >>= ) = Lwt . bind |
type backend = [ ` unix | ` xen ] |
let create ( ) = let path = match Xs_transport . choose_xenstore_path ( ) with | None -> Printf . fprintf stderr " Failed to find xenstore socket . I tried the following :\ n " ; List . iter ( fun x -> Printf . fprintf stderr " % s \ n " x ) ( Xs_transport . get_xenstore_path... |
let destroy fd = Unix . close fd |
let read fd = Unix . read fd |
let write fd bufs ofs len = let n = Unix . write fd bufs ofs len in if n <> len then begin raise End_of_file end |
type ' a t = ' a |
let return x = x |
let ( >>= ) x f = f x |
type backend = [ ` unix | ` xen ] |
type t = | Test of ( unit -> unit ) | Labeled of string * t | List of t list |
let fun_ f = Test f |
let label s t = Labeled ( s , t ) |
let list ts = List ts |
module Config = struct type arg = | Do of Pcre . regexp | Dont of Pcre . regexp type t = { args : arg list ; show_tests : bool ; default_go : bool ; } let rev_args = ref [ ] let show_tests = ref false let from_args default_go = { args = List . rev ! rev_args ; show_tests = ! show_... |
let arg_specs = let open Arg in let open Config in [ " -- test " , String ( fun s -> rev_args +::= Do ( Pcre . regexp s ) ) , " < string >: Perform tests match with the string " ; " -- no - test " , String ( fun s -> rev_args +::= Dont ( Pcre . regexp s ) ) , " <... |
module State = struct type t = { rev_label : string list ; config : Config . t ; } let add_label l st = { st with rev_label = l :: st . rev_label } let labels st = List . rev st . rev_label let is_go t = Config . is_go t . config & List . rev t . rev_label let from_args default_go ... |
let rec iter st go prim = function | Test t -> prim st t | Labeled ( l , t ) -> let st = State . add_label l st in go st ( fun ( ) -> iter st go prim t ) | List ts -> List . iter ( iter st go prim ) ts |
let show st t = let go _st f = f ( ) in let prim st _ = !!% " % s : % s . " @ ( String . concat " " / ( State . labels st ) ) ( if State . is_go st then " go " else " skip " ) in iter st go prim t ; exit 0 |
let run ' st = let go _st f = f ( ) in let prim st t = if State . is_go st then begin let name = String . concat " " / ( State . labels st ) in !!% " Testing % s . . . . " @ name ; begin try t ( ) with | e -> !!% " Error : % s : % s . " @ ( String . conca... |
let run default_go t = let st = State . from_args default_go in if st . State . config . Config . show_tests then show st t else run ' st t |
let sourceDirs = Node . Path . join [ " | lib " ; " bs " ; " . sourcedirs . json ] " | |
let lock = Xwatcher_util . makeLock ( ) |
let events = Xwatcher_util . makeEventObj ( ) |
let watchers : watcher array = [ ] || |
let source_dirname = Js . Option . getExn [ % external __dirname ] __dirname |
let bsb = Node . Path . join [ | source_dirname ; bsb_exe ] | |
let rec onChange = fun eventType fileName -> Js . log { j | Event $ eventType $ fileName | j } j ; events ## push ( eventType , fileName ) fileName ; build bsb events lock ( fun [ @ bs ] bs ( ) -> idle ( ) ) let watchFiles = getWatchFiles sourceDirs in watchers |> Js . Vector .... |
let ( ) = Node . Process . putEnvVar " BS_VSCODE " " 1 " ; Js . Vector . pushBack ( makeWatcher bsconfig ( fun [ @ bs ] bs x y -> onChange x y ) y ) y watchers ; build bsb events lock ( fun [ @ bs ] bs ( ) -> idle ( ) ) |
let source_dirname = Js . Option . getExn [ % external __dirname ] __dirname |
let cwd = Node . Process . cwd ( ) |
let root = if Node . Fs . existsSync ( Node . Path . join [ | cwd ; bsconfig ] ) | then cwd else Xwatcher_util . findFile ~ prev : cwd ~ cwd ( : Node . Path . dirname cwd ) cwd bsconfig |
let jscomp = Js . log { j | Root : $ root | j } j ; Node . Path . join [ | root ; " jscomp " ] | |
let lock = Xwatcher_util . makeLock ( ) |
let events = Xwatcher_util . makeEventObj ( ) |
let exec ( ) = buildWithShell command events lock ( fun [ @ bs ] bs ( ) -> ( ) ) |
let watch dir = makeWatcher dir ( fun [ @ bs ] bs _event fileName -> if Js . String . endsWith " . ml " fileName || Js . String . endsWith " . mli " fileName || Js . String . endsWith " . cppo " fileName || Js . String . endsWith " . js " fileName || fileName = " Makefile " || fi... |
let ( ) = Node . Process . putEnvVar " BS_VSCODE " " 1 " ; match Js . Array . sliceFrom 2 Node . Process . argv with | [ " |- build ] " | -> Xwatcher_util . spawnInheritIgnore command | _ -> begin Js . Vector . iter ( fun [ @ bs ] bs x -> ignore @@ watch ( Node . Path . joi... |
let getWatchFiles file = if Fs . existsSync file then Js . String . split " \ n " ( Fs . readFileAsUtf8Sync file ) |> Js . Array . filter ( fun x -> String . length ( Js . String . trim x ) x <> 0 ) 0 else [ ] || method empty : unit -> unit method needRebuild : unit -> bool metho... |
type eventObj = _eventObj Js . t |
let rec findFile ~ prev ~ cwd f = if String . length prev = String . length cwd then Js . Exn . raiseError { j | $ f not found | j } j else if Fs . existsSync ( Node . Path . join [ | cwd ; f ] ) | then cwd else findFile cwd ( Node . Path . dirname cwd ) f |
let makeEventObj ( ) : eventObj = object ( self ) self val events : ( string * string ) string array = [ ] || method empty ( ) = Js . Vector . empty self ## events method push a = Js . Vector . pushBack a self ## events method needRebuild ( ) = Array . length self ## events <> 0 ... |
type t ( _ [ @ bs . as { json | [ ] | json } json ] json ) json -> ( _ [ @ bs . as { json | { " stdio " : " inherit " } | json } json ] json ) json -> t = " spawn " [ @@ bs . module " child_process ] " ( _ [ @ bs . as { json | [ ] | ... |
type lock = _lock Js . t |
let makeLock ( ) : lock = object ( objectself ) objectself val mutable isBuilding = false method acquire ( ) = if self ## isBuilding then false else begin self ## isBuilding #= true ; true end method release ( ) = self ## isBuilding #= false end [ @ bs ] bs |
let rec build cmd ( event : eventObj ) eventObj ( lock : lock ) idle = if lock ## acquire ( ) then begin Js . log " >>>> Start compiling " ; let events = event ## currentEvents ( ) in Js . log { j | Rebuilding since $ events | j } j ; event ## empty ( ) ; spawnInheritNoShell c... |
let rec buildWithShell cmd ( event : eventObj ) eventObj ( lock : lock ) idle = if lock ## acquire ( ) then begin Js . log " >>>> Start compiling " ; let events = event ## currentEvents ( ) in Js . log { j | Rebuilding since $ events | j } j ; event ## empty ( ) ; spawnInherit... |
type watcher = { dir : string ; watcher : Fs . Watch . t } string -> ( string -> string -> unit [ @ bs ] bs ) bs -> Node . Fs . Watch . t = " watch " [ @@ bs . module " fs ] " |
let makeWatcher file onChange = { watcher = watchOnChange file onChange ; dir = file } |
let make_printable i_char = match i_char with n when ( ( ( Char . code n ) < 32 ) or ( ( Char . code n ) > 126 ) ) -> ' . ' | _ -> i_char ; ; |
let make_hex chr = Printf . sprintf " . % 2x " ( Char . code chr ) ; ; |
let conditional_add_st bffr ch = match bffr with n when ( ( Buffer . length bffr ) = 0 ) -> Buffer . add_string bffr ch | n when ( ( Buffer . length bffr ) = 4 ) -> Buffer . add_string bffr ( " " ^ ch ) | n when ( ( ( Buffer . length bffr ) mod 5 ) = 4 ) -> Bu... |
let string_map str fnc = let rec strmap st acc = match st with " " -> List . rev acc | _ -> strmap ( String . sub st 1 ( ( String . length st ) - 1 ) ) ( ( fnc st . [ 0 ] ) :: acc ) in strmap str [ ] ; ; |
let rec output_lines fle f_buf s_buf curpos = let str_buf = String . create 16 in |
let res = input fle str_buf 0 16 in ( if ( res < 16 ) then ( List . iter ( conditional_add_st f_buf ) List . iter ( Buffer . add_char s_buf ) else ( List . iter ( conditional_add_st f_buf ) ( string_map str_buf make_hex ) ; List . iter ( Buffer . add_char s_buf ) ( str... |
let output_file fname = let fo = open_in_bin fname in |
let res = output_lines fo ( Buffer . create 16 ) ( Buffer . create 16 ) 0 in close_in fo ; res ; ; |
let rec build_char_list sb acc = let nval = try Some ( Scanf . bscanf sb " % 2x " ( fun x -> Char . chr x ) ) with End_of_file -> None in match nval with Some n -> build_char_list sb ( n :: acc ) | None -> List . rev acc ; ; |
let rec input_lines source_chan dest_chan = let write_line sc dc = try let istr = String . sub ( input_line sc ) 9 39 in let buf = Buffer . create 32 in with End_of_file -> false in let do_more = write_line source_chan dest_chan in match do_more with | false -> ( ) ; ; |
let input_file source_file dest_file = let ic = open_in source_file in |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.