1- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+ // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22// file at the top-level directory of this distribution and at
33// http://rust-lang.org/COPYRIGHT.
44//
@@ -43,7 +43,7 @@ extern mod rustrt {
4343/**
4444 * Encapsulates an open TCP/IP connection through libuv
4545 *
46- * `tcp_socket ` is non-copyable/sendable and automagically handles closing the
46+ * `TcpSocket ` is non-copyable/sendable and automagically handles closing the
4747 * underlying libuv data structures when it goes out of scope. This is the
4848 * data structure that is used for read/write operations over a TCP stream.
4949 */
@@ -66,10 +66,10 @@ pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket {
6666}
6767
6868/**
69- * A buffered wrapper for `net::tcp::tcp_socket `
69+ * A buffered wrapper for `net::tcp::TcpSocket `
7070 *
7171 * It is created with a call to `net::tcp::socket_buf()` and has impls that
72- * satisfy both the `io::reader ` and `io::writer ` traits.
72+ * satisfy both the `io::Reader ` and `io::Writer ` traits.
7373 */
7474pub struct TcpSocketBuf {
7575 data : @TcpBufferedSocketData ,
@@ -89,7 +89,7 @@ pub struct TcpErrData {
8989 err_msg : ~str ,
9090}
9191
92- /// Details returned as part of a `result::err ` result from `tcp::listen`
92+ /// Details returned as part of a `Result::Err ` result from `tcp::listen`
9393pub enum TcpListenErrData {
9494 /**
9595 * Some unplanned-for error. The first and second fields correspond
@@ -116,7 +116,7 @@ pub enum TcpListenErrData {
116116 */
117117 AccessDenied
118118}
119- /// Details returned as part of a `result::err ` result from `tcp::connect`
119+ /// Details returned as part of a `Result::Err ` result from `tcp::connect`
120120pub enum TcpConnectErrData {
121121 /**
122122 * Some unplanned-for error. The first and second fields correspond
@@ -139,9 +139,9 @@ pub enum TcpConnectErrData {
139139 * # Returns
140140 *
141141 * A `result` that, if the operation succeeds, contains a
142- * `net::net::tcp_socket ` that can be used to send and receive data to/from
142+ * `net::net::TcpSocket ` that can be used to send and receive data to/from
143143 * the remote host. In the event of failure, a
144- * `net::tcp::tcp_connect_err_data ` instance will be returned
144+ * `net::tcp::TcpConnectErrData ` instance will be returned
145145 */
146146pub fn connect ( input_ip : ip:: IpAddr , port : uint ,
147147 iotask : & IoTask )
@@ -288,14 +288,14 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
288288 *
289289 * # Arguments
290290 *
291- * * sock - a `tcp_socket ` to write to
291+ * * sock - a `TcpSocket ` to write to
292292 * * raw_write_data - a vector of `~[u8]` that will be written to the stream.
293293 * This value must remain valid for the duration of the `write` call
294294 *
295295 * # Returns
296296 *
297- * A `result ` object with a `nil ` value as the `ok ` variant, or a
298- * `tcp_err_data ` value as the `err ` variant
297+ * A `Result ` object with a `() ` value as the `Ok ` variant, or a
298+ * `TcpErrData ` value as the `Err ` variant
299299 */
300300pub fn write ( sock : & TcpSocket , raw_write_data : ~[ u8 ] )
301301 -> result:: Result < ( ) , TcpErrData > {
@@ -306,35 +306,35 @@ pub fn write(sock: &TcpSocket, raw_write_data: ~[u8])
306306}
307307
308308/**
309- * Write binary data to tcp stream; Returns a `future::future ` value
309+ * Write binary data to tcp stream; Returns a `future::Future ` value
310310 * immediately
311311 *
312312 * # Safety
313313 *
314314 * This function can produce unsafe results if:
315315 *
316316 * 1. the call to `write_future` is made
317- * 2. the `future::future ` value returned is never resolved via
318- * `future ::get`
319- * 3. and then the `tcp_socket ` passed in to `write_future` leaves
317+ * 2. the `future::Future ` value returned is never resolved via
318+ * `Future ::get`
319+ * 3. and then the `TcpSocket ` passed in to `write_future` leaves
320320 * scope and is destructed before the task that runs the libuv write
321321 * operation completes.
322322 *
323323 * As such: If using `write_future`, always be sure to resolve the returned
324- * `future ` so as to ensure libuv doesn't try to access a released write
324+ * `Future ` so as to ensure libuv doesn't try to access a released write
325325 * handle. Otherwise, use the blocking `tcp::write` function instead.
326326 *
327327 * # Arguments
328328 *
329- * * sock - a `tcp_socket ` to write to
329+ * * sock - a `TcpSocket ` to write to
330330 * * raw_write_data - a vector of `~[u8]` that will be written to the stream.
331331 * This value must remain valid for the duration of the `write` call
332332 *
333333 * # Returns
334334 *
335- * A `future ` value that, once the `write` operation completes, resolves to a
336- * `result ` object with a `nil` value as the `ok ` variant, or a `tcp_err_data `
337- * value as the `err ` variant
335+ * A `Future ` value that, once the `write` operation completes, resolves to a
336+ * `Result ` object with a `nil` value as the `Ok ` variant, or a `TcpErrData `
337+ * value as the `Err ` variant
338338 */
339339pub fn write_future ( sock : & TcpSocket , raw_write_data : ~[ u8 ] )
340340 -> future:: Future < result:: Result < ( ) , TcpErrData > > {
@@ -353,14 +353,14 @@ pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8])
353353 *
354354 * # Arguments
355355 *
356- * * sock -- a `net::tcp::tcp_socket ` for the connection to read from
356+ * * sock -- a `net::tcp::TcpSocket ` for the connection to read from
357357 *
358358 * # Returns
359359 *
360- * * A `result ` instance that will either contain a
361- * `core::comm::port<tcp_read_result> ` that the user can read (and
362- * optionally, loop on) from until `read_stop` is called, or a
363- * `tcp_err_data ` record
360+ * * A `Result ` instance that will either contain a
361+ * `core::comm::Port<Result<~[u8], TcpErrData>> ` that the user can read
362+ * (and * optionally, loop on) from until `read_stop` is called, or a
363+ * `TcpErrData ` record
364364 */
365365pub fn read_start ( sock : & TcpSocket )
366366 -> result:: Result < @Port <
@@ -376,7 +376,7 @@ pub fn read_start(sock: &TcpSocket)
376376 *
377377 * # Arguments
378378 *
379- * * `sock` - a `net::tcp::tcp_socket ` that you wish to stop reading on
379+ * * `sock` - a `net::tcp::TcpSocket ` that you wish to stop reading on
380380 */
381381pub fn read_stop ( sock : & TcpSocket ) ->
382382 result:: Result < ( ) , TcpErrData > {
@@ -387,17 +387,17 @@ pub fn read_stop(sock: &TcpSocket) ->
387387}
388388
389389/**
390- * Reads a single chunk of data from `tcp_socket `; block until data/error
390+ * Reads a single chunk of data from `TcpSocket `; block until data/error
391391 * recv'd
392392 *
393393 * Does a blocking read operation for a single chunk of data from a
394- * `tcp_socket ` until a data arrives or an error is received. The provided
394+ * `TcpSocket ` until a data arrives or an error is received. The provided
395395 * `timeout_msecs` value is used to raise an error if the timeout period
396396 * passes without any data received.
397397 *
398398 * # Arguments
399399 *
400- * * `sock` - a `net::tcp::tcp_socket ` that you wish to read from
400+ * * `sock` - a `net::tcp::TcpSocket ` that you wish to read from
401401 * * `timeout_msecs` - a `uint` value, in msecs, to wait before dropping the
402402 * read attempt. Pass `0u` to wait indefinitely
403403 */
@@ -408,31 +408,31 @@ pub fn read(sock: &TcpSocket, timeout_msecs: uint)
408408}
409409
410410/**
411- * Reads a single chunk of data; returns a `future::future <~[u8]>`
411+ * Reads a single chunk of data; returns a `future::Future <~[u8]>`
412412 * immediately
413413 *
414414 * Does a non-blocking read operation for a single chunk of data from a
415- * `tcp_socket ` and immediately returns a `future ` value representing the
416- * result. When resolving the returned `future `, it will block until data
415+ * `TcpSocket ` and immediately returns a `Future ` value representing the
416+ * result. When resolving the returned `Future `, it will block until data
417417 * arrives or an error is received. The provided `timeout_msecs`
418418 * value is used to raise an error if the timeout period passes without any
419419 * data received.
420420 *
421421 * # Safety
422422 *
423423 * This function can produce unsafe results if the call to `read_future` is
424- * made, the `future::future ` value returned is never resolved via
425- * `future ::get`, and then the `tcp_socket ` passed in to `read_future` leaves
424+ * made, the `future::Future ` value returned is never resolved via
425+ * `Future ::get`, and then the `TcpSocket ` passed in to `read_future` leaves
426426 * scope and is destructed before the task that runs the libuv read
427427 * operation completes.
428428 *
429429 * As such: If using `read_future`, always be sure to resolve the returned
430- * `future ` so as to ensure libuv doesn't try to access a released read
430+ * `Future ` so as to ensure libuv doesn't try to access a released read
431431 * handle. Otherwise, use the blocking `tcp::read` function instead.
432432 *
433433 * # Arguments
434434 *
435- * * `sock` - a `net::tcp::tcp_socket ` that you wish to read from
435+ * * `sock` - a `net::tcp::TcpSocket ` that you wish to read from
436436 * * `timeout_msecs` - a `uint` value, in msecs, to wait before dropping the
437437 * read attempt. Pass `0u` to wait indefinitely
438438 */
@@ -445,7 +445,7 @@ fn read_future(sock: &TcpSocket, timeout_msecs: uint)
445445}
446446
447447/**
448- * Bind an incoming client connection to a `net::tcp::tcp_socket `
448+ * Bind an incoming client connection to a `net::tcp::TcpSocket `
449449 *
450450 * # Notes
451451 *
@@ -461,57 +461,57 @@ fn read_future(sock: &TcpSocket, timeout_msecs: uint)
461461 *
462462 * This implies that a port/chan pair must be used to make sure that the
463463 * `new_connect_cb` call blocks until an attempt to create a
464- * `net::tcp::tcp_socket ` is completed.
464+ * `net::tcp::TcpSocket ` is completed.
465465 *
466466 * # Example
467467 *
468468 * Here, the `new_conn` is used in conjunction with `accept` from within
469469 * a task spawned by the `new_connect_cb` passed into `listen`
470470 *
471471 * ~~~~~~~~~~~
472- * net::tcp::listen(remote_ip, remote_port, backlog)
472+ * do net::tcp::listen(remote_ip, remote_port, backlog, iotask,
473473 * // this callback is ran once after the connection is successfully
474474 * // set up
475- * { |kill_ch|
475+ * |kill_ch| {
476476 * // pass the kill_ch to your main loop or wherever you want
477477 * // to be able to externally kill the server from
478- * }
478+ * })
479479 * // this callback is ran when a new connection arrives
480- * {|new_conn, kill_ch|
481- * let cont_po = core::comm::port::<Option<tcp_err_data>>();
482- * let cont_ch = core::comm::chan(cont_po);
483- * task::spawn {||
480+ * |new_conn, kill_ch| {
481+ * let (cont_po, cont_ch) = comm::stream::<option::Option<TcpErrData>>();
482+ * do task::spawn {
484483 * let accept_result = net::tcp::accept(new_conn);
485- * if accept_result.is_err() {
486- * core::comm::send(cont_ch, result::get_err(accept_result));
487- * // fail?
488- * }
489- * else {
490- * let sock = result::get(accept_result);
491- * core::comm::send(cont_ch, true);
492- * // do work here
484+ * match accept_result {
485+ * Err(accept_error) => {
486+ * cont_ch.send(Some(accept_error));
487+ * // fail?
488+ * },
489+ * Ok(sock) => {
490+ * cont_ch.send(None);
491+ * // do work here
492+ * }
493493 * }
494494 * };
495- * match core::comm:: recv(cont_po ) {
495+ * match cont_po. recv() {
496496 * // shut down listen()
497- * Some(err_data) { core::comm:: send(kill_chan, Some(err_data)) }
497+ * Some(err_data) => kill_ch. send(Some(err_data)),
498498 * // wait for next connection
499- * None {}
499+ * None => ()
500500 * }
501501 * };
502502 * ~~~~~~~~~~~
503503 *
504504 * # Arguments
505505 *
506- * * `new_conn` - an opaque value used to create a new `tcp_socket `
506+ * * `new_conn` - an opaque value used to create a new `TcpSocket `
507507 *
508508 * # Returns
509509 *
510- * On success, this function will return a `net::tcp::tcp_socket ` as the
511- * `ok ` variant of a `result `. The `net::tcp::tcp_socket ` is anchored within
510+ * On success, this function will return a `net::tcp::TcpSocket ` as the
511+ * `Ok ` variant of a `Result `. The `net::tcp::TcpSocket ` is anchored within
512512 * the task that `accept` was called within for its lifetime. On failure,
513- * this function will return a `net::tcp::tcp_err_data ` record
514- * as the `err ` variant of a `result `.
513+ * this function will return a `net::tcp::TcpErrData ` record
514+ * as the `Err ` variant of a `Result `.
515515 */
516516pub fn accept ( new_conn : TcpNewConnection )
517517 -> result:: Result < TcpSocket , TcpErrData > {
@@ -600,27 +600,27 @@ pub fn accept(new_conn: TcpNewConnection)
600600 *
601601 * # Arguments
602602 *
603- * * `host_ip` - a `net::ip::ip_addr ` representing a unique IP
603+ * * `host_ip` - a `net::ip::IpAddr ` representing a unique IP
604604 * (versions 4 or 6)
605605 * * `port` - a uint representing the port to listen on
606606 * * `backlog` - a uint representing the number of incoming connections
607607 * to cache in memory
608- * * `hl_loop` - a `uv::hl::high_level_loop ` that the tcp request will run on
608+ * * `hl_loop` - a `uv_iotask::IoTask ` that the tcp request will run on
609609 * * `on_establish_cb` - a callback that is evaluated if/when the listener
610610 * is successfully established. it takes no parameters
611611 * * `new_connect_cb` - a callback to be evaluated, on the libuv thread,
612612 * whenever a client attempts to conect on the provided ip/port. the
613613 * callback's arguments are:
614614 * * `new_conn` - an opaque type that can be passed to
615- * `net::tcp::accept` in order to be converted to a `tcp_socket `.
616- * * `kill_ch` - channel of type `core::comm::chan <Option<tcp_err_data>>`.
615+ * `net::tcp::accept` in order to be converted to a `TcpSocket `.
616+ * * `kill_ch` - channel of type `core::comm::Chan <Option<tcp_err_data>>`.
617617 * this channel can be used to send a message to cause `listen` to begin
618618 * closing the underlying libuv data structures.
619619 *
620620 * # returns
621621 *
622- * a `result ` instance containing empty data of type `()` on a
623- * successful/normal shutdown, and a `tcp_listen_err_data ` enum in the event
622+ * a `Result ` instance containing empty data of type `()` on a
623+ * successful/normal shutdown, and a `TcpListenErrData ` enum in the event
624624 * of listen exiting because of an error
625625 */
626626pub fn listen ( host_ip : ip:: IpAddr , port : uint , backlog : uint ,
@@ -799,27 +799,27 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
799799
800800
801801/**
802- * Convert a `net::tcp::tcp_socket ` to a `net::tcp::tcp_socket_buf `.
802+ * Convert a `net::tcp::TcpSocket ` to a `net::tcp::TcpSocketBuf `.
803803 *
804- * This function takes ownership of a `net::tcp::tcp_socket `, returning it
805- * stored within a buffered wrapper, which can be converted to a `io::reader `
806- * or `io::writer `
804+ * This function takes ownership of a `net::tcp::TcpSocket `, returning it
805+ * stored within a buffered wrapper, which can be converted to a `io::Reader `
806+ * or `io::Writer `
807807 *
808808 * # Arguments
809809 *
810- * * `sock` -- a `net::tcp::tcp_socket ` that you want to buffer
810+ * * `sock` -- a `net::tcp::TcpSocket ` that you want to buffer
811811 *
812812 * # Returns
813813 *
814- * A buffered wrapper that you can cast as an `io::reader ` or `io::writer `
814+ * A buffered wrapper that you can cast as an `io::Reader ` or `io::Writer `
815815 */
816816pub fn socket_buf ( sock : TcpSocket ) -> TcpSocketBuf {
817817 TcpSocketBuf ( @TcpBufferedSocketData {
818818 sock : sock, mut buf : ~[ ] , buf_off : 0
819819 } )
820820}
821821
822- /// Convenience methods extending `net::tcp::tcp_socket `
822+ /// Convenience methods extending `net::tcp::TcpSocket `
823823pub impl TcpSocket {
824824 pub fn read_start ( ) -> result:: Result < @Port <
825825 result:: Result < ~[ u8 ] , TcpErrData > > , TcpErrData > {
@@ -862,7 +862,7 @@ pub impl TcpSocket {
862862 }
863863}
864864
865- /// Implementation of `io::reader ` trait for a buffered `net::tcp::tcp_socket `
865+ /// Implementation of `io::Reader ` trait for a buffered `net::tcp::TcpSocket `
866866impl io:: Reader for TcpSocketBuf {
867867 fn read ( & self , buf : & mut [ u8 ] , len : uint ) -> uint {
868868 if len == 0 { return 0 }
@@ -962,7 +962,7 @@ impl io::Reader for TcpSocketBuf {
962962 }
963963}
964964
965- /// Implementation of `io::reader ` trait for a buffered `net::tcp::tcp_socket `
965+ /// Implementation of `io::Reader ` trait for a buffered `net::tcp::TcpSocket `
966966impl io:: Writer for TcpSocketBuf {
967967 pub fn write ( & self , data : & [ const u8 ] ) {
968968 unsafe {
0 commit comments