Skip to content

Commit d34a267

Browse files
committedAug 30, 2023
updated build info and example
1 parent c61bc12 commit d34a267

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed
 

‎README.md

+31-9
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,42 @@ Key features:
1616
`zephyr` applications center around an event loop which drives asynchronous logic:
1717

1818
```cpp
19-
ze::event_loop loop;
19+
Task<int> co_echo(std::shared_ptr<io_uring>& handle) {
20+
void* buf;
21+
TcpListener listener = TcpListener();
22+
TcpStream stream_ = TcpStream();
2023

21-
auto xdp = ze::af_xdp_socket("eth0");
22-
xdp.attach_bpf("filter.o");
24+
listener.bind_socket("127.0.0.1", htons(3344));
25+
26+
listener.listen_socket(1024);
2327

24-
while (true) {
25-
auto [pkt, meta] = co_await xdp.recv();
26-
27-
// process packet
28-
29-
co_await xdp.send(pkt);
28+
co_await listener.async_accept(handle, &stream_);
29+
30+
if(posix_memalign(&buf, 1024, 1024))
31+
co_return 1;
32+
33+
while(1) {
34+
int n = co_await stream_.async_recv(handle, buf, 1024);
35+
36+
if (n == 0) break;
37+
38+
co_await stream_.async_send(handle, buf, n);
39+
}
40+
41+
co_return 0;
3042
}
3143
```
3244
45+
## Build
46+
```shell
47+
git clone https://github.com/g-tejas/zephyr
48+
cd zephyr
49+
git submodule update --init
50+
51+
make # build zephyr.so
52+
make example # build examples
53+
```
54+
3355
The AF_XDP socket and BPF integration allows building high performance network functions like load balancers, firewalls, NATs etc without kernel involvement.
3456

3557
`zephyr` provides the core asynchronous infrastructure to leverage modern Linux features like io_uring, eBPF, AF_XDP for constructing fast and scalable network services in C++20.

0 commit comments

Comments
 (0)