Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Lwt.Infix
- let program =
- let parent_pid = Unix.getpid () in
- let some_func () =
- Printf.sprintf "Process: %d" (Unix.getpid ())
- |> Lwt_io.printl >>= fun () -> Lwt_io.flush Lwt_io.stdout
- in
- let marshaled = Marshal.to_bytes some_func [Marshal.Closures] in
- Printf.sprintf "Parent pid:%d" parent_pid
- |> Lwt_io.printl >>= fun () ->
- Lwt_io.flush Lwt_io.stdout >>= fun () ->
- let fd = Lwt_unix.socket Lwt_unix.PF_UNIX Lwt_unix.SOCK_STREAM 0 in
- for i = 0 to 3 do
- let pid = Lwt_unix.fork () in
- if pid = 0 then
- Lwt.async (fun () ->
- Lwt_unix.accept fd >>= fun (sock, addr) ->
- let b = Bytes.create (Bytes.length marshaled) in
- Lwt_unix.read sock b 0 (Bytes.length marshaled) >>= fun _ ->
- let func : unit -> unit Lwt.t = Marshal.from_bytes b 0 in
- func ()
- )
- done;
- Lwt_unix.write fd marshaled 0 (Bytes.length marshaled) >>= fun _ ->
- Lwt_unix.sleep 10.0
- let () = Lwt_main.run program
- Parent pid:6159
- Fatal error: exception Unix.Unix_error(Unix.ENOTCONN, "write", "")
- Raised at file "src/core/lwt.ml", line 801, characters 16-23
- Called from file "src/unix/lwt_main.ml", line 34, characters 8-18
- Called from file "example/e.ml", line 148, characters 9-29
- Fatal error: exception Unix.Unix_error(Unix.EINVAL, "accept", "")
- Raised by primitive operation at file "src/unix/lwt_unix.ml", line 1370, characters 50-67
- Called from file "src/unix/lwt_unix.ml", line 551, characters 17-28
- Fatal error: exception Unix.Unix_error(Unix.EINVAL, "accept", "")
- Raised by primitive operation at file "src/unix/lwt_unix.ml", line 1370, characters 50-67
- Called from file "src/unix/lwt_unix.ml", line 551, characters 17-28
- Fatal error: exception Unix.Unix_error(Unix.EINVAL, "accept", "")
- Raised by primitive operation at file "src/unix/lwt_unix.ml", line 1370, characters 50-67
- Called from file "src/unix/lwt_unix.ml", line 551, characters 17-28
- Fatal error: exception Unix.Unix_error(Unix.EINVAL, "accept", "")
- Raised by primitive operation at file "src/unix/lwt_unix.ml", line 1370, characters 50-67
- Called from file "src/unix/lwt_unix.ml", line 551, characters 17-28
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement