File: join_link.ml

package info (click to toggle)
jocaml 4.01.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,736 kB
  • ctags: 23,836
  • sloc: ml: 111,262; ansic: 32,746; sh: 6,057; lisp: 4,230; makefile: 3,861; asm: 3,734; awk: 88; perl: 45; fortran: 21; sed: 19; cs: 9
file content (92 lines) | stat: -rw-r--r-- 2,665 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*            Luc Maranget, projet Moscova, INRIA Rocquencourt         *)
(*                                                                     *)
(*  Copyright 2005 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the Q Public License version 1.0.               *)
(*                                                                     *)
(***********************************************************************)

(* $Id: join_link.ml 10588 2010-06-17 16:37:18Z maranget $ *)

(*DEBUG*)open Join_debug
(*DEBUG*)open Printf

exception Failed

type t =
   {
    outc : out_channel ;
    inc : in_channel ;
    fd : Unix.file_descr ;
  } 


let create fd =
  try
    Unix.set_close_on_exec fd ;
  { outc = Unix.out_channel_of_descr fd ;
    inc  = Unix.in_channel_of_descr fd ;
    fd = fd ; }
  with e ->
(*DEBUG*)debug1 "CREATE" "failed on %s" (Join_misc.exn_to_string e) ;
    match e with
    | Out_of_memory -> raise e
    | _  -> assert false


let output_string { outc = outc } v =
  try
    output_string outc v
  with
  | Sys_error _ as _e ->
(*DEBUG*)debug1 "OUTPUT_STRING"  "failed on %s" (Join_misc.exn_to_string _e) ;
      raise Failed
  | _e ->
(*DEBUG*)debug0 "FATAL OUTPUT_STRING"
(*DEBUG*)  "failed on %s" (Join_misc.exn_to_string _e) ;   
      assert false
 

let flush { outc = outc } =
  try
     flush outc
  with
  | Sys_error _ as _e ->
(*DEBUG*)debug1 "FLUSH"
(*DEBUG*)  "failed on %s" (Join_misc.exn_to_string _e) ;
      raise Failed
  | e ->
(*DEBUG*)debug0 "FATAL FLUSH"
(*DEBUG*)  "failed on %s" (Join_misc.exn_to_string e) ;   
      assert false


let really_input { inc = inc } buff ofs len =
  try
    really_input inc buff ofs len
  with
  | End_of_file|Sys_error _ as _e ->
(*DEBUG*)debug1 "REALLY INPUT"
(*DEBUG*)  "failed on %s" (Join_misc.exn_to_string _e) ;
      raise Failed
  | e ->
(*DEBUG*)debug0 "FATAL REALLY INPUT"
(*DEBUG*)  "failed on %s" (Join_misc.exn_to_string e) ;   
      assert false

let close {fd=fd} =
  try
    Unix.close fd
  with
  | Unix.Unix_error (Unix.EBADF,_,_) as _e ->
(*DEBUG*)debug1 "LINK CLOSE"
(*DEBUG*)  "failed on %s" (Join_misc.exn_to_string _e) ;
      raise Failed
  | e ->
(*DEBUG*)debug0 "IO ERROR IN LINK CLOSE"
(*DEBUG*)  "failed on %s" (Join_misc.exn_to_string e) ;   
      exit 0