diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d54fa2f..dfd9841 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,5 +18,3 @@ jobs: - uses: actions/checkout@v3 - name: Build run: cargo build --verbose - - name: Run tests - run: cargo test --verbose diff --git a/Cargo.toml b/Cargo.toml index 736aaaa..e285f56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sctpx" -version = "0.3.0" +version = "0.4.0" authors = ["FanHui "] edition = "2021" description = "A simple and friendly SCTP wrapper." @@ -13,7 +13,7 @@ repository = "https://github.com/rust-util-collections/sctpx.git" [dependencies] nix = { version = "0.29", features = ["net"] } libc = "0.2" -ruc = "6.0" +ruc = "7.0" [features] default = ["client", "server"] diff --git a/README.md b/README.md index 8939a76..10d9c7e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +![GitHub top language](https://img.shields.io/github/languages/top/rust-util-collections/sctpx) +[![Latest Version](https://img.shields.io/crates/v/sctpx.svg)](https://crates.io/crates/sctpx) +[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/sctpx) +[![Rust](https://github.com/rust-util-collections/sctpx/actions/workflows/rust.yml/badge.svg)](https://github.com/rust-util-collections/sctpx/actions/workflows/rust.yml) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.81+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) + # SCTPx **A friendly rust-library for coding with `SCTP` protocol.** diff --git a/rustfmt.toml b/rustfmt.toml index d3bf8c8..038034f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,4 +1 @@ -max_width = 79 -version = "Two" -comment_width = 79 -# error_on_line_overflow = true +max_width = 89 diff --git a/src/client.rs b/src/client.rs index 67b647d..99c553f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -39,11 +39,7 @@ impl Hdr { /// sendmsg to server #[inline(always)] - pub fn sendto_straddr( - &self, - data: &[u8], - server_addr: &str, - ) -> Result { + pub fn sendto_straddr(&self, data: &[u8], server_addr: &str) -> Result { server_addr .parse::() .c(d!()) @@ -52,11 +48,7 @@ impl Hdr { /// sendmsg to server #[inline(always)] - pub fn sendto( - &self, - data: &[u8], - server_addr: SocketAddr, - ) -> Result { + pub fn sendto(&self, data: &[u8], server_addr: SocketAddr) -> Result { sendto( self.fd.as_raw_fd(), data, @@ -68,10 +60,7 @@ impl Hdr { /// recvmsg from server #[inline(always)] - pub fn recvfrom( - &self, - data: &mut [u8], - ) -> Result<(usize, Option)> { + pub fn recvfrom(&self, data: &mut [u8]) -> Result<(usize, Option)> { recvfrom(self.fd.as_raw_fd(), data).c(d!()) } } diff --git a/src/server.rs b/src/server.rs index ac94695..244c53c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -6,8 +6,8 @@ use nix::{ sys::socket::{ - bind, listen, recvfrom, sendto, setsockopt, socket, sockopt, - AddressFamily, Backlog, MsgFlags, SockFlag, SockType, SockaddrStorage, + bind, listen, recvfrom, sendto, setsockopt, socket, sockopt, AddressFamily, + Backlog, MsgFlags, SockFlag, SockType, SockaddrStorage, }, unistd::close, }; @@ -41,16 +41,12 @@ impl Hdr { /// 回调函数可以按需向对端回复消息 #[inline(always)] pub fn sendto(&self, data: &[u8], peeraddr: &PeerAddr) -> Result { - sendto(self.fd.as_raw_fd(), data, &peeraddr.addr, MsgFlags::empty()) - .c(d!()) + sendto(self.fd.as_raw_fd(), data, &peeraddr.addr, MsgFlags::empty()).c(d!()) } // 接收消息端口必须私有 #[inline(always)] - fn recvfrom( - &self, - data: &mut [u8], - ) -> Result<(usize, Option)> { + fn recvfrom(&self, data: &mut [u8]) -> Result<(usize, Option)> { recvfrom(self.fd.as_raw_fd(), data).c(d!()) } } @@ -92,11 +88,7 @@ pub fn start_server( let mut buf = vec![0; siz].into_boxed_slice(); loop { if let Ok((size, Some(peer))) = info!(hdr.recvfrom(&mut buf)) { - info_omit!(cb( - &buf[0..size], - Arc::clone(&hdr), - PeerAddr::new(peer) - )); + info_omit!(cb(&buf[0..size], Arc::clone(&hdr), PeerAddr::new(peer))); } } } @@ -105,8 +97,7 @@ pub fn start_server( // -@recv_bs: max size of system-buffer for sctp recv-queue // -@keep_alive: enable this will get the effect like TCP-keepalive fn gen_hdr(addr: &str, recv_bs: usize, keep_alive: bool) -> Result> { - let recv_bs = - alt!(recv_bs > RECV_BUF_SIZE_LIMIT, RECV_BUF_SIZE_LIMIT, recv_bs); + let recv_bs = alt!(recv_bs > RECV_BUF_SIZE_LIMIT, RECV_BUF_SIZE_LIMIT, recv_bs); let fd = socket( AddressFamily::Inet, diff --git a/tools/fmt.sh b/tools/fmt.sh index 93a3a7d..d2eb723 100755 --- a/tools/fmt.sh +++ b/tools/fmt.sh @@ -47,4 +47,4 @@ for file in $(find .. -type f \ perl -p -i -e 's/ +$//g' $file done -~/.cargo/bin/cargo +nightly fmt +cargo fmt