1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//!High level bindings to the lib nng
//!
//!Version corresponds to C library
//!
//!## Features
//!
//!- `http` - Enables http transport;
//!- `tls` - Enables TLS transpor;
//!- `websocket` - Enables websocket transport. Implies `http` feature;
//!- `log` - Enables logging via [log](https://crates.io/crates/log) crate;
//!- `tracing` - Enables logging via [tracing](https://crates.io/crates/tracing) crate.
//!
//!## Usage
//!
//!Basic example of client and server communication
//!
//!```rust
//!use nng_c::{options, Socket, Message, ErrorCode};
//!
//!use core::time;
//!
//!//Feel free to append zero char to avoid unnecessary allocations
//!const ADDR: &str = "ipc://nng-c-example\0";
//!const REQ_TIMEOUT: options::Req = options::Req {
//! resend_time: Some(time::Duration::from_millis(50)),
//! resend_tick: Some(time::Duration::from_millis(1)),
//!};
//!
//!fn server() -> Result<(), ErrorCode> {
//! let server = Socket::rep0()?;
//! server.listen(ADDR.into()).expect("listen");
//!
//! loop {
//! let msg = server.recv_msg()?;
//! let body = msg.body();
//! let msg = core::str::from_utf8(body).expect("utf-8 bytes");
//! match msg {
//! "quit" => break Ok(()),
//! other => {
//! println!("Received bytes(len={})={:?}", other.len(), other);
//! }
//! }
//! }
//!}
//!
//!let server = std::thread::spawn(server);
//!
//!//Wait for thread to spin
//!std::thread::sleep(time::Duration::from_millis(10));
//!
//!let client = Socket::req0().expect("Create client");
//!client.set_opt(REQ_TIMEOUT).expect("Set options");
//!
//!client.connect(ADDR.into()).expect("connect");
//!
//!let mut msg = Message::new().expect("create message");
//!msg.append("ping".as_bytes()).expect("Input bytes");
//!client.send_msg(msg).expect("send message");
//!
//!let mut msg = Message::new().expect("create message");
//!msg.append("quit".as_bytes()).expect("Input bytes");
//!client.send_msg(msg).expect("send quit");
//!
//!server.join().expect("Finish server successfully");
//!```
//Imagine enabling this shit by default
extern crate alloc;
pub use nng_c_sys as sys;
pub use Message;
pub use ;
pub use Socket;