On 10/24/2012 12:41 AM, [email protected] wrote:
Hi,
I'm starting with rust, although I've been looking inside for a while
its the first time I try writing real rust code.
So, I pulled from master yesterday and wrote this simple server
http://pastebin.com/MMiNpXYG

No tasks, no concurrency, a single-threaded, single-tasked server, that
to my eyes should be able to handle one client after another, however, I
seem to be unable to see any other client than the first one in the
server, netcat does not complain but listen.rs <http://listen.rs> does
not see the new client.
Am I doing anything wrong?

AFAIK, rust is not going to support traditional socket handling,
everything is going to go over libuv, is this statement correct?


Yes, this is correct.

Ok, take this with a grain of salt as I haven't tried to write a server with std::net yet, but I think you need to spawn a new task in the connect callback.

For reference, here is the server test case in net::tcp:

https://github.com/mozilla/rust/blob/incoming/src/libstd/net_tcp.rs#L1560

In the connect callback it looks like it spawns a new task and waits for it to accept the connection. After the connection is accepted the child task handles the connection and the original task continues to listen for additional connections.

As far as BSD sockets, there are bindings here: https://github.com/jdm/rust-socket/

As indicated elsewhere in this thread, when using sockets you have to be aware of the blocking. Specifically, you should start a new scheduler to make the blocking calls on, like `do task().sched_mode(SingleThreaded).spawn {`.

One thing to be aware of when dealing with schedulers is that `spawn` always creates tasks on the *current* scheduler, so if you create a scheduler with the intent of blocking, then spawn additional tasks from that scheduler, they will end up blocking as well. This is a major hazard, should be fixed eventually.


_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to