2 () => (return Err(io
::Error
::new(io
::ErrorKind
::Other
, "No networking available on L4Re."));)
10 use net
::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}
;
11 use sys_common
::{AsInner, FromInner, IntoInner}
;
12 use sys
::fd
::FileDesc
;
16 pub extern crate libc
as netc
;
18 pub struct Socket(FileDesc
);
20 pub fn new(_
: &SocketAddr
, _
: libc
::c_int
) -> io
::Result
<Socket
> {
24 pub fn new_raw(_
: libc
::c_int
, _
: libc
::c_int
) -> io
::Result
<Socket
> {
28 pub fn new_pair(_
: libc
::c_int
, _
: libc
::c_int
) -> io
::Result
<(Socket
, Socket
)> {
32 pub fn connect_timeout(&self, _
: &SocketAddr
, _
: Duration
) -> io
::Result
<()> {
36 pub fn accept(&self, _
: *mut libc
::sockaddr
, _
: *mut libc
::socklen_t
)
37 -> io
::Result
<Socket
> {
41 pub fn duplicate(&self) -> io
::Result
<Socket
> {
45 pub fn read(&self, _
: &mut [u8]) -> io
::Result
<usize> {
49 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
53 pub fn recv_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
57 pub fn peek_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
61 pub fn write(&self, _
: &[u8]) -> io
::Result
<usize> {
65 pub fn set_timeout(&self, _
: Option
<Duration
>, _
: libc
::c_int
) -> io
::Result
<()> {
69 pub fn timeout(&self, _
: libc
::c_int
) -> io
::Result
<Option
<Duration
>> {
73 pub fn shutdown(&self, _
: Shutdown
) -> io
::Result
<()> {
77 pub fn set_nodelay(&self, _
: bool
) -> io
::Result
<()> {
81 pub fn nodelay(&self) -> io
::Result
<bool
> {
85 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
89 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
94 impl AsInner
<libc
::c_int
> for Socket
{
95 fn as_inner(&self) -> &libc
::c_int { self.0.as_inner() }
98 impl FromInner
<libc
::c_int
> for Socket
{
99 fn from_inner(fd
: libc
::c_int
) -> Socket { Socket(FileDesc::new(fd)) }
102 impl IntoInner
<libc
::c_int
> for Socket
{
103 fn into_inner(self) -> libc
::c_int { self.0.into_raw() }
106 pub struct TcpStream
{
111 pub fn connect(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<TcpStream
> {
115 pub fn connect_timeout(_
: &SocketAddr
, _
: Duration
) -> io
::Result
<TcpStream
> {
119 pub fn socket(&self) -> &Socket { &self.inner }
121 pub fn into_socket(self) -> Socket { self.inner }
123 pub fn set_read_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
127 pub fn set_write_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
131 pub fn read_timeout(&self) -> io
::Result
<Option
<Duration
>> {
135 pub fn write_timeout(&self) -> io
::Result
<Option
<Duration
>> {
139 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
143 pub fn read(&self, _
: &mut [u8]) -> io
::Result
<usize> {
147 pub fn write(&self, _
: &[u8]) -> io
::Result
<usize> {
151 pub fn peer_addr(&self) -> io
::Result
<SocketAddr
> {
155 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
159 pub fn shutdown(&self, _
: Shutdown
) -> io
::Result
<()> {
163 pub fn duplicate(&self) -> io
::Result
<TcpStream
> {
167 pub fn set_nodelay(&self, _
: bool
) -> io
::Result
<()> {
171 pub fn nodelay(&self) -> io
::Result
<bool
> {
175 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
179 pub fn ttl(&self) -> io
::Result
<u32> {
183 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
187 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
192 impl FromInner
<Socket
> for TcpStream
{
193 fn from_inner(socket
: Socket
) -> TcpStream
{
194 TcpStream { inner: socket }
198 impl fmt
::Debug
for TcpStream
{
199 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
200 write
!(f
, "No networking support available on L4Re")
204 pub struct TcpListener
{
209 pub fn bind(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<TcpListener
> {
213 pub fn socket(&self) -> &Socket { &self.inner }
215 pub fn into_socket(self) -> Socket { self.inner }
217 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
221 pub fn accept(&self) -> io
::Result
<(TcpStream
, SocketAddr
)> {
225 pub fn duplicate(&self) -> io
::Result
<TcpListener
> {
229 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
233 pub fn ttl(&self) -> io
::Result
<u32> {
237 pub fn set_only_v6(&self, _
: bool
) -> io
::Result
<()> {
241 pub fn only_v6(&self) -> io
::Result
<bool
> {
245 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
249 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
254 impl FromInner
<Socket
> for TcpListener
{
255 fn from_inner(socket
: Socket
) -> TcpListener
{
256 TcpListener { inner: socket }
260 impl fmt
::Debug
for TcpListener
{
261 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
262 write
!(f
, "No networking support available on L4Re.")
266 pub struct UdpSocket
{
271 pub fn bind(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<UdpSocket
> {
275 pub fn socket(&self) -> &Socket { &self.inner }
277 pub fn into_socket(self) -> Socket { self.inner }
279 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
283 pub fn recv_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
287 pub fn peek_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
291 pub fn send_to(&self, _
: &[u8], _
: &SocketAddr
) -> io
::Result
<usize> {
295 pub fn duplicate(&self) -> io
::Result
<UdpSocket
> {
299 pub fn set_read_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
303 pub fn set_write_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
307 pub fn read_timeout(&self) -> io
::Result
<Option
<Duration
>> {
311 pub fn write_timeout(&self) -> io
::Result
<Option
<Duration
>> {
315 pub fn set_broadcast(&self, _
: bool
) -> io
::Result
<()> {
319 pub fn broadcast(&self) -> io
::Result
<bool
> {
323 pub fn set_multicast_loop_v4(&self, _
: bool
) -> io
::Result
<()> {
327 pub fn multicast_loop_v4(&self) -> io
::Result
<bool
> {
331 pub fn set_multicast_ttl_v4(&self, _
: u32) -> io
::Result
<()> {
335 pub fn multicast_ttl_v4(&self) -> io
::Result
<u32> {
339 pub fn set_multicast_loop_v6(&self, _
: bool
) -> io
::Result
<()> {
343 pub fn multicast_loop_v6(&self) -> io
::Result
<bool
> {
347 pub fn join_multicast_v4(&self, _
: &Ipv4Addr
, _
: &Ipv4Addr
)
352 pub fn join_multicast_v6(&self, _
: &Ipv6Addr
, _
: u32)
357 pub fn leave_multicast_v4(&self, _
: &Ipv4Addr
, _
: &Ipv4Addr
)
362 pub fn leave_multicast_v6(&self, _
: &Ipv6Addr
, _
: u32)
367 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
371 pub fn ttl(&self) -> io
::Result
<u32> {
375 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
379 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
383 pub fn recv(&self, _
: &mut [u8]) -> io
::Result
<usize> {
387 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
391 pub fn send(&self, _
: &[u8]) -> io
::Result
<usize> {
395 pub fn connect(&self, _
: io
::Result
<&SocketAddr
>) -> io
::Result
<()> {
400 impl FromInner
<Socket
> for UdpSocket
{
401 fn from_inner(socket
: Socket
) -> UdpSocket
{
402 UdpSocket { inner: socket }
406 impl fmt
::Debug
for UdpSocket
{
407 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
408 write
!(f
, "No networking support on L4Re available.")
412 pub struct LookupHost
{
413 original
: *mut libc
::addrinfo
,
414 cur
: *mut libc
::addrinfo
,
417 impl Iterator
for LookupHost
{
418 type Item
= SocketAddr
;
419 fn next(&mut self) -> Option
<SocketAddr
> {
425 pub fn port(&self) -> u16 {
430 unsafe impl Sync
for LookupHost {}
431 unsafe impl Send
for LookupHost {}
434 impl<'a
> TryFrom
<&'a
str> for LookupHost
{
435 type Error
= io
::Error
;
437 fn try_from(_v
: &'a
str) -> io
::Result
<LookupHost
> {
442 impl<'a
> TryFrom
<(&'a
str, u16)> for LookupHost
{
443 type Error
= io
::Error
;
445 fn try_from(_v
: (&'a
str, u16)) -> io
::Result
<LookupHost
> {