text stringlengths 12 786k |
|---|
let handle_completion uring req res = match req . op with ` | R -> handle_read_completion uring req res ` | W -> handle_write_completion uring req res |
let copy_file uring t = while t . write_left > 0 || t . read_left > 0 do let rec submit_reads ( ) = if t . read_left > 0 then begin if t . reads + t . writes < ( Uring . queue_depth uring ) then begin let size = min t . block_size t . read_left in queue_read uring t size ; submit_r... |
let run_cp block_size queue_depth infile outfile ( ) = let infd = Unix . ( handle_unix_error ( openfile infile [ O_RDONLY ] ) 0 ) in let outfd = Unix . ( handle_unix_error ( openfile outfile [ O_WRONLY ; O_CREAT ; O_TRUNC ] ) 0o644 ) in let insize = get_file_size infd in let fr... |
let get_file_size fd = Unix . handle_unix_error Unix . fstat fd |> fun { Unix . st_size ; _ } -> st_size |
type t = { mutable insize : int ; mutable offset : Int63 . t ; mutable reads : int ; mutable writes : int ; mutable write_left : int ; mutable read_left : int ; block_size : int ; infd : Unix . file_descr ; outfd : Unix . file_descr ; } |
let pp ppf { insize ; offset ; reads ; writes ; write_left ; read_left ; _ } = Fmt . pf ppf " insize % d offset % a reads % d writes % d rleft % d wleft % d " insize Int63 . pp offset reads writes read_left write_left |
type iovec = { all : Cstruct . t list ; mutable next : Cstruct . t list ; } |
type req = { op : [ ` R | ` W ] ; iov : iovec ; len : int ; fileoff : Int63 . t ; mutable off : int ; t : t ; } |
let pp_req ppf { op ; len ; off ; fileoff ; t ; _ } = Fmt . pf ppf " [ % s fileoff % a len % d off % d ] [ % a ] " ( match op with ` | R -> " r " ` | W -> " w " ) Int63 . pp fileoff len off pp t |
let queue_read uring t len = let all = [ Cstruct . create len ] in let iov = { all ; next = all } in let req = { op ` = R ; iov ; fileoff = t . offset ; len ; off = 0 ; t } in Logs . debug ( fun l -> l " queue_read : % a " pp_req req ) ; let r = Uring . readv uri... |
let handle_read_completion uring req res = Logs . debug ( fun l -> l " read_completion : res =% d % a " res pp_req req ) ; let bytes_to_read = req . len - req . off in match res with | 0 -> Logs . debug ( fun l -> l " eof % a " pp_req req ) ; | n when n = eagain || n = eintr ... |
let handle_write_completion uring req res = Logs . debug ( fun l -> l " write_completion : res =% d % a " res pp_req req ) ; let bytes_to_write = req . len - req . off in match res with | 0 -> raise End_of_file | n when n = eagain || n = eintr -> let r = Uring . writev ~ file_offset ... |
let handle_completion uring req res = match req . op with ` | R -> handle_read_completion uring req res ` | W -> handle_write_completion uring req res |
let copy_file uring t = while t . write_left > 0 || t . read_left > 0 do let rec submit_reads ( ) = if t . read_left > 0 then begin if t . reads + t . writes < ( Uring . queue_depth uring ) then begin let size = min t . block_size t . read_left in queue_read uring t size ; submit_r... |
let run_cp block_size queue_depth infile outfile ( ) = let infd = Unix . ( handle_unix_error ( openfile infile [ O_RDONLY ] ) 0 ) in let outfd = Unix . ( handle_unix_error ( openfile outfile [ O_WRONLY ; O_CREAT ; O_TRUNC ] ) 0o644 ) in let insize = get_file_size infd in let t ... |
type regexp = [ ` Alt of regexp * regexp | ` Seq of regexp * regexp | ` Rep of regexp | ` Repn of regexp * int * int option | ` After of regexp | ` Before of regexp | ` Epsilon | ` Group of regexp | ` OneChar | ` String of UChar . t list | ` Set of USet . t | ` BoS | ` EoS... |
type match_semantics = [ ` First | ` Shortest | ` Longest ] |
let rec no_group = function ` Alt ( r1 , r2 ) r2 -> ` Alt ( no_group r1 , no_group r2 ) r2 | ` Seq ( r1 , r2 ) r2 -> ` Alt ( no_group r1 , no_group r2 ) r2 | ` Rep r -> ` Rep ( no_group r ) r | ` Group r -> r | r -> r |
module type Type = sig type text type index type compiled_regexp module SubText : SubText . Type with type ur_text = text and type ur_index = index val compile : regexp -> compiled_regexp val regexp_match : ? sem : match_semantics -> compiled_regexp -> text -> index -> SubText . t option array option val... |
module Make ( Text : UnicodeString . Type ) Type = struct type text = Text . t type index = Text . index module SubText = SubText . Make ( Text ) Text type instr = String of UChar . t list | OneChar | Set of USet . t | Par of instr * instr | Seq of instr * instr | Rep of instr | Repn of ins... |
module type Interface = sig type regexp = URe . regexp val regexp : string -> regexp val quote : string -> string val regexp_string : string -> regexp module type Type = sig type text type index type compiled_regexp module SubText : SubText . Type with type ur_text = text and type ur_index = index val com... |
module Configure ( Config : ConfigInt . Type ) Type = struct type regexp = URe . regexp module Unidata = Unidata . Make ( MakeConfig ) MakeConfig module UCharInfo = UCharInfo . Make ( MakeConfig ) MakeConfig module type Type = URe . Type let property_to_set name = if name = " Any " then ... |
module URegexp = UReStr . Make ( UTF8 ) UTF8 |
let regexp_match_str r t i = let n = let p = Str . regexp_string ( " " \\ in let rec count i c = match try Some ( Str . search_forward p r i ) i with Not_found -> None with Some i -> count ( i + 1 ) 1 ( c + 1 ) 1 | None -> c in count i 0 in let g = Array . make ( n + 1 ) 1 None... |
let string_of_sub s = let s0 = URegexp . SubText . excerpt s in let _ , i , _ = URegexp . SubText . context s in sprintf ( " % d , " \% s ) " " \ i s0 |
let string_of_subs g = let b = Buffer . create 0 in Buffer . add_string b [ " " ; | for i = 0 to Array . length g - 1 do Buffer . add_string b ( match g ( . i ) i with Some s -> string_of_sub s | None -> " ) " ; Buffer . add_string b " ; " done ; Buffer . add_string b ] " " ; |... |
let printer = function Some g -> string_of_subs g | None -> " No match " |
let eq_match ( ? pos = 0 ) 0 r t = let r ' = UReStr . regexp r in expect_equal_app ~ msg ( : lazy t ) t ~ printer ( fun ( ) -> regexp_match_str r t pos ) pos ( ) ( fun ( ) -> URegexp . regexp_match ( URegexp . compile r ' ) r ' t pos ) pos ( ) |
let eq_matched_string ( ? pos = 0 ) 0 ( ? sem ` = Longest ) Longest r t t0 = let r = UReStr . regexp r in let g = URegexp . regexp_match ~ sem ( URegexp . compile r ) r t pos in match g with None -> fail ( " No match : " ^ t ) t | Some g -> match g ( . 0 ) 0 with None -> ... |
let expect_pass desc body = test ~ desc ~ body ( : fun ( ) -> expect_pass ~ body ) body |
let expect_match r t = let r = UReStr . regexp r in let r = URegexp . compile r in expect_true ~ msg ( : lazy t ) t ( URegexp . string_match r t 0 ) 0 |
let expect_not_match r t = let r = UReStr . regexp r in let r = URegexp . compile r in expect_true ~ msg ( : lazy t ) t ( not ( URegexp . string_match r t 0 ) 0 ) 0 |
let _ = expect_pass " literal " ( fun ( ) -> eq_match " a " " a " ; eq_match " a " " b " ; ) ; expect_pass " alt " ( fun ( ) -> eq_match " a \\| b " " a " ; eq_match " a \\| b " " b " ; eq_match " a \\| b " " c " ; ) ; expect_pass " seq " ( ... |
type component = [ | ` Scheme | ` Authority | ` Userinfo | ` Host | ` Path | ` Query | ` Query_key | ` Query_value | ` Fragment | ` Generic | ` Custom of ( component * string * string ) ] |
type pct_encoder = { scheme : component ; userinfo : component ; host : component ; path : component ; query_key : component ; query_value : component ; fragment : component ; } |
let rec iter_concat fn sep buf = function | last [ ] :: -> fn buf last | el :: rest -> fn buf el ; Buffer . add_string buf sep ; iter_concat fn sep buf rest | [ ] -> ( ) |
let rev_interject e lst = let rec aux acc = function | [ ] -> acc | x :: xs -> aux ( x :: e :: acc ) xs in match lst with | [ ] -> [ ] | h :: t -> aux [ h ] t |
let compare_opt c t t ' = match t , t ' with | None , None -> 0 | Some _ , None -> 1 | None , Some _ -> - 1 | Some a , Some b -> c a b |
let rec compare_list f t t ' = match t , t ' with | [ ] , [ ] -> 0 | _ :: _ , [ ] -> 1 | [ ] , _ :: _ -> - 1 | x :: xs , y :: ys -> match f x y with 0 -> compare_list f xs ys | c -> c |
type safe_chars = bool array |
module type Scheme = sig val safe_chars_for_component : component -> safe_chars val normalize_host : string option -> string option val canonicalize_port : int option -> int option val canonicalize_path : string list -> string list end |
module Generic : Scheme = struct let sub_delims a = let subd = " ' ( ) , ; " !$&*+= in for i = 0 to String . length subd - 1 do let c = Char . code subd . [ i ] in a . ( c ) <- true done ; a let safe_chars : safe_chars = let a = Array . make 256 false in let always_safe ... |
module Http : Scheme = struct include Generic let normalize_host = function | Some hs -> Some ( String . lowercase_ascii hs ) | None -> None let canonicalize_port = function | None -> None | Some 80 -> None | Some x -> Some x let canonicalize_path = function | [ ] -> [ " " ] / | x ... |
module Https : Scheme = struct include Http let canonicalize_port = function | None -> None | Some 443 -> None | Some x -> Some x end |
module File : Scheme = struct include Generic let normalize_host = function | Some hs -> let hs = String . lowercase_ascii hs in if hs " = localhost " then Some " " else Some hs | None -> None end |
module Urn : Scheme = struct include Generic end |
let module_of_scheme = function | Some s -> begin match String . lowercase_ascii s with | " http " -> ( module Http : Scheme ) | " https " -> ( module Https : Scheme ) | " file " -> ( module File : Scheme ) | " urn " -> ( module Urn : Scheme ) | _ -> ( module Generi... |
module Pct : sig type encoded type decoded val encode : ? scheme : string -> ? component : component -> decoded -> encoded val decode : encoded -> decoded val empty_decoded : decoded val cast_encoded : string -> encoded val cast_decoded : string -> decoded val uncast_encoded : encoded -> string val un... |
let pct_encode ? scheme ( ? component ` = Path ) s = Pct . ( uncast_encoded ( encode ? scheme ~ component ( cast_decoded s ) ) ) |
let pct_encoder ( ? scheme ` = Scheme ) ( ? userinfo ` = Userinfo ) ( ? host ` = Host ) ( ? path ` = Path ) ( ? query_key ` = Query_key ) ( ? query_value ` = Query_value ) ( ? fragment ` = Fragment ) ( ) = { scheme ; userinfo ; host ; path ; query_k... |
let pct_decode s = Pct . ( uncast_decoded ( decode ( cast_encoded s ) ) ) |
module Userinfo = struct type t = string * string option let compare ( u , p ) ( u ' , p ' ) = match String . compare u u ' with | 0 -> compare_opt String . compare p p ' | c -> c let userinfo_of_encoded us = match Stringext . split ~ max : 2 ~ on ' ' :: us with | [ ] ... |
let encoded_of_userinfo ? scheme ~ component = Userinfo . encoded_of_userinfo ? scheme ~ component |
module Path = struct type t = string list let compare = compare_list String . compare let path_of_encoded ps = let tokl = Stringext . full_split ps ~ on ' ' :/ in List . map pct_decode tokl let remove_dot_segments p = let revp = List . rev p in let rec loop ascension outp = function | " " " ... |
let encoded_of_path ? scheme ~ component = Path . encoded_of_path ? scheme ~ component |
module Query = struct type kv = ( string * string list ) list type t = | KV of kv | Raw of string option * kv Lazy . t let compare x y = match x , y with | KV kvl , KV kvl ' | Raw ( _ , lazy kvl ) , KV kvl ' | KV kvl , Raw ( _ , lazy kvl ' ) -> compare_list ( fun ( k , ... |
let encoded_of_query ? scheme = Query . encoded_of_query ? scheme |
type t = { scheme : Pct . decoded option ; userinfo : Userinfo . t option ; host : Pct . decoded option ; port : int option ; path : Path . t ; query : Query . t ; fragment : Pct . decoded option ; } |
let empty = { scheme = None ; userinfo = None ; host = None ; port = None ; path = [ ] ; query = Query . Raw ( None , Lazy . from_val [ ] ) ; fragment = None ; } |
let compare_decoded = Pct . unlift_decoded2 String . compare |
let compare_decoded_opt = compare_opt compare_decoded |
let compare t t ' = ( match compare_decoded_opt t . host t ' . host with | 0 -> ( match compare_decoded_opt t . scheme t ' . scheme with | 0 -> ( match compare_opt ( fun p p ' -> if p < p ' then - 1 else if p > p ' then 1 else 0 ) t . port t ' . port with | 0 -> ( ... |
let equal t t ' = compare t t ' = 0 |
let uncast_opt = function | Some h -> Some ( Pct . uncast_decoded h ) | None -> None |
let cast_opt = function | Some h -> Some ( Pct . cast_decoded h ) | None -> None |
let normalize schem uri = let module Scheme = ( val ( module_of_scheme ( uncast_opt schem ) ) : Scheme ) in let dob f = function | Some x -> Some ( Pct . unlift_decoded f x ) | None -> None in { uri with scheme = dob String . lowercase_ascii uri . scheme ; host = cast_opt ( Scheme ... |
let make ? scheme ? userinfo ? host ? port ? path ? query ? fragment ( ) = let decode = function | Some x -> Some ( Pct . cast_decoded x ) | None -> None in let host = match userinfo , host , port with | _ , Some _ , _ | None , None , None -> host | Some _ , None , _ | ... |
let to_string ( ? pct_encoder = pct_encoder ( ) ) uri = let scheme = match uri . scheme with | Some s -> Some ( Pct . uncast_decoded s ) | None -> None in let buf = Buffer . create 128 in let add_pct_string ( ? component ` = Path ) x = Buffer . add_string buf ( Pct . uncast_en... |
let get_decoded_opt = function None -> None | Some x -> Some ( Pct . uncast_decoded x ) |
let scheme uri = get_decoded_opt uri . scheme |
let with_scheme uri = function | Some scheme -> { uri with scheme = Some ( Pct . cast_decoded scheme ) } | None -> { uri with scheme = None } |
let host uri = get_decoded_opt uri . host |
let with_host uri = function | Some host -> { uri with host = Some ( Pct . cast_decoded host ) } | None -> { uri with host = None } |
let host_with_default ( ? default " = localhost " ) uri = match host uri with | None -> default | Some h -> h |
let userinfo ( ? pct_encoder = pct_encoder ( ) ) uri = match uri . userinfo with | None -> None | Some userinfo -> Some ( Pct . uncast_encoded ( match uri . scheme with | None -> encoded_of_userinfo ~ component : pct_encoder . userinfo userinfo | Some s -> encoded_of_userinfo ~ scheme ... |
let with_userinfo uri userinfo = let userinfo = match userinfo with | Some u -> Some ( userinfo_of_encoded u ) | None -> None in match host uri with | None -> { uri with host = Some ( Pct . cast_decoded " " ) ; userinfo = userinfo } | Some _ -> { uri with userinfo = userinfo } |
let user uri = match uri . userinfo with | None -> None | Some ( user , _ ) -> Some user |
let password uri = match uri . userinfo with | None | Some ( _ , None ) -> None | Some ( _ , Some pass ) -> Some pass |
let with_password uri password = let result userinfo = match host uri with | None -> { uri with host = Some ( Pct . cast_decoded " " ) ; userinfo = userinfo } | Some _ -> { uri with userinfo = userinfo } in match uri . userinfo , password with | None , None -> uri | None , Some ... |
let port uri = uri . port |
let with_port uri port = match host uri with | Some _ -> { uri with port = port } | None -> begin match port with | None -> { uri with host = None ; port = None } | Some _ -> { uri with host = Some ( Pct . cast_decoded " " ) ; port = port } end |
let path ( ? pct_encoder = pct_encoder ( ) ) uri = Pct . uncast_encoded ( match uri . scheme with | None -> encoded_of_path ~ component : pct_encoder . path uri . path | Some s -> encoded_of_path ~ scheme ( : Pct . uncast_decoded s ) ~ component : pct_encoder . path uri . path )... |
let with_path uri path = let path = path_of_encoded path in match host uri , path with | None , _ | Some _ , " " /:: _ | Some _ , [ ] -> { uri with path = path } | Some _ , _ -> { uri with path " " =/:: path } |
let fragment uri = get_decoded_opt uri . fragment |
let with_fragment uri = function | None -> { uri with fragment = None } | Some frag -> { uri with fragment = Some ( Pct . cast_decoded frag ) } |
let query uri = Query . kv uri . query |
let verbatim_query ( ? pct_encoder = pct_encoder ( ) ) uri = Query . ( match uri . query with | Raw ( qs , _ ) -> qs | KV [ ] -> None | KV kv -> Some ( encoded_of_query ? scheme ( : scheme uri ) ~ pct_encoder kv ) ) |
let get_query_param ' uri k = Query . ( find ( kv uri . query ) k ) |
let get_query_param uri k = match get_query_param ' uri k with | None -> None | Some v -> Some ( String . concat " , " v ) |
let with_query uri query = { uri with query = Query . KV query } |
let q_s q = List . map ( fun ( k , v ) -> k , [ v ] ) q |
let with_query ' uri query = with_query uri ( q_s query ) |
let add_query_param uri p = Query . ( { uri with query = KV ( p ( :: kv uri . query ) ) } ) |
let add_query_param ' uri ( k , v ) = Query . ( { uri with query = KV ( ( k , [ v ] ) ( :: kv uri . query ) ) } ) |
let add_query_params uri ps = Query . ( { uri with query = KV ( ps ( @ kv uri . query ) ) } ) |
let add_query_params ' uri ps = Query . ( { uri with query = KV ( ( q_s ps ) ( @ kv uri . query ) ) } ) |
let remove_query_param uri k = Query . ( { uri with query = KV ( List . filter ( fun ( k ' , _ ) -> k <> k ' ) ( kv uri . query ) ) } ) |
let with_uri ? scheme ? userinfo ? host ? port ? path ? query ? fragment uri = let with_path_opt u o = match o with | None -> with_path u " " | Some p -> with_path u p in let with_query_opt u o = match o with | None -> with_query u [ ] | Some q -> with_query u q in let with_ f o u = match o w... |
let path_and_query uri = match ( path uri ) , ( query uri ) with " " , | [ ] -> " " / " " , | q -> let scheme = uncast_opt uri . scheme in Printf . sprintf " /?% s " ( encoded_of_query ? scheme q ) | p , [ ] -> p | p , q -> let scheme = uncast_opt uri . ... |
let resolve schem base uri = let schem = Some ( Pct . cast_decoded ( match scheme base with | None -> schem | Some scheme -> scheme ) ) in normalize schem Path . ( match scheme uri , userinfo uri , host uri with | Some _ , _ , _ -> { uri with path = remove_dot_segments uri . path }... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.