mirror of
https://github.com/c-cube/nanoev.git
synced 2025-12-05 19:00:35 -05:00
add Nanoev_picos.Net with send/recv functions
This commit is contained in:
parent
00c845ec8d
commit
0f8e8797e8
4 changed files with 28 additions and 3 deletions
|
|
@ -4,5 +4,6 @@ include Base
|
||||||
module Global_ev = Global_ev
|
module Global_ev = Global_ev
|
||||||
module IO_in = IO_in
|
module IO_in = IO_in
|
||||||
module IO_out = IO_out
|
module IO_out = IO_out
|
||||||
|
module Net = Net
|
||||||
module Net_client = Net_client
|
module Net_client = Net_client
|
||||||
module Net_server = Net_server
|
module Net_server = Net_server
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,6 @@ end
|
||||||
|
|
||||||
module IO_in = IO_in
|
module IO_in = IO_in
|
||||||
module IO_out = IO_out
|
module IO_out = IO_out
|
||||||
|
module Net = Net
|
||||||
module Net_client = Net_client
|
module Net_client = Net_client
|
||||||
module Net_server = Net_server
|
module Net_server = Net_server
|
||||||
|
|
|
||||||
11
src/picos/net.ml
Normal file
11
src/picos/net.ml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
let[@inline] send sock buf i len ~flags : int =
|
||||||
|
Base.Raw.retry_write sock (fun () -> Unix.send sock buf i len flags)
|
||||||
|
|
||||||
|
let[@inline] sendto sock ~addr ~flags buf i len : int =
|
||||||
|
Base.Raw.retry_write sock (fun () -> Unix.sendto sock buf i len flags addr)
|
||||||
|
|
||||||
|
let[@inline] recv sock buf i len ~flags : int =
|
||||||
|
Base.Raw.retry_read sock (fun () -> Unix.recv sock buf i len flags)
|
||||||
|
|
||||||
|
let[@inline] recvfrom sock buf i len ~flags : int * Unix.sockaddr =
|
||||||
|
Base.Raw.retry_read sock (fun () -> Unix.recvfrom sock buf i len flags)
|
||||||
|
|
@ -159,7 +159,12 @@ let wakeup_from_outside (self : st) : unit =
|
||||||
let rec perform_cbs ~closed = function
|
let rec perform_cbs ~closed = function
|
||||||
| Nil -> ()
|
| Nil -> ()
|
||||||
| Sub (x, y, f, tail) ->
|
| Sub (x, y, f, tail) ->
|
||||||
f ~closed x y;
|
(try f ~closed x y
|
||||||
|
with exn ->
|
||||||
|
let bt = Printexc.get_raw_backtrace () in
|
||||||
|
Printf.eprintf "nanoev-posix: uncaught error %s\n%s%!"
|
||||||
|
(Printexc.to_string exn)
|
||||||
|
(Printexc.raw_backtrace_to_string bt));
|
||||||
perform_cbs ~closed tail
|
perform_cbs ~closed tail
|
||||||
|
|
||||||
(** Change the event loop right now. This must be called only from the owner
|
(** Change the event loop right now. This must be called only from the owner
|
||||||
|
|
@ -320,8 +325,15 @@ let step (self : st) : unit =
|
||||||
let (Timer t) = Heap.peek_min_exn self.timer in
|
let (Timer t) = Heap.peek_min_exn self.timer in
|
||||||
if t.deadline <= now then (
|
if t.deadline <= now then (
|
||||||
ignore (Heap.pop_min_exn self.timer : timer_ev);
|
ignore (Heap.pop_min_exn self.timer : timer_ev);
|
||||||
t.f t.x t.y;
|
try
|
||||||
true
|
t.f t.x t.y;
|
||||||
|
true
|
||||||
|
with exn ->
|
||||||
|
let bt = Printexc.get_raw_backtrace () in
|
||||||
|
Printf.eprintf "nanoev-posix: uncaught error %s in timer\n%s%!"
|
||||||
|
(Printexc.to_string exn)
|
||||||
|
(Printexc.raw_backtrace_to_string bt);
|
||||||
|
false
|
||||||
) else
|
) else
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue