Skip to content

Commit

Permalink
remove a number of warnings. Also changed a number of tests to be mor…
Browse files Browse the repository at this point in the history
…e mac friendly
  • Loading branch information
jstnlef committed Jun 27, 2019
1 parent 1357021 commit 131b146
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 95 deletions.
14 changes: 8 additions & 6 deletions examples/server_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SERVER: &str = "127.0.0.1:12351";

fn server() -> Result<(), ErrorKind> {
let mut socket = Socket::bind(SERVER)?;
let (mut sender, mut receiver) = (socket.get_packet_sender(), socket.get_event_receiver());
let (sender, receiver) = (socket.get_packet_sender(), socket.get_event_receiver());
let _thread = thread::spawn(move || socket.start_polling());

loop {
Expand All @@ -29,10 +29,12 @@ fn server() -> Result<(), ErrorKind> {

println!("Received {:?} from {:?}", msg, ip);

sender.send(Packet::reliable_unordered(
packet.addr(),
"Copy that!".as_bytes().to_vec(),
));
sender
.send(Packet::reliable_unordered(
packet.addr(),
"Copy that!".as_bytes().to_vec(),
))
.expect("This should send");
}
SocketEvent::Timeout(address) => {
println!("Client timed out: {}", address);
Expand Down Expand Up @@ -65,7 +67,7 @@ fn client() -> Result<(), ErrorKind> {
socket.send(Packet::reliable_unordered(
server,
line.clone().into_bytes(),
));
))?;

socket.manual_poll(Instant::now());

Expand Down
5 changes: 2 additions & 3 deletions examples/simple_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
//! 2. setting up client to send data.
//! 3. serialize data to send and deserialize when received.
use bincode::{deserialize, serialize};
use crossbeam_channel::{Receiver, Sender};
use laminar::{ErrorKind, Packet, Socket, SocketEvent};
use laminar::{Packet, Socket, SocketEvent};
use serde_derive::{Deserialize, Serialize};
use std::net::SocketAddr;
use std::{thread, time::Instant};
use std::time::Instant;

/// The socket address of where the server is located.
const SERVER_ADDR: &'static str = "127.0.0.1:12345";
Expand Down
7 changes: 3 additions & 4 deletions examples/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//! 1. sending data
//! 2. receiving data
//! 3. constructing the packet for sending.
use laminar::{Packet, Socket, SocketEvent};
use laminar::{Packet, Result, Socket, SocketEvent};

use std::net::SocketAddr;
use std::thread;

/// The socket address of where the server is located.
const SERVER_ADDR: &'static str = "127.0.0.1:12345";
Expand All @@ -21,14 +20,14 @@ fn server_address() -> SocketAddr {
}

/// This is an example of how to send data to an specific address.
pub fn send_data() {
pub fn send_data() -> Result<()> {
// Setup a udp socket and bind it to the client address.
let mut socket = Socket::bind(client_address()).unwrap();

let packet = construct_packet();

// next send or packet to the endpoint we earlier putted into the packet.
socket.send(packet);
socket.send(packet)
}

/// This is an example of how to receive data over udp.
Expand Down
1 change: 0 additions & 1 deletion src/net/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ mod tests {
use super::{ActiveConnections, Config};
use std::{
sync::Arc,
thread,
time::{Duration, Instant},
};

Expand Down
Loading

0 comments on commit 131b146

Please sign in to comment.