De-export net::*. Part of #3583.
This commit is contained in:
parent
53906bb4fb
commit
35598b4595
5 changed files with 46 additions and 91 deletions
|
@ -1,10 +1,5 @@
|
||||||
//! Top-level module for network-related functionality
|
//! Top-level module for network-related functionality
|
||||||
|
|
||||||
use tcp = net_tcp;
|
pub use tcp = net_tcp;
|
||||||
export tcp;
|
pub use ip = net_ip;
|
||||||
|
pub use url = net_url;
|
||||||
use ip = net_ip;
|
|
||||||
export ip;
|
|
||||||
|
|
||||||
use url = net_url;
|
|
||||||
export url;
|
|
||||||
|
|
|
@ -20,14 +20,8 @@ use get_data_for_req = uv::ll::get_data_for_req;
|
||||||
use ll = uv::ll;
|
use ll = uv::ll;
|
||||||
use comm = core::comm;
|
use comm = core::comm;
|
||||||
|
|
||||||
export IpAddr, parse_addr_err;
|
|
||||||
export format_addr;
|
|
||||||
export v4, v6;
|
|
||||||
export get_addr;
|
|
||||||
export Ipv4, Ipv6;
|
|
||||||
|
|
||||||
/// An IP address
|
/// An IP address
|
||||||
enum IpAddr {
|
pub enum IpAddr {
|
||||||
/// An IPv4 address
|
/// An IPv4 address
|
||||||
Ipv4(sockaddr_in),
|
Ipv4(sockaddr_in),
|
||||||
Ipv6(sockaddr_in6)
|
Ipv6(sockaddr_in6)
|
||||||
|
@ -45,7 +39,7 @@ type ParseAddrErr = {
|
||||||
*
|
*
|
||||||
* * ip - a `std::net::ip::ip_addr`
|
* * ip - a `std::net::ip::ip_addr`
|
||||||
*/
|
*/
|
||||||
fn format_addr(ip: &IpAddr) -> ~str {
|
pub fn format_addr(ip: &IpAddr) -> ~str {
|
||||||
match *ip {
|
match *ip {
|
||||||
Ipv4(ref addr) => unsafe {
|
Ipv4(ref addr) => unsafe {
|
||||||
let result = uv_ip4_name(addr);
|
let result = uv_ip4_name(addr);
|
||||||
|
@ -83,7 +77,7 @@ enum IpGetAddrErr {
|
||||||
* a vector of `ip_addr` results, in the case of success, or an error
|
* a vector of `ip_addr` results, in the case of success, or an error
|
||||||
* object in the case of failure
|
* object in the case of failure
|
||||||
*/
|
*/
|
||||||
fn get_addr(node: &str, iotask: iotask)
|
pub fn get_addr(node: &str, iotask: iotask)
|
||||||
-> result::Result<~[IpAddr], IpGetAddrErr> {
|
-> result::Result<~[IpAddr], IpGetAddrErr> {
|
||||||
do core::comm::listen |output_ch| {
|
do core::comm::listen |output_ch| {
|
||||||
do str::as_buf(node) |node_ptr, len| unsafe {
|
do str::as_buf(node) |node_ptr, len| unsafe {
|
||||||
|
@ -116,8 +110,7 @@ fn get_addr(node: &str, iotask: iotask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod v4 {
|
pub mod v4 {
|
||||||
#[legacy_exports];
|
|
||||||
/**
|
/**
|
||||||
* Convert a str to `ip_addr`
|
* Convert a str to `ip_addr`
|
||||||
*
|
*
|
||||||
|
@ -133,7 +126,7 @@ mod v4 {
|
||||||
*
|
*
|
||||||
* * an `ip_addr` of the `ipv4` variant
|
* * an `ip_addr` of the `ipv4` variant
|
||||||
*/
|
*/
|
||||||
fn parse_addr(ip: &str) -> IpAddr {
|
pub fn parse_addr(ip: &str) -> IpAddr {
|
||||||
match try_parse_addr(ip) {
|
match try_parse_addr(ip) {
|
||||||
result::Ok(copy addr) => addr,
|
result::Ok(copy addr) => addr,
|
||||||
result::Err(ref err_data) => fail err_data.err_msg
|
result::Err(ref err_data) => fail err_data.err_msg
|
||||||
|
@ -141,9 +134,9 @@ mod v4 {
|
||||||
}
|
}
|
||||||
// the simple, old style numberic representation of
|
// the simple, old style numberic representation of
|
||||||
// ipv4
|
// ipv4
|
||||||
type Ipv4Rep = { a: u8, b: u8, c: u8, d:u8 };
|
pub type Ipv4Rep = { a: u8, b: u8, c: u8, d:u8 };
|
||||||
|
|
||||||
trait AsUnsafeU32 {
|
pub trait AsUnsafeU32 {
|
||||||
unsafe fn as_u32() -> u32;
|
unsafe fn as_u32() -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +146,7 @@ mod v4 {
|
||||||
*((ptr::addr_of(&self)) as *u32)
|
*((ptr::addr_of(&self)) as *u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn parse_to_ipv4_rep(ip: &str) -> result::Result<Ipv4Rep, ~str> {
|
pub fn parse_to_ipv4_rep(ip: &str) -> result::Result<Ipv4Rep, ~str> {
|
||||||
let parts = vec::map(str::split_char(ip, '.'), |s| {
|
let parts = vec::map(str::split_char(ip, '.'), |s| {
|
||||||
match uint::from_str(*s) {
|
match uint::from_str(*s) {
|
||||||
Some(n) if n <= 255 => n,
|
Some(n) if n <= 255 => n,
|
||||||
|
@ -171,7 +164,7 @@ mod v4 {
|
||||||
c: parts[2] as u8, d: parts[3] as u8})
|
c: parts[2] as u8, d: parts[3] as u8})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {
|
pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let INADDR_NONE = ll::get_INADDR_NONE();
|
let INADDR_NONE = ll::get_INADDR_NONE();
|
||||||
let ip_rep_result = parse_to_ipv4_rep(ip);
|
let ip_rep_result = parse_to_ipv4_rep(ip);
|
||||||
|
@ -203,8 +196,7 @@ mod v4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mod v6 {
|
pub mod v6 {
|
||||||
#[legacy_exports];
|
|
||||||
/**
|
/**
|
||||||
* Convert a str to `ip_addr`
|
* Convert a str to `ip_addr`
|
||||||
*
|
*
|
||||||
|
@ -220,13 +212,13 @@ mod v6 {
|
||||||
*
|
*
|
||||||
* * an `ip_addr` of the `ipv6` variant
|
* * an `ip_addr` of the `ipv6` variant
|
||||||
*/
|
*/
|
||||||
fn parse_addr(ip: &str) -> IpAddr {
|
pub fn parse_addr(ip: &str) -> IpAddr {
|
||||||
match try_parse_addr(ip) {
|
match try_parse_addr(ip) {
|
||||||
result::Ok(copy addr) => addr,
|
result::Ok(copy addr) => addr,
|
||||||
result::Err(copy err_data) => fail err_data.err_msg
|
result::Err(copy err_data) => fail err_data.err_msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {
|
pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// need to figure out how to establish a parse failure..
|
// need to figure out how to establish a parse failure..
|
||||||
let new_addr = uv_ip6_addr(str::from_slice(ip), 22);
|
let new_addr = uv_ip6_addr(str::from_slice(ip), 22);
|
||||||
|
@ -251,7 +243,7 @@ type GetAddrData = {
|
||||||
};
|
};
|
||||||
|
|
||||||
extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||||
res: *addrinfo) unsafe {
|
res: *addrinfo) unsafe {
|
||||||
log(debug, ~"in get_addr_cb");
|
log(debug, ~"in get_addr_cb");
|
||||||
let handle_data = get_data_for_req(handle) as
|
let handle_data = get_data_for_req(handle) as
|
||||||
*GetAddrData;
|
*GetAddrData;
|
||||||
|
@ -311,7 +303,6 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[legacy_exports];
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ip_ipv4_parse_and_format_ip() {
|
fn test_ip_ipv4_parse_and_format_ip() {
|
||||||
let localhost_str = ~"127.0.0.1";
|
let localhost_str = ~"127.0.0.1";
|
||||||
|
|
|
@ -11,22 +11,8 @@ use libc::size_t;
|
||||||
use io::{Reader, ReaderUtil, Writer};
|
use io::{Reader, ReaderUtil, Writer};
|
||||||
use comm = core::comm;
|
use comm = core::comm;
|
||||||
|
|
||||||
// tcp interfaces
|
|
||||||
export TcpSocket;
|
|
||||||
// buffered socket
|
|
||||||
export TcpSocketBuf, socket_buf;
|
|
||||||
// errors
|
|
||||||
export TcpErrData, TcpConnectErrData;
|
|
||||||
// operations on a tcp_socket
|
|
||||||
export write, write_future, read_start, read_stop;
|
|
||||||
// tcp server stuff
|
|
||||||
export listen, accept;
|
|
||||||
// tcp client stuff
|
|
||||||
export connect;
|
|
||||||
|
|
||||||
#[nolink]
|
#[nolink]
|
||||||
extern mod rustrt {
|
extern mod rustrt {
|
||||||
#[legacy_exports];
|
|
||||||
fn rust_uv_current_kernel_malloc(size: libc::c_uint) -> *libc::c_void;
|
fn rust_uv_current_kernel_malloc(size: libc::c_uint) -> *libc::c_void;
|
||||||
fn rust_uv_current_kernel_free(mem: *libc::c_void);
|
fn rust_uv_current_kernel_free(mem: *libc::c_void);
|
||||||
fn rust_uv_helper_uv_tcp_t_size() -> libc::c_uint;
|
fn rust_uv_helper_uv_tcp_t_size() -> libc::c_uint;
|
||||||
|
@ -48,7 +34,7 @@ struct TcpSocket {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket {
|
pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket {
|
||||||
TcpSocket {
|
TcpSocket {
|
||||||
socket_data: socket_data
|
socket_data: socket_data
|
||||||
}
|
}
|
||||||
|
@ -64,14 +50,14 @@ struct TcpSocketBuf {
|
||||||
data: @TcpBufferedSocketData,
|
data: @TcpBufferedSocketData,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn TcpSocketBuf(data: @TcpBufferedSocketData) -> TcpSocketBuf {
|
pub fn TcpSocketBuf(data: @TcpBufferedSocketData) -> TcpSocketBuf {
|
||||||
TcpSocketBuf {
|
TcpSocketBuf {
|
||||||
data: data
|
data: data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains raw, string-based, error information returned from libuv
|
/// Contains raw, string-based, error information returned from libuv
|
||||||
type TcpErrData = {
|
pub type TcpErrData = {
|
||||||
err_name: ~str,
|
err_name: ~str,
|
||||||
err_msg: ~str
|
err_msg: ~str
|
||||||
};
|
};
|
||||||
|
@ -103,7 +89,7 @@ enum TcpListenErrData {
|
||||||
AccessDenied
|
AccessDenied
|
||||||
}
|
}
|
||||||
/// Details returned as part of a `result::err` result from `tcp::connect`
|
/// Details returned as part of a `result::err` result from `tcp::connect`
|
||||||
enum TcpConnectErrData {
|
pub enum TcpConnectErrData {
|
||||||
/**
|
/**
|
||||||
* Some unplanned-for error. The first and second fields correspond
|
* Some unplanned-for error. The first and second fields correspond
|
||||||
* to libuv's `err_name` and `err_msg` fields, respectively.
|
* to libuv's `err_name` and `err_msg` fields, respectively.
|
||||||
|
@ -129,7 +115,7 @@ enum TcpConnectErrData {
|
||||||
* the remote host. In the event of failure, a
|
* the remote host. In the event of failure, a
|
||||||
* `net::tcp::tcp_connect_err_data` instance will be returned
|
* `net::tcp::tcp_connect_err_data` instance will be returned
|
||||||
*/
|
*/
|
||||||
fn connect(input_ip: ip::IpAddr, port: uint,
|
pub fn connect(input_ip: ip::IpAddr, port: uint,
|
||||||
iotask: IoTask)
|
iotask: IoTask)
|
||||||
-> result::Result<TcpSocket, TcpConnectErrData> unsafe {
|
-> result::Result<TcpSocket, TcpConnectErrData> unsafe {
|
||||||
let result_po = core::comm::Port::<ConnAttempt>();
|
let result_po = core::comm::Port::<ConnAttempt>();
|
||||||
|
@ -262,7 +248,7 @@ fn connect(input_ip: ip::IpAddr, port: uint,
|
||||||
* A `result` object with a `nil` value as the `ok` variant, or a
|
* A `result` object with a `nil` value as the `ok` variant, or a
|
||||||
* `tcp_err_data` value as the `err` variant
|
* `tcp_err_data` value as the `err` variant
|
||||||
*/
|
*/
|
||||||
fn write(sock: &TcpSocket, raw_write_data: ~[u8])
|
pub fn write(sock: &TcpSocket, raw_write_data: ~[u8])
|
||||||
-> result::Result<(), TcpErrData> unsafe {
|
-> result::Result<(), TcpErrData> unsafe {
|
||||||
let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data)));
|
let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data)));
|
||||||
write_common_impl(socket_data_ptr, raw_write_data)
|
write_common_impl(socket_data_ptr, raw_write_data)
|
||||||
|
@ -299,7 +285,7 @@ fn write(sock: &TcpSocket, raw_write_data: ~[u8])
|
||||||
* `result` object with a `nil` value as the `ok` variant, or a `tcp_err_data`
|
* `result` object with a `nil` value as the `ok` variant, or a `tcp_err_data`
|
||||||
* value as the `err` variant
|
* value as the `err` variant
|
||||||
*/
|
*/
|
||||||
fn write_future(sock: &TcpSocket, raw_write_data: ~[u8])
|
pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8])
|
||||||
-> future::Future<result::Result<(), TcpErrData>> unsafe {
|
-> future::Future<result::Result<(), TcpErrData>> unsafe {
|
||||||
let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data)));
|
let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data)));
|
||||||
do future_spawn {
|
do future_spawn {
|
||||||
|
@ -323,7 +309,7 @@ fn write_future(sock: &TcpSocket, raw_write_data: ~[u8])
|
||||||
* optionally, loop on) from until `read_stop` is called, or a
|
* optionally, loop on) from until `read_stop` is called, or a
|
||||||
* `tcp_err_data` record
|
* `tcp_err_data` record
|
||||||
*/
|
*/
|
||||||
fn read_start(sock: &TcpSocket)
|
pub fn read_start(sock: &TcpSocket)
|
||||||
-> result::Result<comm::Port<
|
-> result::Result<comm::Port<
|
||||||
result::Result<~[u8], TcpErrData>>, TcpErrData> unsafe {
|
result::Result<~[u8], TcpErrData>>, TcpErrData> unsafe {
|
||||||
let socket_data = ptr::addr_of(&(*(sock.socket_data)));
|
let socket_data = ptr::addr_of(&(*(sock.socket_data)));
|
||||||
|
@ -337,7 +323,7 @@ fn read_start(sock: &TcpSocket)
|
||||||
*
|
*
|
||||||
* * `sock` - a `net::tcp::tcp_socket` that you wish to stop reading on
|
* * `sock` - a `net::tcp::tcp_socket` that you wish to stop reading on
|
||||||
*/
|
*/
|
||||||
fn read_stop(sock: &TcpSocket,
|
pub fn read_stop(sock: &TcpSocket,
|
||||||
+read_port: comm::Port<result::Result<~[u8], TcpErrData>>) ->
|
+read_port: comm::Port<result::Result<~[u8], TcpErrData>>) ->
|
||||||
result::Result<(), TcpErrData> unsafe {
|
result::Result<(), TcpErrData> unsafe {
|
||||||
log(debug, fmt!("taking the read_port out of commission %?", read_port));
|
log(debug, fmt!("taking the read_port out of commission %?", read_port));
|
||||||
|
@ -472,7 +458,7 @@ fn read_future(sock: &TcpSocket, timeout_msecs: uint)
|
||||||
* this function will return a `net::tcp::tcp_err_data` record
|
* this function will return a `net::tcp::tcp_err_data` record
|
||||||
* as the `err` variant of a `result`.
|
* as the `err` variant of a `result`.
|
||||||
*/
|
*/
|
||||||
fn accept(new_conn: TcpNewConnection)
|
pub fn accept(new_conn: TcpNewConnection)
|
||||||
-> result::Result<TcpSocket, TcpErrData> unsafe {
|
-> result::Result<TcpSocket, TcpErrData> unsafe {
|
||||||
|
|
||||||
match new_conn{
|
match new_conn{
|
||||||
|
@ -570,7 +556,7 @@ fn accept(new_conn: TcpNewConnection)
|
||||||
* successful/normal shutdown, and a `tcp_listen_err_data` enum in the event
|
* successful/normal shutdown, and a `tcp_listen_err_data` enum in the event
|
||||||
* of listen exiting because of an error
|
* of listen exiting because of an error
|
||||||
*/
|
*/
|
||||||
fn listen(host_ip: ip::IpAddr, port: uint, backlog: uint,
|
pub fn listen(host_ip: ip::IpAddr, port: uint, backlog: uint,
|
||||||
iotask: IoTask,
|
iotask: IoTask,
|
||||||
+on_establish_cb: fn~(comm::Chan<Option<TcpErrData>>),
|
+on_establish_cb: fn~(comm::Chan<Option<TcpErrData>>),
|
||||||
+new_connect_cb: fn~(TcpNewConnection,
|
+new_connect_cb: fn~(TcpNewConnection,
|
||||||
|
@ -728,17 +714,17 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint,
|
||||||
*
|
*
|
||||||
* A buffered wrapper that you can cast as an `io::reader` or `io::writer`
|
* A buffered wrapper that you can cast as an `io::reader` or `io::writer`
|
||||||
*/
|
*/
|
||||||
fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
|
pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
|
||||||
TcpSocketBuf(@{ sock: move sock, mut buf: ~[] })
|
TcpSocketBuf(@{ sock: move sock, mut buf: ~[] })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience methods extending `net::tcp::tcp_socket`
|
/// Convenience methods extending `net::tcp::tcp_socket`
|
||||||
impl TcpSocket {
|
impl TcpSocket {
|
||||||
fn read_start() -> result::Result<comm::Port<
|
pub fn read_start() -> result::Result<comm::Port<
|
||||||
result::Result<~[u8], TcpErrData>>, TcpErrData> {
|
result::Result<~[u8], TcpErrData>>, TcpErrData> {
|
||||||
read_start(&self)
|
read_start(&self)
|
||||||
}
|
}
|
||||||
fn read_stop(read_port:
|
pub fn read_stop(read_port:
|
||||||
comm::Port<result::Result<~[u8], TcpErrData>>) ->
|
comm::Port<result::Result<~[u8], TcpErrData>>) ->
|
||||||
result::Result<(), TcpErrData> {
|
result::Result<(), TcpErrData> {
|
||||||
read_stop(&self, move read_port)
|
read_stop(&self, move read_port)
|
||||||
|
@ -751,11 +737,11 @@ impl TcpSocket {
|
||||||
future::Future<result::Result<~[u8], TcpErrData>> {
|
future::Future<result::Result<~[u8], TcpErrData>> {
|
||||||
read_future(&self, timeout_msecs)
|
read_future(&self, timeout_msecs)
|
||||||
}
|
}
|
||||||
fn write(raw_write_data: ~[u8])
|
pub fn write(raw_write_data: ~[u8])
|
||||||
-> result::Result<(), TcpErrData> {
|
-> result::Result<(), TcpErrData> {
|
||||||
write(&self, raw_write_data)
|
write(&self, raw_write_data)
|
||||||
}
|
}
|
||||||
fn write_future(raw_write_data: ~[u8])
|
pub fn write_future(raw_write_data: ~[u8])
|
||||||
-> future::Future<result::Result<(), TcpErrData>> {
|
-> future::Future<result::Result<(), TcpErrData>> {
|
||||||
write_future(&self, raw_write_data)
|
write_future(&self, raw_write_data)
|
||||||
}
|
}
|
||||||
|
@ -816,7 +802,7 @@ impl TcpSocketBuf: io::Reader {
|
||||||
|
|
||||||
/// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket`
|
/// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket`
|
||||||
impl TcpSocketBuf: io::Writer {
|
impl TcpSocketBuf: io::Writer {
|
||||||
fn write(data: &[const u8]) unsafe {
|
pub fn write(data: &[const u8]) unsafe {
|
||||||
let socket_data_ptr =
|
let socket_data_ptr =
|
||||||
ptr::addr_of(&(*((*(self.data)).sock).socket_data));
|
ptr::addr_of(&(*((*(self.data)).sock).socket_data));
|
||||||
let w_result = write_common_impl(socket_data_ptr,
|
let w_result = write_common_impl(socket_data_ptr,
|
||||||
|
@ -1224,16 +1210,13 @@ type TcpBufferedSocketData = {
|
||||||
|
|
||||||
//#[cfg(test)]
|
//#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[legacy_exports];
|
|
||||||
// FIXME don't run on fbsd or linux 32 bit (#2064)
|
// FIXME don't run on fbsd or linux 32 bit (#2064)
|
||||||
#[cfg(target_os="win32")]
|
#[cfg(target_os="win32")]
|
||||||
#[cfg(target_os="darwin")]
|
#[cfg(target_os="darwin")]
|
||||||
#[cfg(target_os="linux")]
|
#[cfg(target_os="linux")]
|
||||||
mod tcp_ipv4_server_and_client_test {
|
mod tcp_ipv4_server_and_client_test {
|
||||||
#[legacy_exports];
|
|
||||||
#[cfg(target_arch="x86_64")]
|
#[cfg(target_arch="x86_64")]
|
||||||
mod impl64 {
|
mod impl64 {
|
||||||
#[legacy_exports];
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gl_tcp_server_and_client_ipv4() unsafe {
|
fn test_gl_tcp_server_and_client_ipv4() unsafe {
|
||||||
impl_gl_tcp_ipv4_server_and_client();
|
impl_gl_tcp_ipv4_server_and_client();
|
||||||
|
@ -1258,7 +1241,6 @@ mod test {
|
||||||
}
|
}
|
||||||
#[cfg(target_arch="x86")]
|
#[cfg(target_arch="x86")]
|
||||||
mod impl32 {
|
mod impl32 {
|
||||||
#[legacy_exports];
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore(cfg(target_os = "linux"))]
|
#[ignore(cfg(target_os = "linux"))]
|
||||||
fn test_gl_tcp_server_and_client_ipv4() unsafe {
|
fn test_gl_tcp_server_and_client_ipv4() unsafe {
|
||||||
|
|
|
@ -10,15 +10,6 @@ use result::{Err, Ok};
|
||||||
use to_str::ToStr;
|
use to_str::ToStr;
|
||||||
use to_bytes::IterBytes;
|
use to_bytes::IterBytes;
|
||||||
|
|
||||||
export Url, Query;
|
|
||||||
export from_str, to_str;
|
|
||||||
export get_scheme;
|
|
||||||
export query_to_str;
|
|
||||||
|
|
||||||
export encode, decode;
|
|
||||||
export encode_component, decode_component;
|
|
||||||
export encode_form_urlencoded, decode_form_urlencoded;
|
|
||||||
|
|
||||||
struct Url {
|
struct Url {
|
||||||
scheme: ~str,
|
scheme: ~str,
|
||||||
user: Option<UserInfo>,
|
user: Option<UserInfo>,
|
||||||
|
@ -34,9 +25,9 @@ type UserInfo = {
|
||||||
pass: Option<~str>
|
pass: Option<~str>
|
||||||
};
|
};
|
||||||
|
|
||||||
type Query = ~[(~str, ~str)];
|
pub type Query = ~[(~str, ~str)];
|
||||||
|
|
||||||
fn Url(scheme: ~str, +user: Option<UserInfo>, +host: ~str,
|
pub fn Url(scheme: ~str, +user: Option<UserInfo>, +host: ~str,
|
||||||
+port: Option<~str>, +path: ~str, +query: Query,
|
+port: Option<~str>, +path: ~str, +query: Query,
|
||||||
+fragment: Option<~str>) -> Url {
|
+fragment: Option<~str>) -> Url {
|
||||||
Url { scheme: move scheme, user: move user, host: move host,
|
Url { scheme: move scheme, user: move user, host: move host,
|
||||||
|
@ -93,7 +84,7 @@ fn encode_inner(s: &str, full_url: bool) -> ~str {
|
||||||
*
|
*
|
||||||
* This function is compliant with RFC 3986.
|
* This function is compliant with RFC 3986.
|
||||||
*/
|
*/
|
||||||
fn encode(s: &str) -> ~str {
|
pub fn encode(s: &str) -> ~str {
|
||||||
encode_inner(s, true)
|
encode_inner(s, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +94,7 @@ fn encode(s: &str) -> ~str {
|
||||||
*
|
*
|
||||||
* This function is compliant with RFC 3986.
|
* This function is compliant with RFC 3986.
|
||||||
*/
|
*/
|
||||||
fn encode_component(s: &str) -> ~str {
|
pub fn encode_component(s: &str) -> ~str {
|
||||||
encode_inner(s, false)
|
encode_inner(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,14 +141,14 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
|
||||||
*
|
*
|
||||||
* This will only decode escape sequences generated by encode_uri.
|
* This will only decode escape sequences generated by encode_uri.
|
||||||
*/
|
*/
|
||||||
fn decode(s: &str) -> ~str {
|
pub fn decode(s: &str) -> ~str {
|
||||||
decode_inner(s, true)
|
decode_inner(s, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode a string encoded with percent encoding.
|
* Decode a string encoded with percent encoding.
|
||||||
*/
|
*/
|
||||||
fn decode_component(s: &str) -> ~str {
|
pub fn decode_component(s: &str) -> ~str {
|
||||||
decode_inner(s, false)
|
decode_inner(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +174,7 @@ fn encode_plus(s: &str) -> ~str {
|
||||||
/**
|
/**
|
||||||
* Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
|
* Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
|
||||||
*/
|
*/
|
||||||
fn encode_form_urlencoded(m: HashMap<~str, @DVec<@~str>>) -> ~str {
|
pub fn encode_form_urlencoded(m: HashMap<~str, @DVec<@~str>>) -> ~str {
|
||||||
let mut out = ~"";
|
let mut out = ~"";
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
|
||||||
|
@ -209,7 +200,7 @@ fn encode_form_urlencoded(m: HashMap<~str, @DVec<@~str>>) -> ~str {
|
||||||
* Decode a string encoded with the 'application/x-www-form-urlencoded' media
|
* Decode a string encoded with the 'application/x-www-form-urlencoded' media
|
||||||
* type into a hashmap.
|
* type into a hashmap.
|
||||||
*/
|
*/
|
||||||
fn decode_form_urlencoded(s: ~[u8]) ->
|
pub fn decode_form_urlencoded(s: ~[u8]) ->
|
||||||
map::HashMap<~str, @dvec::DVec<@~str>> {
|
map::HashMap<~str, @dvec::DVec<@~str>> {
|
||||||
do io::with_bytes_reader(s) |rdr| {
|
do io::with_bytes_reader(s) |rdr| {
|
||||||
let m = HashMap();
|
let m = HashMap();
|
||||||
|
@ -334,7 +325,7 @@ fn query_from_str(rawquery: &str) -> Query {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_to_str(query: Query) -> ~str {
|
pub fn query_to_str(query: Query) -> ~str {
|
||||||
let mut strvec = ~[];
|
let mut strvec = ~[];
|
||||||
for query.each |kv| {
|
for query.each |kv| {
|
||||||
let (k, v) = copy *kv;
|
let (k, v) = copy *kv;
|
||||||
|
@ -344,7 +335,7 @@ fn query_to_str(query: Query) -> ~str {
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the scheme and the rest of the url, or a parsing error
|
// returns the scheme and the rest of the url, or a parsing error
|
||||||
fn get_scheme(rawurl: &str) -> result::Result<(~str, ~str), @~str> {
|
pub fn get_scheme(rawurl: &str) -> result::Result<(~str, ~str), @~str> {
|
||||||
for str::each_chari(rawurl) |i,c| {
|
for str::each_chari(rawurl) |i,c| {
|
||||||
match c {
|
match c {
|
||||||
'A' .. 'Z' | 'a' .. 'z' => loop,
|
'A' .. 'Z' | 'a' .. 'z' => loop,
|
||||||
|
@ -623,7 +614,7 @@ fn get_query_fragment(rawurl: &str) ->
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn from_str(rawurl: &str) -> result::Result<Url, ~str> {
|
pub fn from_str(rawurl: &str) -> result::Result<Url, ~str> {
|
||||||
// scheme
|
// scheme
|
||||||
let mut schm = get_scheme(rawurl);
|
let mut schm = get_scheme(rawurl);
|
||||||
if result::is_err(&schm) {
|
if result::is_err(&schm) {
|
||||||
|
@ -681,7 +672,7 @@ impl Url : FromStr {
|
||||||
* result in just "http://somehost.com".
|
* result in just "http://somehost.com".
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
fn to_str(url: Url) -> ~str {
|
pub fn to_str(url: Url) -> ~str {
|
||||||
let user = if url.user.is_some() {
|
let user = if url.user.is_some() {
|
||||||
userinfo_to_str(option::unwrap(copy url.user))
|
userinfo_to_str(option::unwrap(copy url.user))
|
||||||
} else {
|
} else {
|
||||||
|
@ -713,7 +704,7 @@ fn to_str(url: Url) -> ~str {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Url: to_str::ToStr {
|
impl Url: to_str::ToStr {
|
||||||
fn to_str() -> ~str {
|
pub fn to_str() -> ~str {
|
||||||
to_str(self)
|
to_str(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,9 @@ export cell;
|
||||||
|
|
||||||
// General io and system-services modules
|
// General io and system-services modules
|
||||||
|
|
||||||
#[legacy_exports]
|
|
||||||
mod net;
|
mod net;
|
||||||
#[legacy_exports]
|
|
||||||
mod net_ip;
|
mod net_ip;
|
||||||
#[legacy_exports]
|
|
||||||
mod net_tcp;
|
mod net_tcp;
|
||||||
#[legacy_exports]
|
|
||||||
mod net_url;
|
mod net_url;
|
||||||
|
|
||||||
// libuv modules
|
// libuv modules
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue