Skip to content
Snippets Groups Projects
Commit f874c182 authored by Covertness's avatar Covertness
Browse files

support windows

parent 430bdf5b
No related branches found
No related tags found
No related merge requests found
[package]
name = "coap"
version = "0.3.0"
version = "0.3.1"
description = "A CoAP library"
readme = "README.md"
documentation = "http://covertness.github.io/coap-rs/coap/index.html"
......@@ -12,8 +12,7 @@ keywords = ["CoAP"]
[dependencies]
bincode = "0.3.0"
rustc-serialize = "0.3"
bytes = "0.2.11"
mio = "0.4"
mio = "0.5"
threadpool = "0.1"
url = "0.2.36"
num = "0.1"
......
......@@ -25,7 +25,8 @@ fn main() {
},
Err(e) => {
match e.kind() {
ErrorKind::WouldBlock => println!("Request timeout"),
ErrorKind::WouldBlock => println!("Request timeout"), // Unix
ErrorKind::TimedOut => println!("Request timeout"), // Windows
_ => println!("Request error: {:?}", e),
}
}
......
......@@ -191,6 +191,10 @@ mod test {
server.handle(request_handler).unwrap();
let error = CoAPClient::request_with_timeout("coap://127.0.0.1:5684/Rust", Some(Duration::new(1, 0))).unwrap_err();
if cfg!(windows) {
assert_eq!(error.kind(), ErrorKind::TimedOut);
} else {
assert_eq!(error.kind(), ErrorKind::WouldBlock);
}
}
}
\ No newline at end of file
......@@ -66,7 +66,6 @@
extern crate bincode;
extern crate rustc_serialize;
extern crate bytes;
extern crate mio;
extern crate threadpool;
extern crate url;
......
......@@ -7,7 +7,6 @@ use mio::udp::UdpSocket;
use packet::Packet;
use client::CoAPClient;
use threadpool::ThreadPool;
use bytes::RingBuf;
const DEFAULT_WORKER_NUM: usize = 4;
......@@ -51,12 +50,12 @@ impl<H: CoAPHandler + 'static> Handler for UdpHandler<H> {
fn ready(&mut self, _: &mut EventLoop<UdpHandler<H>>, _: Token, events: EventSet) {
if events.is_readable() {
let coap_handler = self.coap_handler;
let mut buf = RingBuf::new(1500);
let mut buf = [0; 1500];
match self.socket.recv_from(&mut buf) {
Ok(Some(src)) => {
Ok(Some((nread, src))) => {
self.thread_pool.execute(move || {
match Packet::from_bytes(buf.bytes()) {
match Packet::from_bytes(&buf[..nread]) {
Ok(packet) => {
let client = CoAPClient::new(src).unwrap();
coap_handler.handle(packet, client);
......@@ -112,7 +111,7 @@ impl CoAPServer {
let thread = thread::spawn(move || {
let thread_pool = ThreadPool::new(worker_num);
let mut event_loop = EventLoop::new().unwrap();
event_loop.register(&socket, Token(0)).unwrap();
event_loop.register(&socket, Token(0), EventSet::readable(), PollOpt::edge()).unwrap();
tx.send(event_loop.channel()).unwrap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment