Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Oct 7, 2024
1 parent 4266c92 commit 6dbc382
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 38 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ jobs:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sctpx"
version = "0.3.0"
version = "0.4.0"
authors = ["FanHui <[email protected]>"]
edition = "2021"
description = "A simple and friendly SCTP wrapper."
Expand All @@ -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"]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.**
Expand Down
5 changes: 1 addition & 4 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
max_width = 79
version = "Two"
comment_width = 79
# error_on_line_overflow = true
max_width = 89
17 changes: 3 additions & 14 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ impl Hdr {

/// sendmsg to server
#[inline(always)]
pub fn sendto_straddr(
&self,
data: &[u8],
server_addr: &str,
) -> Result<usize> {
pub fn sendto_straddr(&self, data: &[u8], server_addr: &str) -> Result<usize> {
server_addr
.parse::<SocketAddr>()
.c(d!())
Expand All @@ -52,11 +48,7 @@ impl Hdr {

/// sendmsg to server
#[inline(always)]
pub fn sendto(
&self,
data: &[u8],
server_addr: SocketAddr,
) -> Result<usize> {
pub fn sendto(&self, data: &[u8], server_addr: SocketAddr) -> Result<usize> {
sendto(
self.fd.as_raw_fd(),
data,
Expand All @@ -68,10 +60,7 @@ impl Hdr {

/// recvmsg from server
#[inline(always)]
pub fn recvfrom(
&self,
data: &mut [u8],
) -> Result<(usize, Option<SockaddrStorage>)> {
pub fn recvfrom(&self, data: &mut [u8]) -> Result<(usize, Option<SockaddrStorage>)> {
recvfrom(self.fd.as_raw_fd(), data).c(d!())
}
}
Expand Down
21 changes: 6 additions & 15 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -41,16 +41,12 @@ impl Hdr {
/// 回调函数可以按需向对端回复消息
#[inline(always)]
pub fn sendto(&self, data: &[u8], peeraddr: &PeerAddr) -> Result<usize> {
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<SockaddrStorage>)> {
fn recvfrom(&self, data: &mut [u8]) -> Result<(usize, Option<SockaddrStorage>)> {
recvfrom(self.fd.as_raw_fd(), data).c(d!())
}
}
Expand Down Expand Up @@ -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)));
}
}
}
Expand All @@ -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<Arc<Hdr>> {
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,
Expand Down
2 changes: 1 addition & 1 deletion tools/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6dbc382

Please sign in to comment.