socket9 0.1.0-alpha.1

Extended untilities for the networking/unix sockets and raw network sockets
Documentation
use std::net::UdpSocket;

use socket9::{So9SockType, So9SockDomain, So9SockProtocol, Socket9, Socket9ExtSo};


#[test]
fn test_so_udpsocket()
{
    let so9 = Socket9::<UdpSocket>::new_with_bind(&"127.0.0.1:0").unwrap();

    assert_eq!(so9.get_so_domain().unwrap(), So9SockDomain::IPV4);
    assert_eq!(so9.get_so_type().unwrap(), So9SockType::DGRAM);
    assert_eq!(so9.get_so_protocol().unwrap(), So9SockProtocol::UDP);
    #[cfg(unix)]
    {
        assert_eq!(so9.get_so_listening_status().unwrap(), false);
    }
    #[cfg(windows)]
    {
        assert_eq!(so9.get_so_listening_status().err().unwrap().raw_os_error(), Some(10042));
    }
    assert_eq!(so9.get_so_broadcast().unwrap(), false);
    assert_eq!(so9.get_so_error().is_none(), true);

    #[cfg(unix)]
    {
        assert_eq!(so9.get_so_keepalive().unwrap(), false);
    }
    #[cfg(windows)]
    {
        assert_eq!(so9.get_so_keepalive().err().unwrap().raw_os_error(), Some(10042));
    }
    
    #[cfg(unix)]
    {
        assert_eq!(so9.get_so_linger().unwrap(), None);
    }
    #[cfg(windows)]
    {
        assert_eq!(so9.get_so_linger().err().unwrap().raw_os_error(), Some(10042));
    }

    #[cfg(unix)]
    {
        assert_eq!(so9.get_so_out_of_band_inline().unwrap(), false);
    }
    #[cfg(windows)]
    {
        assert_eq!(so9.get_so_out_of_band_inline().err().unwrap().raw_os_error(), Some(10042));
    }
    
    #[cfg(any(target_os = "linux"))]
    match so9.get_so_passcred()
    {
        Ok(_) =>{},
        Err(ref e) if e.raw_os_error() == Some(95) =>{}
        Err(e) => panic!("{}", e)
    }
    
    #[cfg(any(target_os = "linux", target_os = "android"))]
    assert_eq!(so9.get_so_priority().unwrap(), 0);

    #[cfg(unix)]
    {
        assert_eq!(so9.get_so_recv_buf_size().unwrap(), 212992);
    }
    #[cfg(windows)]
    {
        assert_eq!(so9.get_so_recv_buf_size().unwrap(), 65536);
    }

    #[cfg(unix)]
    {
        assert_eq!(so9.get_so_recv_min_output_count().unwrap(), 1);
    }

    assert_eq!(so9.get_so_recv_timeout().unwrap(), None);

    assert_eq!(so9.get_so_reuse_addr().unwrap(), false);
    match so9.set_so_reuse_addr(true)
    {
        Ok(_) => 
        {
            assert_eq!(so9.get_so_reuse_addr().unwrap(), true);
        },
        Err(e) =>
        {
            println!("{}", e);
        }
    }

    #[cfg(unix)]
    {
        assert_eq!(so9.get_so_reuse_port().unwrap(), false);
        match so9.set_so_reuse_port(true)
        {
            Ok(_) => 
            {
                assert_eq!(so9.get_so_reuse_port().unwrap(), true);
            },
            Err(e) =>
            {
                println!("{}", e);
            }
        }
    }

    assert_eq!(so9.get_so_dont_route().unwrap(), false);

    #[cfg(unix)]
    assert_eq!(so9.get_so_send_buf_size().unwrap(), 212992);

    #[cfg(windows)]
    assert_eq!(so9.get_so_send_buf_size().unwrap(), 65536);

    #[cfg(unix)]
    assert_eq!(so9.get_so_send_output_min_count().unwrap(), 1);
    assert_eq!(so9.get_so_send_timeout().unwrap(), None);

    #[cfg(unix)]
    assert_eq!(so9.get_so_cpu_affinity().unwrap(), -1);
    
}