@@ -11,16 +11,16 @@ open Effect.Deep
1111type file_descr = Unix .file_descr
1212type sockaddr = Unix .sockaddr
1313type msg_flag = Unix .msg_flag
14- type _ Effect.t + = Fork : (unit -> unit ) -> unit Effect .t
15- type _ Effect.t + = Accept : file_descr -> (file_descr * sockaddr ) Effect .t
14+ type _ eff + = Fork : (unit -> unit ) -> unit eff
15+ type _ eff + = Accept : file_descr -> (file_descr * sockaddr ) eff
1616
17- type _ Effect.t + =
18- | Recv : file_descr * bytes * int * int * msg_flag list -> int Effect .t
17+ type _ eff + =
18+ | Recv : file_descr * bytes * int * int * msg_flag list -> int eff
1919
20- type _ Effect.t + =
21- | Send : file_descr * bytes * int * int * msg_flag list -> int Effect .t
20+ type _ eff + =
21+ | Send : file_descr * bytes * int * int * msg_flag list -> int eff
2222
23- type _ Effect.t + = Sleep : float -> unit Effect .t
23+ type _ eff + = Sleep : float -> unit eff
2424
2525let fork f = perform (Fork f)
2626let accept fd = perform (Accept fd)
@@ -151,56 +151,39 @@ and perform_io st timeout =
151151let run main =
152152 let st = init () in
153153 let rec fork st f =
154- match_with f ()
155- {
156- retc = (fun () -> schedule st);
157- exnc =
158- (fun exn ->
159- print_string (Printexc. to_string exn );
160- schedule st);
161- effc =
162- (fun (type a ) (e : a Effect.t ) ->
163- match e with
164- | Fork f ->
165- Some
166- (fun (k : (a, _) continuation ) ->
167- enqueue_thread st k () ;
168- fork st f)
169- | Accept fd ->
170- Some
171- (fun k ->
172- if poll_rd fd then
173- let res = Unix. accept fd in
174- continue k res
175- else (
176- block_accept st fd k;
177- schedule st))
178- | Recv (fd , buf , pos , len , mode ) ->
179- Some
180- (fun k ->
181- if poll_rd fd then
182- let res = Unix. recv fd buf pos len mode in
183- continue k res
184- else (
185- block_recv st fd buf pos len mode k;
186- schedule st))
187- | Send (fd , buf , pos , len , mode ) ->
188- Some
189- (fun k ->
190- if poll_wr fd then
191- let res = Unix. send fd buf pos len mode in
192- continue k res
193- else (
194- block_send st fd buf pos len mode k;
195- schedule st))
196- | Sleep t ->
197- Some
198- (fun k ->
199- if t < = 0. then continue k ()
200- else (
201- block_sleep st t k;
202- schedule st))
203- | _ -> None );
204- }
154+ match f () with
155+ | () -> schedule st
156+ | exception exn ->
157+ print_string (Printexc. to_string exn );
158+ schedule st
159+ | effect (Fork f ), k ->
160+ enqueue_thread st k () ;
161+ fork st f
162+ | effect (Accept fd ), k ->
163+ if poll_rd fd then
164+ let res = Unix. accept fd in
165+ continue k res
166+ else (
167+ block_accept st fd k;
168+ schedule st)
169+ | effect (Recv (fd , buf , pos , len , mode )), k ->
170+ if poll_rd fd then
171+ let res = Unix. recv fd buf pos len mode in
172+ continue k res
173+ else (
174+ block_recv st fd buf pos len mode k;
175+ schedule st)
176+ | effect (Send (fd , buf , pos , len , mode )), k ->
177+ if poll_wr fd then
178+ let res = Unix. send fd buf pos len mode in
179+ continue k res
180+ else (
181+ block_send st fd buf pos len mode k;
182+ schedule st)
183+ | effect (Sleep t ), k ->
184+ if t < = 0. then continue k ()
185+ else (
186+ block_sleep st t k;
187+ schedule st)
205188 in
206189 fork st main
0 commit comments