-
Notifications
You must be signed in to change notification settings - Fork 13.5k
high-level tcp bindings for std #2409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
deba9eb
initial stab at API for std::net::tcp
olsonjeffery ad35511
std: pushing existing code in net.rs -> net_ip.rs and re-import/expor…
olsonjeffery 4dc697a
std: misc cleanup for uv::ll
olsonjeffery 0f071a8
std: export net::ip::format_addr
olsonjeffery c5cf2bc
std: impl for net::tcp::connect
olsonjeffery c6c870a
std: tweak uv::ll::write signature and make it generic/more flexible
olsonjeffery 7cc0646
std: impl of net::tcp::write and make net::tcp::tcp_socket a resource
olsonjeffery 703121e
std: impl for high-level tcp client/request workflow
olsonjeffery 71b68ca
std: no longer return uv::ll::err_data records from net::tcp
olsonjeffery d0ca3f7
core: add result::unwrap() .. patch from @nmatsakis
olsonjeffery 959362a
std: change tcp_*_result to use result::result.. flatter!
olsonjeffery b8f3f5d
std: makeing uv::ll::listen/accept use generic params for ptr args
olsonjeffery 9706fba
std: FIXME stub net::ip::ip_addr::ipv6 variant...needs parse/format impl
olsonjeffery f0a9a67
std: first-pass at a tcp server API, with a basic (non-robust) test
olsonjeffery d99c7a6
std: change sig of uv::ll::accept, again.
olsonjeffery 6ddf458
std: tightening up net::tcp, server/client test done, still has races..
olsonjeffery 63f7ecd
rt: adding rust_uv_* binding for kernel malloc and free'ing :/
olsonjeffery d5ed0cb
std: reworking how some net and libuv modules are exported in the rc
olsonjeffery adffc3c
std: splitting out tcp server API WIP
olsonjeffery 8a54ee9
std: splitting out tcp server API + tests
olsonjeffery 33ec1cb
std: ignoring timer test that seems to be race-failing b/c valgrind
olsonjeffery a6ae810
std: more docs and some methods for types in net::tcp
olsonjeffery fadff9f
core: doc/err feedback tweeks for result::unwrap
olsonjeffery 0cabb2f
std: add try_parse_addr and change an alt w/ ip_addr::ipv6 to avoid w…
olsonjeffery 7ac7571
std: several minor cleanups wrt codereview.. see extended comments
olsonjeffery b86839e
std: adding tcp::write_future for non-block tcp writes, docs cleanup
olsonjeffery 133f52b
std:: adding tcp::read fn as simple, blocking read operation, akin to…
olsonjeffery a97b9f6
std: more work on uv tests to endure valgrind's machinations against …
olsonjeffery b561469
std: high-level libuv-leverage APIs now take a hl_loop as arg (tcp/ti…
olsonjeffery f77892b
std: warning cleanup
olsonjeffery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,9 @@ | ||
import vec; | ||
import uint; | ||
#[doc=" | ||
Top-level module for network-related functionality | ||
"]; | ||
|
||
#[doc = "An IP address"] | ||
enum ip_addr { | ||
/* | ||
Variant: ipv4 | ||
import tcp = net_tcp; | ||
export tcp; | ||
|
||
An IPv4 address | ||
*/ | ||
ipv4(u8, u8, u8, u8), | ||
} | ||
|
||
#[doc = "Convert an `ip_addr` to a str"] | ||
fn format_addr(ip: ip_addr) -> str { | ||
alt ip { | ||
ipv4(a, b, c, d) { | ||
#fmt["%u.%u.%u.%u", a as uint, b as uint, c as uint, d as uint] | ||
} | ||
} | ||
} | ||
|
||
#[doc = " | ||
Convert a str to `ip_addr` | ||
|
||
Converts a string of the format `x.x.x.x` into an ip_addr enum. | ||
|
||
Fails if the string is not a valid IPv4 address | ||
"] | ||
fn parse_addr(ip: str) -> ip_addr { | ||
let parts = vec::map(str::split_char(ip, '.'), {|s| | ||
alt uint::from_str(s) { | ||
some(n) if n <= 255u { n } | ||
_ { fail "Invalid IP Address part." } | ||
} | ||
}); | ||
if vec::len(parts) != 4u { fail "Too many dots in IP address"; } | ||
ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8) | ||
} | ||
|
||
#[test] | ||
fn test_format_ip() { | ||
assert (net::format_addr(net::ipv4(127u8, 0u8, 0u8, 1u8)) == "127.0.0.1") | ||
} | ||
|
||
#[test] | ||
fn test_parse_ip() { | ||
assert (net::parse_addr("127.0.0.1") == net::ipv4(127u8, 0u8, 0u8, 1u8)); | ||
} | ||
import ip = net_ip; | ||
export ip; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#[doc=" | ||
Types/fns concerning Internet Protocol (IP), versions 4 & 6 | ||
"]; | ||
|
||
import vec; | ||
import uint; | ||
|
||
export ip_addr, parse_addr_err; | ||
export format_addr; | ||
export v4; | ||
|
||
#[doc = "An IP address"] | ||
enum ip_addr { | ||
#[doc="An IPv4 address"] | ||
ipv4(u8, u8, u8, u8), | ||
ipv6(u16,u16,u16,u16,u16,u16,u16,u16) | ||
} | ||
|
||
#[doc=" | ||
Human-friendly feedback on why a parse_addr attempt failed | ||
"] | ||
type parse_addr_err = { | ||
err_msg: str | ||
}; | ||
|
||
#[doc=" | ||
Convert a `ip_addr` to a str | ||
|
||
# Arguments | ||
|
||
* ip - a `std::net::ip::ip_addr` | ||
"] | ||
fn format_addr(ip: ip_addr) -> str { | ||
alt ip { | ||
ipv4(a, b, c, d) { | ||
#fmt["%u.%u.%u.%u", a as uint, b as uint, c as uint, d as uint] | ||
} | ||
ipv6(_, _, _, _, _, _, _, _) { | ||
fail "FIXME impl parsing of ipv6 addr"; | ||
} | ||
} | ||
} | ||
|
||
mod v4 { | ||
#[doc = " | ||
Convert a str to `ip_addr` | ||
|
||
# Failure | ||
|
||
j Fails if the string is not a valid IPv4 address | ||
|
||
# Arguments | ||
|
||
* ip - a string of the format `x.x.x.x` | ||
|
||
# Returns | ||
|
||
* an `ip_addr` of the `ipv4` variant | ||
"] | ||
fn parse_addr(ip: str) -> ip_addr { | ||
alt try_parse_addr(ip) { | ||
result::ok(addr) { addr } | ||
result::err(err_data) { | ||
fail err_data.err_msg | ||
} | ||
} | ||
} | ||
fn try_parse_addr(ip: str) -> result::result<ip_addr,parse_addr_err> { | ||
let parts = vec::map(str::split_char(ip, '.'), {|s| | ||
alt uint::from_str(s) { | ||
some(n) if n <= 255u { n } | ||
_ { 256u } | ||
} | ||
}); | ||
if vec::len(parts) != 4u { | ||
result::err({err_msg: #fmt("'%s' doesn't have 4 parts", | ||
ip)}) | ||
} | ||
else if vec::contains(parts, 256u) { | ||
result::err({err_msg: #fmt("invalid octal in provided addr '%s'", | ||
ip)}) | ||
} | ||
else { | ||
result::ok(ipv4(parts[0] as u8, parts[1] as u8, | ||
parts[2] as u8, parts[3] as u8)) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn test_format_ip() { | ||
assert (format_addr(ipv4(127u8, 0u8, 0u8, 1u8)) | ||
== "127.0.0.1") | ||
} | ||
|
||
#[test] | ||
fn test_parse_ip() { | ||
assert (v4::parse_addr("127.0.0.1") == | ||
ipv4(127u8, 0u8, 0u8, 1u8)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to have a
result
version of this too.