From bafd9f36b7e275cb553da9c4512c67c1f0dc243d Mon Sep 17 00:00:00 2001 From: Pierre-Henri Symoneaux Date: Thu, 12 May 2016 21:45:08 +0200 Subject: [PATCH] Fixes #4 --- Cargo.toml | 2 +- examples/listener.rs | 6 +++--- examples/one_to_many.rs | 10 +++++----- examples/stream.rs | 10 +++++----- src/lib.rs | 4 +++- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1cd68b..b07e5a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rust-sctp" -version = "0.0.4" +version = "0.0.5" description = "High level SCTP networking library" repository = "https://github.com/phsym/rust-sctp" documentation = "http://phsym.github.io/rust-sctp" diff --git a/examples/listener.rs b/examples/listener.rs index 9f67f54..0335a80 100644 --- a/examples/listener.rs +++ b/examples/listener.rs @@ -2,9 +2,9 @@ extern crate sctp; use sctp::*; fn main() { -// match SctpListener::bind("0.0.0.0:3868") { - match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) { - Ok(serv) => { + match SctpListener::bind("0.0.0.0:3868") { +// match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) { + Ok(serv) => { println!("bound to {:?}", serv.local_addrs().unwrap()); // serv.set_timeout(5).unwrap(); match serv.accept() { diff --git a/examples/one_to_many.rs b/examples/one_to_many.rs index ff346a4..56fbfee 100644 --- a/examples/one_to_many.rs +++ b/examples/one_to_many.rs @@ -3,20 +3,20 @@ use sctp::*; fn main() { // Create a new Sctp endpoint, and bind it to one or more socket addresses -// let sock = match SctpEndpoint::bind("0.0.0.0:3868") { - let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) { + let sock = match SctpEndpoint::bind("0.0.0.0:3868") { +// let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) { Ok(s) => s, Err(e) => panic!("{:?}", e.kind()) }; println!("Bound to {:?}", sock.local_addrs().unwrap()); - + let mut buf = [0u8; 1024]; - + // Read a message match sock.recv_from(&mut buf) { Ok((len, stream, addr)) => println!("Received {} bytes from {} on stream {} from {}", len, addr, stream, addr), Err(e) => println!("{:?}", e.kind()) }; - + sock.send_to(&mut buf, "191.168.1.2:3868", 6).unwrap(); } diff --git a/examples/stream.rs b/examples/stream.rs index a9ceb4e..77df794 100644 --- a/examples/stream.rs +++ b/examples/stream.rs @@ -5,23 +5,23 @@ use std::io::prelude::*; fn main() { // Create a new one-to-one stream -// match SctpStream::connect("127.0.0.1:3868") { - match SctpStream::connectx(&["10.0.2.15:3868", "127.0.0.1:3868"]) { + match SctpStream::connect("127.0.0.1:3868") { +// match SctpStream::connectx(&["10.0.2.15:3868", "127.0.0.1:3868"]) { Err(e) => println!("{:?}", e.kind()), Ok(mut peer) => { // Set SCTP no delay println!("{}", peer.has_nodelay().unwrap()); peer.set_nodelay(true).unwrap(); println!("{}", peer.has_nodelay().unwrap()); - + // Set socket send buffer size let oldsize = peer.get_buffer_size(SoDirection::Send).unwrap(); peer.set_buffer_size(SoDirection::Send, 4096).unwrap(); println!("Set send buffer size to {} (was : {})", peer.get_buffer_size(SoDirection::Send).unwrap(), oldsize); - + println!("Setting read timeout to 10 s"); peer.set_timeout(SoDirection::Receive, 10).unwrap(); - + // Write a message using the io::Write trait peer.write_all("foo bar\n".as_bytes()).unwrap(); // Write a message on stream 6 diff --git a/src/lib.rs b/src/lib.rs index 69cc6cd..e3335ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -201,8 +201,9 @@ impl SctpEndpoint { /// Create a one-to-many SCTP endpoint bound to a single address pub fn bind(address: A) -> Result { let raw_addr = try!(SocketAddr::from_addr(&address)); - let sock = try!(SctpSocket::new(raw_addr.family(), SOCK_STREAM)); + let sock = try!(SctpSocket::new(raw_addr.family(), SOCK_SEQPACKET)); try!(sock.bind(raw_addr)); + try!(sock.listen(-1)); return Ok(SctpEndpoint(sock)); } @@ -338,6 +339,7 @@ impl SctpListener { let raw_addr = try!(SocketAddr::from_addr(&address)); let sock = try!(SctpSocket::new(raw_addr.family(), SOCK_STREAM)); try!(sock.bind(raw_addr)); + try!(sock.listen(-1)); return Ok(SctpListener(sock)); }