Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
grebneerg committed Mar 19, 2019
2 parents 3bf444c + b49795a commit b8ca762
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ impl DSConnection {
.as_slice(),
)
.unwrap();
tcp.write(state.lock().unwrap().match_info.clone().to_packet().as_slice()).unwrap();
tcp.write(
state
.lock()
.unwrap()
.match_info
.clone()
.to_packet()
.as_slice(),
)
.unwrap();

loop {
match receiver_signal.try_recv() {
Expand Down Expand Up @@ -118,9 +127,9 @@ impl DSConnection {

if last.elapsed() >= Duration::from_millis(20) {
last = Instant::now();
let packet = state.lock().unwrap().udp_packet();
let packet = state.lock().unwrap().udp_packet();
match udp.send(packet.as_ref()) {
Ok(s) => {}, // println!("udp sent {:?}", packet),
Ok(s) => {} // println!("udp sent {:?}", packet),
Err(e) => {
if e.kind() != io::ErrorKind::WouldBlock {
if let Err(e) = sender_res.send(Err(e)) {
Expand Down
8 changes: 4 additions & 4 deletions src/messages/ds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod tcp {
use crate::joystick::{AxisType, JoystickType};
use crate::states::MatchType;

use byteorder::{WriteBytesExt, NetworkEndian};
use byteorder::{NetworkEndian, WriteBytesExt};

pub trait Tag {
fn id(&self) -> u8;
Expand All @@ -13,10 +13,10 @@ pub mod tcp {
let mut buf = Vec::new();
buf.push(self.id());
buf.extend(self.as_bytes());

let len = buf.len();
let mut packet = Vec::new();
packet.write_u16::<NetworkEndian>(len as u16);
let mut packet = Vec::new();
packet.write_u16::<NetworkEndian>(len as u16);
packet.extend(buf);

packet
Expand Down

0 comments on commit b8ca762

Please sign in to comment.