text
stringlengths
0
601k
let domain_of_sockaddr = function ADDR_UNIX _ -> PF_UNIX | ADDR_INET ( a , _ ) -> if is_inet6_addr a then PF_INET6 else PF_INET
type shutdown_command = SHUTDOWN_RECEIVE | SHUTDOWN_SEND | SHUTDOWN_ALL
type msg_flag = MSG_OOB | MSG_DONTROUTE | MSG_PEEK ? cloexec : bool -> socket_domain -> socket_type -> int -> file_descr = " unix_socket " ? cloexec : bool -> socket_domain -> socket_type -> int -> file_descr * file_descr = " unix_socketpair " ? cloexec : bool -> file_descr -> file_descr * sockaddr = " unix_accept " fi...
let recv fd buf ofs len flags = if ofs < 0 || len < 0 || ofs > Bytes . length buf - len then invalid_arg " Unix . recv " else unsafe_recv fd buf ofs len flags
let recvfrom fd buf ofs len flags = if ofs < 0 || len < 0 || ofs > Bytes . length buf - len then invalid_arg " Unix . recvfrom " else unsafe_recvfrom fd buf ofs len flags
let send fd buf ofs len flags = if ofs < 0 || len < 0 || ofs > Bytes . length buf - len then invalid_arg " Unix . send " else unsafe_send fd buf ofs len flags
let sendto fd buf ofs len flags addr = if ofs < 0 || len < 0 || ofs > Bytes . length buf - len then invalid_arg " Unix . sendto " else unsafe_sendto fd buf ofs len flags addr
let send_substring fd buf ofs len flags = send fd ( Bytes . unsafe_of_string buf ) ofs len flags
let sendto_substring fd buf ofs len flags addr = sendto fd ( Bytes . unsafe_of_string buf ) ofs len flags addr
type socket_bool_option = SO_DEBUG | SO_BROADCAST | SO_REUSEADDR | SO_KEEPALIVE | SO_DONTROUTE | SO_OOBINLINE | SO_ACCEPTCONN | TCP_NODELAY | IPV6_ONLY | SO_REUSEPORT
type socket_int_option = SO_SNDBUF | SO_RCVBUF | SO_ERROR | SO_TYPE | SO_RCVLOWAT | SO_SNDLOWAT
type socket_float_option = SO_RCVTIMEO | SO_SNDTIMEO
module SO : sig type ( ' opt , ' v ) t val bool : ( socket_bool_option , bool ) t val int : ( socket_int_option , int ) t val optint : ( socket_optint_option , int option ) t val float : ( socket_float_option , float ) t val error : ( socket_error_option , error option ) t val get : ( ' opt , ' v ) t -> file_descr -> '...
let getsockopt fd opt = SO . get SO . bool fd opt
let setsockopt fd opt v = SO . set SO . bool fd opt v
let getsockopt_int fd opt = SO . get SO . int fd opt
let setsockopt_int fd opt v = SO . set SO . int fd opt v
let getsockopt_optint fd opt = SO . get SO . optint fd opt
let setsockopt_optint fd opt v = SO . set SO . optint fd opt v
let getsockopt_float fd opt = SO . get SO . float fd opt
let setsockopt_float fd opt v = SO . set SO . float fd opt v
let getsockopt_error fd = SO . get SO . error fd SO_ERROR
type host_entry = { h_name : string ; h_aliases : string array ; h_addrtype : socket_domain ; h_addr_list : inet_addr array }
type protocol_entry = { p_name : string ; p_aliases : string array ; p_proto : int }
type service_entry = { s_name : string ; s_aliases : string array ; s_port : int ; s_proto : string } = " unix_getprotobyname " = " unix_getprotobynumber " = " unix_getservbyname " = " unix_getservbyport "
type addr_info = { ai_family : socket_domain ; ai_socktype : socket_type ; ai_protocol : int ; ai_addr : sockaddr ; ai_canonname : string }
type getaddrinfo_option = AI_FAMILY of socket_domain | AI_SOCKTYPE of socket_type | AI_PROTOCOL of int | AI_NUMERICHOST | AI_CANONNAME | AI_PASSIVE : string -> string -> getaddrinfo_option list -> addr_info list = " unix_getaddrinfo "
let getaddrinfo_emulation node service opts = let opt_socktype = ref None and opt_protocol = ref 0 and opt_passive = ref false in List . iter ( function AI_SOCKTYPE s -> opt_socktype := Some s | AI_PROTOCOL p -> opt_protocol := p | AI_PASSIVE -> opt_passive := true | _ -> ( ) ) opts ; let get_port ty kind = if service ...
let getaddrinfo node service opts = try List . rev ( getaddrinfo_system node service opts ) with Invalid_argument _ -> getaddrinfo_emulation node service opts
type name_info = { ni_hostname : string ; ni_service : string }
type getnameinfo_option = NI_NOFQDN | NI_NUMERICHOST | NI_NAMEREQD | NI_NUMERICSERV | NI_DGRAM : sockaddr -> getnameinfo_option list -> name_info = " unix_getnameinfo "
let getnameinfo_emulation addr opts = match addr with | ADDR_UNIX f -> { ni_hostname = " " ; ni_service = f } | ADDR_INET ( a , p ) -> let hostname = try if List . mem NI_NUMERICHOST opts then raise Not_found ; ( gethostbyaddr a ) . h_name with Not_found -> if List . mem NI_NAMEREQD opts then raise Not_found ; string_o...
let getnameinfo addr opts = try getnameinfo_system addr opts with Invalid_argument _ -> getnameinfo_emulation addr opts file_descr -> file_descr -> file_descr -> int = " win_create_process " " win_create_process_native "
let make_cmdline args = String . concat " " ( List . map maybe_quote ( Array . to_list args ) )
let make_process_env env = Array . iter ( fun s -> if String . contains s ' \ 000 ' then raise ( Unix_error ( EINVAL , " " , s ) ) ) env ; String . concat " \ 000 " ( Array . to_list env ) ^ " \ 000 "
let create_process prog args fd1 fd2 fd3 = win_create_process prog ( make_cmdline args ) None fd1 fd2 fd3
let create_process_env prog args env fd1 fd2 fd3 = win_create_process prog ( make_cmdline args ) ( Some ( make_process_env env ) ) fd1 fd2 fd3
type popen_process = Process of in_channel * out_channel | Process_in of in_channel | Process_out of out_channel | Process_full of in_channel * out_channel * in_channel
let popen_processes = ( Hashtbl . create 7 : ( popen_process , int ) Hashtbl . t )
let open_proc prog cmdline optenv proc input output error = let pid = win_create_process prog cmdline optenv input output error in Hashtbl . add popen_processes proc pid
let open_process_cmdline_in prog cmdline = let ( in_read , in_write ) = pipe ~ cloexec : true ( ) in let inchan = in_channel_of_descr in_read in begin try open_proc prog cmdline None ( Process_in inchan ) stdin in_write stderr with e -> close_in inchan ; close in_write ; raise e end ; close in_write ; inchan
let open_process_cmdline_out prog cmdline = let ( out_read , out_write ) = pipe ~ cloexec : true ( ) in let outchan = out_channel_of_descr out_write in begin try open_proc prog cmdline None ( Process_out outchan ) out_read stdout stderr with e -> close_out outchan ; close out_read ; raise e end ; close out_read ; outch...
let open_process_cmdline prog cmdline = let ( in_read , in_write ) = pipe ~ cloexec : true ( ) in let ( out_read , out_write ) = try pipe ~ cloexec : true ( ) with e -> close in_read ; close in_write ; raise e in let inchan = in_channel_of_descr in_read in let outchan = out_channel_of_descr out_write in begin try open_...
let open_process_cmdline_full prog cmdline env = let ( in_read , in_write ) = pipe ~ cloexec : true ( ) in let ( out_read , out_write ) = try pipe ~ cloexec : true ( ) with e -> close in_read ; close in_write ; raise e in let ( err_read , err_write ) = try pipe ~ cloexec : true ( ) with e -> close in_read ; close in_wr...
let open_process_args_in prog args = open_process_cmdline_in prog ( make_cmdline args )
let open_process_args_out prog args = open_process_cmdline_out prog ( make_cmdline args )
let open_process_args prog args = open_process_cmdline prog ( make_cmdline args )
let open_process_args_full prog args = open_process_cmdline_full prog ( make_cmdline args )
let open_process_shell fn cmd = let shell = try Sys . getenv " COMSPEC " with Not_found -> raise ( Unix_error ( ENOEXEC , " open_process_shell " , cmd ) ) in fn shell ( shell ^ " / c " ^ cmd )
let open_process_in cmd = open_process_shell open_process_cmdline_in cmd
let open_process_out cmd = open_process_shell open_process_cmdline_out cmd
let open_process cmd = open_process_shell open_process_cmdline cmd
let open_process_full cmd = open_process_shell open_process_cmdline_full cmd
let find_proc_id fun_name proc = try Hashtbl . find popen_processes proc with Not_found -> raise ( Unix_error ( EBADF , fun_name , " " ) )
let remove_proc_id proc = Hashtbl . remove popen_processes proc
let process_in_pid inchan = find_proc_id " process_in_pid " ( Process_in inchan )
let process_out_pid outchan = find_proc_id " process_out_pid " ( Process_out outchan )
let process_pid ( inchan , outchan ) = find_proc_id " process_pid " ( Process ( inchan , outchan ) )
let process_full_pid ( inchan , outchan , errchan ) = find_proc_id " process_full_pid " ( Process_full ( inchan , outchan , errchan ) )
let close_process_in inchan = let proc = Process_in inchan in let pid = find_proc_id " close_process_in " proc in remove_proc_id proc ; close_in inchan ; snd ( waitpid [ ] pid )
let close_process_out outchan = let proc = Process_out outchan in let pid = find_proc_id " close_process_out " proc in remove_proc_id proc ; close_out outchan ; snd ( waitpid [ ] pid )
let close_process ( inchan , outchan ) = let proc = Process ( inchan , outchan ) in let pid = find_proc_id " close_process " proc in remove_proc_id proc ; close_in inchan ; close_out outchan ; snd ( waitpid [ ] pid )
let close_process_full ( inchan , outchan , errchan ) = let proc = Process_full ( inchan , outchan , errchan ) in let pid = find_proc_id " close_process_full " proc in remove_proc_id proc ; close_in inchan ; close_out outchan ; close_in errchan ; snd ( waitpid [ ] pid ) file_descr list -> file_descr list -> file_descr ...
let open_connection sockaddr = let sock = socket ~ cloexec : true ( domain_of_sockaddr sockaddr ) SOCK_STREAM 0 in try connect sock sockaddr ; ( in_channel_of_descr sock , out_channel_of_descr sock ) with exn -> close sock ; raise exn
let shutdown_connection inchan = shutdown ( descr_of_in_channel inchan ) SHUTDOWN_SEND
let establish_server _server_fun _sockaddr = invalid_arg " Unix . establish_server not implemented "
type terminal_io = { mutable c_ignbrk : bool ; mutable c_brkint : bool ; mutable c_ignpar : bool ; mutable c_parmrk : bool ; mutable c_inpck : bool ; mutable c_istrip : bool ; mutable c_inlcr : bool ; mutable c_igncr : bool ; mutable c_icrnl : bool ; mutable c_ixon : bool ; mutable c_ixoff : bool ; mutable c_opost : bo...
type setattr_when = TCSANOW | TCSADRAIN | TCSAFLUSH
let tcgetattr _fd = invalid_arg " Unix . tcgetattr not implemented "
let tcsetattr _fd _wh = invalid_arg " Unix . tcsetattr not implemented "
let tcsendbreak _fd _n = invalid_arg " Unix . tcsendbreak not implemented "
let tcdrain _fd = invalid_arg " Unix . tcdrain not implemented "
type flush_queue = TCIFLUSH | TCOFLUSH | TCIOFLUSH
let tcflush _fd _q = invalid_arg " Unix . tcflush not implemented "
type flow_action = TCOOFF | TCOON | TCIOFF | TCION
let tcflow _fd _fl = invalid_arg " Unix . tcflow not implemented "
let setsid ( ) = invalid_arg " Unix . setsid not implemented "
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " UnmonitorInstances " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . ren...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " UnmonitorInstancesResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp UnmonitorInstancesResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed UnmonitorInstancesResult . ...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None
let debug = ref false
module Unpack_one = struct type ( ' a , ' state ) unpack_result = [ ` Ok of ' a * int | ` Not_enough_data of ' state * int | ` Invalid_data of Error . t ] type ( ' a , ' state ) unpack = state : ' state -> buf : Bigstring . t -> pos : int -> len : int -> ( ' a , ' state ) unpack_result type ' a t = T : { initial_state ...
type ( ' a , ' state ) alive = { mutable state : ' state ; mutable state_is_initial : bool ; initial_state : ' state ; unpack : ( ( ' a , ' state ) Unpack_one . unpack [ @ sexp . opaque ] ) ; mutable buf : Bigstring . t ; mutable pos : int ; mutable len : int }
type ' a alive_or_dead = | Alive : ( ' a , _ ) alive -> ' a alive_or_dead | Dead of Error . t
type ' a t = { mutable alive_or_dead : ' a alive_or_dead }
let invariant _ t = try match t . alive_or_dead with | Dead _ -> ( ) | Alive alive -> assert ( alive . pos >= 0 ) ; assert ( alive . len >= 0 ) ; if alive . len = 0 then assert ( alive . pos = 0 ) ; if alive . state_is_initial then assert ( phys_equal alive . state alive . initial_state ) ; assert ( alive . pos + alive...
let create ( Unpack_one . T { initial_state ; unpack } ) = { alive_or_dead = Alive { state = initial_state ; state_is_initial = true ; initial_state ; unpack ; buf = Bigstring . create 1 ; pos = 0 ; len = 0 } ; } ; ;
let create_bin_prot bin_prot_reader = create ( Unpack_one . create_bin_prot bin_prot_reader ) ; ;
let is_empty t = match t . alive_or_dead with | Dead error -> Error error | Alive alive -> Ok ( alive . state_is_initial && alive . len = 0 ) ; ;
let is_available t len = let input_start = t . pos + t . len in let available = Bigstring . length t . buf - input_start in available >= len ; ;
let ensure_available t len = if not ( is_available t len ) then begin let new_buf = Bigstring . create ( max ( t . len + len ) ( 2 * Bigstring . length t . buf ) ) in Bigstring . blito ~ src : t . buf ~ src_pos : t . pos ~ src_len : t . len ~ dst : new_buf ( ) ; t . pos <- 0 ; t . buf <- new_buf ; assert ( is_available...
let feed_gen buf_length ( blit_buf_to_bigstring : ( _ , _ ) Blit . blito ) ? pos ? len t buf = if ! debug then invariant ignore t ; match t . alive_or_dead with | Dead e -> Error e | Alive t -> let ( src_pos , src_len ) = Ordered_collection_common . get_pos_len_exn ( ) ? pos ? len ~ total_length ( : buf_length buf ) in...
let feed ? pos ? len t buf = feed_gen Bigstring . length Bigstring . blito ? pos ? len t buf ; ;
let feed_string ? pos ? len t buf = feed_gen String . length Bigstring . From_string . blito ? pos ? len t buf ; ;
let feed_bytes ? pos ? len t buf = feed_gen Bytes . length Bigstring . From_bytes . blito ? pos ? len t buf ; ;
let error t e = t . alive_or_dead <- Dead e ; Error e ; ;
let consume alive ~ num_bytes = alive . pos <- alive . pos + num_bytes ; alive . len <- alive . len - num_bytes ; ; ;
let rec unpack_iter_loop t alive ~ f = if alive . len = 0 then begin alive . pos <- 0 ; Ok ( ) ; end else begin match alive . unpack ~ buf : alive . buf ~ pos : alive . pos ~ len : alive . len ~ state : alive . state with | exception exn -> error t ( Error . create " unpack error " exn [ % sexp_of : Exn . t ] ) | unpac...
let unpack_iter t ~ f = if ! debug then invariant ignore t ; match t . alive_or_dead with | Dead e -> Error e | Alive alive -> unpack_iter_loop t alive ~ f ; ;
let unpack_into t q = unpack_iter t ~ f ( : Queue . enqueue q )