- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Closed
Description
hey, I'm working on trying to make a multi-client network server as my first project in Rust, so I've got this small hello-worldish program:
extern mod extra;
use std::io::{Listener, Acceptor};
use std::io::net::ip::SocketAddr;
use std::io::net::tcp::{TcpListener, TcpStream};
use std::io::timer;
fn main() {
    let addr = from_str::<SocketAddr>("0.0.0.0:3569").unwrap();
    let listener = TcpListener::bind(addr).unwrap();
    let mut acceptor = listener.listen().unwrap();
    loop {
        let mut stream: TcpStream = acceptor.accept().unwrap();
        stream.write_str("hey hi\r\n");
        spawn(proc() {
            loop {
                let mut stream = stream;
                stream.write_str("ping\r\n");
                timer::sleep(1000);
            }
        });
    }
}
it compiles fine, but when I run this program, and connect to it by telnetting to localhost:3569, it prints "hey hi", then one "ping", then crashes.
here's a stack trace:
(gdb) bt
#0  0x00000000004629b4 in io::net::tcp::Writer$TcpStream::write::h3e42059c65c3f43f05au::v0.10.pre ()
#1  0x00000000004064d1 in io::Writer::write_str::hb41c95d4c4ae4cb1aY::v0.0 ()
#2  0x000000000040663e in main::anon::expr_fn::aa ()
#3  0x00000000004c9368 in task::__extensions__::build_start_wrapper::anon::anon::expr_fn::aI ()
#4  0x00000000004a1e33 in rt::task::__extensions__::run::anon::expr_fn::aG ()
#5  0x00000000004a9bec in rust_try ()
#6  0x00000000004a1da2 in rt::task::Task::run::hc9c9660d47e409e7TWaD::v0.10.pre
    ()
#7  0x00000000004c9039 in task::__extensions__::build_start_wrapper::anon::expr_fn::aw ()
#8  0x0000000000000000 in ?? ()
I'm using master as of 3e39e3e.
Metadata
Metadata
Assignees
Labels
No labels