Last active
December 20, 2015 01:49
-
-
Save jmgrosen/6051437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main.rs:159:13: 196:5 error: capture of moved value: `chans` | |
main.rs:159 do task::spawn { | |
main.rs:160 let iotask = uv_global_loop::get(); | |
main.rs:161 let localhost = net::ip::v4::parse_addr("127.0.0.1"); | |
main.rs:162 println("um"); | |
main.rs:163 | |
main.rs:164 let listen_result = do net::tcp::listen(localhost, 7654, 1, &iotask, | |
... | |
main.rs:165:54: 195:9 note: `chans` moved into closure environment here because it has type `~fn:Send(extra::net::tcp::TcpNewConnection, std::comm::SharedChan<std::option::Option<extra::net::tcp::TcpErrData>>)`, which is non-copyable (perhaps you meant to use clone()?) | |
main.rs:165 |_| ()) |new_conn, kill_ch| { | |
main.rs:166 let my_chans = chans.clone(); | |
main.rs:167 do task::spawn { | |
main.rs:168 let accept_result = net::tcp::accept(new_conn); | |
main.rs:169 let sock = match accept_result { | |
main.rs:170 Ok(val) => val, | |
... | |
main.rs:165:54: 195:9 error: capture of moved value: `chans` | |
main.rs:165 |_| ()) |new_conn, kill_ch| { | |
main.rs:166 let my_chans = chans.clone(); | |
main.rs:167 do task::spawn { | |
main.rs:168 let accept_result = net::tcp::accept(new_conn); | |
main.rs:169 let sock = match accept_result { | |
main.rs:170 Ok(val) => val, | |
... | |
main.rs:165:54: 195:9 note: `chans` moved into closure environment here because it has type `~fn:Send(extra::net::tcp::TcpNewConnection, std::comm::SharedChan<std::option::Option<extra::net::tcp::TcpErrData>>)`, which is non-copyable (perhaps you meant to use clone()?) | |
main.rs:165 |_| ()) |new_conn, kill_ch| { | |
main.rs:166 let my_chans = chans.clone(); | |
main.rs:167 do task::spawn { | |
main.rs:168 let accept_result = net::tcp::accept(new_conn); | |
main.rs:169 let sock = match accept_result { | |
main.rs:170 Ok(val) => val, | |
... | |
error: aborting due to 2 previous errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod extra; | |
use std::comm; | |
use std::task; | |
use extra::net; | |
use extra::uv_global_loop; | |
use std::uint; | |
fn start_server(leds: u8) -> ~[comm::Port<(f32, f32, f32)>] { | |
let mut ports: ~[comm::Port<(f32, f32, f32)>] = ~[]; | |
let mut chans: ~[comm::SharedChan<(f32, f32, f32)>] = ~[]; | |
for uint::range(0, leds as uint) |_| { | |
let (port, chan) = comm::stream(); | |
ports.push(port); | |
chans.push(comm::SharedChan::new(chan)); | |
} | |
let chans = chans; | |
do task::spawn { | |
let iotask = uv_global_loop::get(); | |
let localhost = net::ip::v4::parse_addr("127.0.0.1"); | |
println("um"); | |
let listen_result = do net::tcp::listen(localhost, 7654, 1, &iotask, | |
|_| ()) |new_conn, kill_ch| { | |
let my_chans = chans.clone(); | |
do task::spawn { | |
let accept_result = net::tcp::accept(new_conn); | |
let sock = match accept_result { | |
Ok(val) => val, | |
Err(error) => { | |
kill_ch.send(Some(error)); | |
fail!("Socket error") | |
} | |
}; | |
printfln!("Connection from %s", net::ip::format_addr(&sock.get_peer_addr())); | |
let sock_buf = net::tcp::socket_buf(sock); | |
while true { | |
let leds = sock_buf.read_byte(); | |
if leds < 0 { | |
kill_ch.send(None); | |
fail!("Socket error") | |
} | |
for uint::range(0, leds as uint) |_| { | |
let bytes = sock_buf.read_bytes(4); | |
let led = bytes[0]; | |
let r: f32 = (bytes[1] as f32) / 255.0f32; | |
let g: f32 = (bytes[2] as f32) / 255.0f32; | |
let b: f32 = (bytes[3] as f32) / 255.0f32; | |
printfln!("Changing LED #%? to (%?, %?, %?)", led, r, g, b); | |
my_chans[led].send((r, g, b)); | |
} | |
} | |
} | |
}; | |
} | |
return ports; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment