[][src]Crate sendmmsg

This crate provides a convenient approach for transmitting multiple messages using one system call (but only on Linux-based operating systems).

Kernel calls might take relatively long time, consequently, calling the same kernel function lots of times will increase CPU load significantly. This is why I have created this library; it simply wraps the sendmmsg kernel function.

Examples

This example sends four messages called data portions to the example.com website using a single system call on an orginary TcpStream:

(examples/sender.rs)

#![feature(iovec)]

use sendmmsg::SendMMsg;
use std::io::IoVec;
use std::net::TcpStream;

fn main() {
   // Specify all the messages you want to send
   let messages = &mut [
       (0, IoVec::new(b"Generals gathered in their masses")),
       (0, IoVec::new(b"Just like witches at black masses")),
       (0, IoVec::new(b"Evil minds that plot destruction")),
       (0, IoVec::new(b"Sorcerers of death's construction")),
   ];

   // Setup the `TcpStream` instance connected to example.com
   let socket = TcpStream::connect("93.184.216.34:80").unwrap();

   // Finally, send all the messages above
   match socket.sendmmsg(messages) {
       Err(error) => eprintln!("An error occurred: {}!", error),
       Ok(packets) => println!("Packets sent: {}", packets),
   }
}

Traits

SendMMsg

A trait which is implemented for UdpSocket and TcpStream, thereby allowing them to send multiple messages using one system call.