From 1a574e19d06af412ba1fa07ba83bb81fb8485ca3 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Wed, 21 Feb 2024 10:35:49 +0000 Subject: [PATCH] Illustrate network example --- README.md | 9 +- doc/traces/Makefile | 2 +- doc/traces/net-posix.fxt | Bin 0 -> 3080 bytes doc/traces/net-posix.svg | 831 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 839 insertions(+), 3 deletions(-) create mode 100644 doc/traces/net-posix.fxt create mode 100644 doc/traces/net-posix.svg diff --git a/README.md b/README.md index 79bd33971..84cc71d90 100644 --- a/README.md +++ b/README.md @@ -392,8 +392,8 @@ Here is a client that connects to address `addr` using network `net` and reads a ```ocaml let run_client ~net ~addr = + Switch.run ~name:"client" @@ fun sw -> traceln "Client: connecting to server"; - Switch.run @@ fun sw -> let flow = Eio.Net.connect ~sw net addr in let b = Buffer.create 100 in Eio.Flow.copy flow (Eio.Flow.buffer_sink b); @@ -401,6 +401,7 @@ let run_client ~net ~addr = ``` Note: the `flow` is attached to `sw` and will be closed automatically when it finishes. +We also named the switch here; this will appear in the trace output (see below). This can also be tested on its own using a mock network: @@ -439,7 +440,7 @@ We can now run the client and server together using the real network (in a singl ```ocaml let main ~net ~addr = - Switch.run @@ fun sw -> + Switch.run ~name:"main" @@ fun sw -> let server = Eio.Net.listen net ~sw ~reuse_addr:true ~backlog:5 addr in Fiber.fork_daemon ~sw (fun () -> run_server server); run_client ~net ~addr @@ -460,6 +461,10 @@ the test would never finish. - : unit = () ``` +

+ +

+ See [examples/net](./examples/net/) for a more complete example. ## Design Note: Capabilities diff --git a/doc/traces/Makefile b/doc/traces/Makefile index 81823bc70..1f8a478b1 100644 --- a/doc/traces/Makefile +++ b/doc/traces/Makefile @@ -1,4 +1,4 @@ -all: both-posix.svg cancel-posix.svg switch-mock.svg +all: both-posix.svg cancel-posix.svg switch-mock.svg net-posix.svg %.svg: %.fxt eio-trace render -f "$<" "$@" diff --git a/doc/traces/net-posix.fxt b/doc/traces/net-posix.fxt new file mode 100644 index 0000000000000000000000000000000000000000..bf2dd7edc98353b300a14b366abf706ffc2129f9 GIT binary patch literal 3080 zcmai0OKcle6uq$nsofT*rcIi<36qyki$n~yD*;_nK2^(xrhHmH(PaGU401fycoL^V ztw3sps6doYRlW-r2tT!{CXwxP-+lMq zckX%b%^>vOzjAB{4D`VO0JOruv+XwG4BUV?^qciN@cRMCWYC5F`Pm!)`gogQ16lk7 zuztV>1N|5Q!1H9h+T*Wr3}zuezb1YLZp4`Y(W#ati@~Z0hd~et-o$yl))GO8pwgE` zj~~An|K=>>JzO;p@y8IxqjgQdro@Q94CHVG;G{oq!+pHI9F<5mdV1G)mzbTkRmr3E zS0E2taLfy>8`&8SN3Jz+u&z9)zt*Mm_VB7CD1B=DzrISxuQEFT%CpvIU^Ca+?)Z_n zz&vD#hil)Zc_41-As#m4_kVfV!j&w#ev|yBAw$cFvl35R6P~Kf(^lf?CUU}OBc6^d z814sYf*#}p>&t`Ml@A?PKD1utW8c&1I92X`!iUy@I>^%cFFhmv8lSX7&qnL7;7am1 z9xgTK+BRIaA-f|FSq`o9D^OtmP~YYDQoCiFHFhk*Ab(FnCR@N?S1w9^t^e#Bg0=5h zC->>4H`8@$UpK1Lz&7rK*YIrmGy&_&6w&tL zJCfJHc4o2>)VY2GJJ^2_H@{oAa1h0 zxI-9c2=b(5dk4XT*- zNGJ3oyUcyZb?t`ydbb{4XXDl>)}et>zCpZ3(54GW_#K6%vWzP)YYz*qpd#q}uq%F) zoc;j!GOuIs)MMh;+jr&99+&ZiKhdq)F+c0{p%a>)_#J`wTV2fj?u`@+zr~JV>xE z)BFOc-M}q!-&?naH1Yl{qOG*jjm!J_<#URqA0J)lVy@%wR}@Pf)2|EGI@}od)}eOl zGv)m}_9GpT4o_XuxN?pSyeD`b9IQ1tr$Xylf7#X?bI3Ltfe2oXE7}&McRsH!UzYi# zcL(j7=kTi74UF@7h3`WVo_qA3!RPjcD>APA)VB&cx5qI~@BJ$48HKA~$~?_;ePEjP zMwsrcQZ9`b@`4TSW_k~^VHkw?UBL`=kIzQ6hCg4v4`qi4;27Vp2CnXqd0L;|r?k$A zfBBsoPW$Qkqki`wBXq&c^7}>E?YMq4=hqtiQigU~R{=lwm$YsgN=l}Zs%Y)tgtlwuJNiePFj~@KiqcV=`Lp_W^;dnZ4QYYyj&!Z=k qc(gx0@B|x};&->Y$7P~krulqoN1eF_?rnX)!T$A4;n>}Q%=-s>I+z{+ literal 0 HcmV?d00001 diff --git a/doc/traces/net-posix.svg b/doc/traces/net-posix.svg new file mode 100644 index 000000000..f7ec16cc9 --- /dev/null +++ b/doc/traces/net-posix.svg @@ -0,0 +1,831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +