Guest User

Untitled

a guest
Feb 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. let a () =
  2. (* Function A *)
  3. let socket = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
  4. begin
  5. Unix.set_nonblock socket ;
  6. try
  7. Unix.connect
  8. socket
  9. (Unix.ADDR_INET((Unix.gethostbyname "google.com").Unix.h_addr_list.(0),80)) ;
  10. with
  11. Unix.Unix_error(Unix.EWOULDBLOCK, _, _) ->
  12. let _, w, _ = Unix.select [] [socket] [] 3. in
  13. if w = [] then
  14. Printf.printf "Connection timedouti\n" ;
  15. Unix.clear_nonblock socket
  16. end
  17.  
  18. let b () =
  19. (* Function B *)
  20. let socket = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
  21. Unix.connect
  22. socket
  23. (Unix.ADDR_INET((Unix.gethostbyname "google.com").Unix.h_addr_list.(0),80)) ;
  24. let _,w,_ = Unix.select [] [socket] [] 3. in
  25. if w = [] then
  26. Printf.printf "Write timedout!\n"
  27. else
  28. try
  29. ignore(Unix.read socket "foobarlol" 0 4)
  30. with Unix.Unix_error (e,_,_) -> Printf.printf "Unix error: %s\n" (Unix.error_message e)
  31.  
  32. let () = a (); b ()
Add Comment
Please, Sign In to add comment