Hi everybody, after using Rust for the last few months to get used to it (I really love it), I recently started to play around with the new I/O, especially the networking stuff. I'd say that I'm familiar with how std::rt.:io, std::task and std::comm works. However I'm not sure how I should handle multiple I/O streams.
Let's say I'm building a simple chat server where people can connect on a TCP port, set a name and broadcast messages to everyone else. For each accepted incoming stream, I'd spawn a new task and pass the stream to it. Or actually I'd create a struct Connection that contains the stream and connection related information, like the user's name. Every child task would run a loop that reads a line from its stream and processes it. It should either broadcast to all other connections or do something else like setting the name. How can one connection write stuff to the others if it doesn't know about them? If I use a chan/port for every connection to report text to be broadcasted back to the main task, the broadcast needs to take place in the main task. But the main task can not hold a list of connections since every connection has moved to its own task where the reading loop takes place. There could be a second chan/port for every connection that allows the main task to send something to a connection, but how would a connection's task be supposed to recv from the port when it's generally waiting to read from the stream most time? I'm also unsure how the main task should be able to iterate all connection, e.g. if somebody wants to list all connected users. I'd appreciate any hint on how this can be done the Rust-way. (I thereby want to prevent using @-boxes at all) Thanks, Andreas
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev