mozilla/rust — pull request #3815 by luqmana (2012-10-19 23:36:10+00:00)
Title: uv: implement a way to get client's ip/port.

Can now get the remote ip address and port of a client upon accepting.

Quick example:

```rust
extern mod std;

use core::comm;
use std::uv;
use std::net::{ip, tcp};
use std::uv::*;

fn main() {

let iotask = uv::global_loop::get();
let addr = ip::v4::parse_addr("0.0.0.0");
let port = 4000;

tcp::listen(addr, port, 128u, iotask,
|kill_ch| {
info!("Listening on %s:%u.", ip::format_addr(&addr), port);
},
|conn, kill_ch| {
do task::spawn_sched(task::ThreadPerCore) {
match tcp::accept(conn) {
result::Ok(move sock) => {

let addr = sock.getpeername();
info!("accept %s:%u", ip::format_addr(&addr),
ip::get_port(&addr));

}
result::Err(move e) => {
comm::send(kill_ch, Some(e));
}
}
}
}
);

}
```