Module net stdlib

net
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
5
Imported by:
10
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Overview

net provides networking functions. It is mostly a wrapper to BSD sockets, so you can listen on a port, connect to remote TCP/UDP services, and communicate with them.

Aliases

This section is empty.

Constants

#constant no_timeout

pub const no_timeout = time.Duration(0)

no_timeout should be given to functions when no timeout is wanted (i.e. all functions return instantly)

#constant infinite_timeout

pub const infinite_timeout = time.infinite

infinite_timeout should be given to functions when an infinite_timeout is wanted (i.e. functions only ever return with data)

#constant errors_base

errors_base             = 0

Well defined errors that are returned from socket functions

#constant err_new_socket_failed

err_new_socket_failed   = error_with_code('net: new_socket failed to create socket',
	errors_base + 1)

Well defined errors that are returned from socket functions

#constant err_option_not_settable

err_option_not_settable = error_with_code('net: set_option_xxx option not settable',
	errors_base + 2)

Well defined errors that are returned from socket functions

#constant err_option_wrong_type

err_option_wrong_type   = error_with_code('net: set_option_xxx option wrong type',
	errors_base + 3)

Well defined errors that are returned from socket functions

#constant err_port_out_of_range

err_port_out_of_range   = error_with_code('net: port out of range', errors_base + 5)

Well defined errors that are returned from socket functions

#constant err_no_udp_remote

err_no_udp_remote       = error_with_code('net: no udp remote', errors_base + 6)

Well defined errors that are returned from socket functions

#constant err_connect_failed

err_connect_failed      = error_with_code('net: connect failed', errors_base + 7)

Well defined errors that are returned from socket functions

#constant err_connect_timed_out

err_connect_timed_out   = error_with_code('net: connect timed out', errors_base + 8)

Well defined errors that are returned from socket functions

#constant err_timed_out

err_timed_out           = error_with_code('net: op timed out', errors_base + 9)

Well defined errors that are returned from socket functions

#constant err_timed_out_code

err_timed_out_code      = errors_base + 9

Well defined errors that are returned from socket functions

#constant err_connection_refused

err_connection_refused  = error_with_code('net: connection refused', errors_base + 10)

Well defined errors that are returned from socket functions

#constant msg_nosignal

Linux
msg_nosignal = 0x4000

Sum types

This section is empty.

Functions

#fn addr_from_socket_handle

fn addr_from_socket_handle(handle int) Addr

addr_from_socket_handle returns an address, based on the given integer socket handle

#fn close

fn close(handle int) !

close a socket, given its file descriptor handle.

#fn dial_tcp

fn dial_tcp(address string) !&TcpConn

#fn dial_tcp_with_bind

fn dial_tcp_with_bind(saddr string, laddr string) !&TcpConn

bind local address and dial.

#fn dial_udp

fn dial_udp(raddr string) !&UdpConn

#fn listen_tcp

fn listen_tcp(family AddrFamily, saddr string) !&TcpListener

#fn listen_udp

fn listen_udp(laddr string) !&UdpConn

#fn resolve_addrs

fn resolve_addrs(addr string, family AddrFamily, @type SocketType) ![]Addr

resolve_addrs converts the given addr, family and @type to a list of addresses

#fn resolve_addrs_fuzzy

fn resolve_addrs_fuzzy(addr string, @type SocketType) ![]Addr

resolve_addrs converts the given addr and @type to a list of addresses

#fn resolve_ipaddrs

fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ![]Addr

resolve_ipaddrs converts the given addr, family and typ to a list of addresses

#fn shutdown

fn shutdown(handle int, config ShutdownConfig) int

shutdown shutsdown a socket, given its file descriptor handle.

By default it shuts it down in both directions, both for reading and for writing. You can change that using net.shutdown(handle, how: .read) or net.shutdown(handle, how: .write)

#fn socket_error

fn socket_error(potential_code int) !int

#fn socket_error_message

fn socket_error_message(potential_code int, s string) !int

#fn split_address

fn split_address(addr string) !(string, u16)

split address splits an address into its host name and its port

#fn tcp_socket_from_handle_raw

fn tcp_socket_from_handle_raw(sockfd int) TcpSocket

tcp_socket_from_handle_raw is similar to tcp_socket_from_handle, but it does not modify any socket options

#fn validate_port

fn validate_port(port int) !u16

validate_port checks whether a port is valid and returns the port or an error

#fn wrap_error

fn wrap_error(error_code int) !

#fn wsa_error

Windows
fn wsa_error(code int) WsaError

wsa_error casts an int to its WsaError value

Structs

#struct C.fd_set

typedef
pub struct C.fd_set {}

#struct C.addrinfo

Android
pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in

Android
pub struct C.sockaddr_in {
mut:
	sin_family u16
	sin_port   u16
	sin_addr   u32
}

#struct C.sockaddr_in6

Android
pub struct C.sockaddr_in6 {
mut:
	sin6_family u16
	sin6_port   u16
	sin6_addr   [4]u32
}

#struct C.sockaddr_un

Android
pub struct C.sockaddr_un {
mut:
	sun_family u16
	sun_path   [max_unix_path]char
}

#struct Ip6

Android_pack:1
pub struct Ip6 {
	port      u16
	flow_info u32
	addr      [16]u8
	scope_id  u32
}

#fn (Ip6) str

fn (a Ip6) str() string

str returns a string representation of a

#struct Ip

Android_pack:1
pub struct Ip {
	port u16
	addr [4]u8
	// Pad to size so that socket functions
	// dont complain to us (see  in.h and bind())
	// TODO(emily): I would really like to use
	// some constant calculations here
	// so that this doesnt have to be hardcoded
	sin_pad [8]u8
}

#fn new_ip

fn new_ip(port u16, addr [987654321]u8) Addr

new_ip creates a new Addr from the IPv4 address family, based on the given port and addr

#fn (Ip) str

fn (a Ip) str() string

str returns a string representation of a

#struct Unix

Android
pub struct Unix {
	path [max_unix_path]u8
}

#struct Addr

Android_pack:1
pub struct Addr {
pub:
	f    u16
	addr AddrData
}

#fn (Addr) family

fn (a Addr) family() AddrFamily

family returns the family/kind of the given address a

#fn (Addr) len

fn (a Addr) len() u32

len returns the length in bytes of the address a, depending on its family

#fn (Addr) str

fn (a Addr) str() string

str returns a string representation of the address a

#struct C.addrinfo

pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in6

pub struct C.sockaddr_in6 {
mut:
	// 1 + 1 + 2 + 4 + 16 + 4 = 28;
	sin6_len      u8     // 1
	sin6_family   u8     // 1
	sin6_port     u16    // 2
	sin6_flowinfo u32    // 4
	sin6_addr     [16]u8 // 16
	sin6_scope_id u32    // 4
}

#struct C.sockaddr_in

pub struct C.sockaddr_in {
mut:
	sin_len    u8
	sin_family u8
	sin_port   u16
	sin_addr   u32
	sin_zero   [8]char
}

#struct C.sockaddr_un

pub struct C.sockaddr_un {
mut:
	sun_len    u8
	sun_family u8
	sun_path   [max_unix_path]char
}

#struct C.addrinfo

pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in

pub struct C.sockaddr_in {
mut:
	sin_family u8
	sin_port   u16
	sin_addr   u32
}

#struct C.sockaddr_in6

pub struct C.sockaddr_in6 {
mut:
	sin6_family u8
	sin6_port   u16
	sin6_addr   [4]u32
}

#struct C.sockaddr_un

pub struct C.sockaddr_un {
mut:
	sun_family u8
	sun_path   [max_unix_path]char
}

#struct C.addrinfo

Dragonfly
pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in6

Dragonfly
pub struct C.sockaddr_in6 {
mut:
	// 1 + 1 + 2 + 4 + 16 + 4 = 28;
	sin6_len      u8     // 1
	sin6_family   u8     // 1
	sin6_port     u16    // 2
	sin6_flowinfo u32    // 4
	sin6_addr     [16]u8 // 16
	sin6_scope_id u32    // 4
}

#struct C.sockaddr_in

Dragonfly
pub struct C.sockaddr_in {
mut:
	sin_len    u8
	sin_family u8
	sin_port   u16
	sin_addr   u32
	sin_zero   [8]char
}

#struct C.sockaddr_un

Dragonfly
pub struct C.sockaddr_un {
mut:
	sun_len    u8
	sun_family u8
	sun_path   [max_unix_path]char
}

#struct C.addrinfo

FreeBSD
pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in6

FreeBSD
pub struct C.sockaddr_in6 {
mut:
	// 1 + 1 + 2 + 4 + 16 + 4 = 28;
	sin6_len      u8     // 1
	sin6_family   u8     // 1
	sin6_port     u16    // 2
	sin6_flowinfo u32    // 4
	sin6_addr     [16]u8 // 16
	sin6_scope_id u32    // 4
}

#struct C.sockaddr_in

FreeBSD
pub struct C.sockaddr_in {
mut:
	sin_len    u8
	sin_family u8
	sin_port   u16
	sin_addr   u32
	sin_zero   [8]char
}

#struct C.sockaddr_un

FreeBSD
pub struct C.sockaddr_un {
mut:
	sun_len    u8
	sun_family u8
	sun_path   [max_unix_path]char
}

#struct C.addrinfo

Linux
pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in

Linux
pub struct C.sockaddr_in {
mut:
	sin_family u16
	sin_port   u16
	sin_addr   u32
}

#struct C.sockaddr_in6

Linux
pub struct C.sockaddr_in6 {
mut:
	sin6_family u16
	sin6_port   u16
	sin6_addr   [4]u32
}

#struct C.sockaddr_un

Linux
pub struct C.sockaddr_un {
mut:
	sun_family u16
	sun_path   [max_unix_path]char
}

#struct C.addrinfo

NetBSD
pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in6

NetBSD
pub struct C.sockaddr_in6 {
mut:
	// 1 + 1 + 2 + 4 + 16 + 4 = 28;
	sin6_len      u8     // 1
	sin6_family   u8     // 1
	sin6_port     u16    // 2
	sin6_flowinfo u32    // 4
	sin6_addr     [16]u8 // 16
	sin6_scope_id u32    // 4
}

#struct C.sockaddr_in

NetBSD
pub struct C.sockaddr_in {
mut:
	sin_len    u8
	sin_family u8
	sin_port   u16
	sin_addr   u32
	sin_zero   [8]char
}

#struct C.sockaddr_un

NetBSD
pub struct C.sockaddr_un {
mut:
	sun_len    u8
	sun_family u8
	sun_path   [max_unix_path]char
}

#struct C.addrinfo

OpenBSD
pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in6

OpenBSD
pub struct C.sockaddr_in6 {
mut:
	// 1 + 1 + 2 + 4 + 16 + 4 = 28;
	sin6_len      u8     // 1
	sin6_family   u8     // 1
	sin6_port     u16    // 2
	sin6_flowinfo u32    // 4
	sin6_addr     [16]u8 // 16
	sin6_scope_id u32    // 4
}

#struct C.sockaddr_in

OpenBSD
pub struct C.sockaddr_in {
mut:
	sin_len    u8
	sin_family u8
	sin_port   u16
	sin_addr   u32
	sin_zero   [8]char
}

#struct C.sockaddr_un

OpenBSD
pub struct C.sockaddr_un {
mut:
	sun_len    u8
	sun_family u8
	sun_path   [max_unix_path]char
}

#struct C.addrinfo

Windows
pub struct C.addrinfo {
mut:
	ai_family    int
	ai_socktype  int
	ai_flags     int
	ai_protocol  int
	ai_addrlen   int
	ai_addr      voidptr
	ai_canonname voidptr
	ai_next      voidptr
}

#struct C.sockaddr_in

Windows
pub struct C.sockaddr_in {
mut:
	sin_family u16
	sin_port   u16
	sin_addr   u32
}

#struct C.sockaddr_in6

Windows
pub struct C.sockaddr_in6 {
mut:
	sin6_family u16
	sin6_port   u16
	sin6_addr   [4]u32
}

#struct C.sockaddr_un

Windows
pub struct C.sockaddr_un {
mut:
	sun_family u16
	sun_path   [max_unix_path]char
}

#struct ShutdownConfig

params
pub struct ShutdownConfig {
	how ShutdownDirection = .read_and_write
}

#struct Socket

pub struct Socket {
pub:
	handle int
}

#fn (&Socket) address

fn (s &Socket) address() !Addr

address gets the address of a socket

#struct TcpConn

heap
pub struct TcpConn {
pub mut:
	sock TcpSocket
mut:
	handle         int
	write_deadline time.Time
	read_deadline  time.Time
	read_timeout   time.Duration
	write_timeout  time.Duration
	is_blocking    bool
}

#fn (&TcpConn) close

fn (mut c &TcpConn) close() !

#fn (TcpConn) read_ptr

fn (c TcpConn) read_ptr(buf_ptr &u8, len int) !int

#fn (TcpConn) read

fn (c TcpConn) read(mut buf &[]u8) !int

#fn (&TcpConn) read_deadline

fn (mut c &TcpConn) read_deadline() !time.Time

#fn (&TcpConn) write_ptr

fn (mut c &TcpConn) write_ptr(b &u8, len int) !int

write_ptr blocks and attempts to write all data

#fn (&TcpConn) write

fn (mut c &TcpConn) write(bytes []u8) !int

write blocks and attempts to write all data

#fn (&TcpConn) write_string

fn (mut c &TcpConn) write_string(s string) !int

write_string blocks and attempts to write all data

#fn (&TcpConn) set_read_deadline

fn (mut c &TcpConn) set_read_deadline(deadline time.Time)

#fn (&TcpConn) write_deadline

fn (mut c &TcpConn) write_deadline() !time.Time

#fn (&TcpConn) set_write_deadline

fn (mut c &TcpConn) set_write_deadline(deadline time.Time)

#fn (&TcpConn) read_timeout

fn (c &TcpConn) read_timeout() time.Duration

#fn (&TcpConn) set_read_timeout

fn (mut c &TcpConn) set_read_timeout(t time.Duration)

#fn (&TcpConn) write_timeout

fn (c &TcpConn) write_timeout() time.Duration

#fn (&TcpConn) set_write_timeout

fn (mut c &TcpConn) set_write_timeout(t time.Duration)

#fn (TcpConn) wait_for_read

inline
fn (c TcpConn) wait_for_read() !

#fn (&TcpConn) wait_for_write

inline
fn (mut c &TcpConn) wait_for_write() !

#fn (&TcpConn) set_sock

fn (mut c &TcpConn) set_sock() !

set_sock initialises the c.sock field. It should be called after .accept_only()!.

Note: just use .accept()!. In most cases it is simpler, and calls .set_sock()! for you.

#fn (&TcpConn) peer_addr

fn (c &TcpConn) peer_addr() !Addr

#fn (&TcpConn) peer_ip

fn (c &TcpConn) peer_ip() !string

#fn (&TcpConn) addr

fn (c &TcpConn) addr() !Addr

#fn (TcpConn) str

fn (c TcpConn) str() string

#fn (&TcpConn) get_blocking

fn (mut con &TcpConn) get_blocking() bool

get_blocking returns whether the connection is in a blocking state, that is calls to .read_line, C.recv etc will block till there is new data arrived, instead of returning immediately.

#fn (&TcpConn) set_blocking

fn (mut con &TcpConn) set_blocking(state bool) !

set_blocking will change the state of the connection to either blocking, when state is true, or non blocking (false).

The default for net tcp connections is the non blocking mode.

Calling .read_line will set the connection to blocking mode.

#fn (&TcpConn) read_line

fn (mut con &TcpConn) read_line() string

read_line is a simple, non customizable, blocking line reader.

It will return a line, ending with LF, or just '', on EOF.

Note: if you want more control over the buffer, please use a buffered IO reader instead: io.new_buffered_reader({reader: io.make_reader(con)})

#fn (&TcpConn) read_line_max

manualfree
fn (mut con &TcpConn) read_line_max(max_line_len int) string

read_line_max is a simple, non customizable, blocking line reader.

It will return a line, ending with LF, '' on EOF.

It stops reading, when the result line length exceeds max_line_len.

#struct TcpListener

pub struct TcpListener {
pub mut:
	sock TcpSocket
mut:
	accept_timeout  time.Duration
	accept_deadline time.Time
}

#fn (&TcpListener) accept

fn (mut l &TcpListener) accept() !&TcpConn

accept a tcp connection from an external source to the listener l.

#fn (&TcpListener) accept_only

fn (mut l &TcpListener) accept_only() !&TcpConn

accept_only accepts a tcp connection from an external source to the listener l.

Unlike accept, accept_only will not call .set_sock()! on the result, and is thus faster.

Note: you need to call .set_sock()! manually, before using the connection after calling .accept_only()!, but that does not have to happen in the same thread that called .accept_only()!.

The intention of this API, is to have a more efficient way to accept connections, that are later processed by a thread pool, while the main thread remains active, so that it can accept other connections.

See also vlib/vweb/vweb.v .

If you do not need that, just call .accept()! instead, which will call .set_sock()! for you.

#fn (&TcpListener) accept_deadline

fn (c &TcpListener) accept_deadline() !time.Time

#fn (&TcpListener) set_accept_deadline

fn (mut c &TcpListener) set_accept_deadline(deadline time.Time)

#fn (&TcpListener) accept_timeout

fn (c &TcpListener) accept_timeout() time.Duration

#fn (&TcpListener) set_accept_timeout

fn (mut c &TcpListener) set_accept_timeout(t time.Duration)

#fn (&TcpListener) wait_for_accept

fn (mut c &TcpListener) wait_for_accept() !

#fn (&TcpListener) close

fn (mut c &TcpListener) close() !

#fn (&TcpListener) addr

fn (c &TcpListener) addr() !Addr

#struct UdpConn

#fn (&UdpConn) write_ptr

fn (mut c &UdpConn) write_ptr(b &u8, len int) !int

#fn (&UdpConn) write

fn (mut c &UdpConn) write(buf []u8) !int

#fn (&UdpConn) write_string

fn (mut c &UdpConn) write_string(s string) !int

#fn (&UdpConn) write_to_ptr

fn (mut c &UdpConn) write_to_ptr(addr Addr, b &u8, len int) !int

#fn (&UdpConn) write_to

fn (mut c &UdpConn) write_to(addr Addr, buf []u8) !int

write_to blocks and writes the buf to the remote addr specified

#fn (&UdpConn) write_to_string

fn (mut c &UdpConn) write_to_string(addr Addr, s string) !int

write_to_string blocks and writes the buf to the remote addr specified

#fn (&UdpConn) read

fn (mut c &UdpConn) read(mut buf &[]u8) !(int, Addr)

read reads from the socket into buf up to buf.len returning the number of bytes read

#fn (&UdpConn) read_deadline

fn (c &UdpConn) read_deadline() !time.Time

#fn (&UdpConn) set_read_deadline

fn (mut c &UdpConn) set_read_deadline(deadline time.Time)

#fn (&UdpConn) write_deadline

fn (c &UdpConn) write_deadline() !time.Time

#fn (&UdpConn) set_write_deadline

fn (mut c &UdpConn) set_write_deadline(deadline time.Time)

#fn (&UdpConn) read_timeout

fn (c &UdpConn) read_timeout() time.Duration

#fn (&UdpConn) set_read_timeout

fn (mut c &UdpConn) set_read_timeout(t time.Duration)

#fn (&UdpConn) write_timeout

fn (c &UdpConn) write_timeout() time.Duration

#fn (&UdpConn) set_write_timeout

fn (mut c &UdpConn) set_write_timeout(t time.Duration)

#fn (&UdpConn) wait_for_read

inline
fn (mut c &UdpConn) wait_for_read() !

#fn (&UdpConn) wait_for_write

inline
fn (mut c &UdpConn) wait_for_write() !

#fn (&UdpConn) str

fn (c &UdpConn) str() string

#fn (&UdpConn) close

fn (mut c &UdpConn) close() !

Interfaces

This section is empty.

Enums

#enum SocketType

pub enum SocketType {
	udp = C.SOCK_DGRAM
	tcp = C.SOCK_STREAM
	seqpacket = C.SOCK_SEQPACKET
}

SocketType are the available sockets

#enum AddrFamily

pub enum AddrFamily {
	unix = C.AF_UNIX
	ip = C.AF_INET
	ip6 = C.AF_INET6
	unspec = C.AF_UNSPEC
}

AddrFamily are the available address families

#enum ShutdownDirection

pub enum ShutdownDirection {
	read
	write
	read_and_write
}

ShutdownDirection is used by shutdown, for specifying the direction for which the communication will be cut.

#enum WsaError

Windows
pub enum WsaError {
	//
	// MessageId: WSAEINTR
	//
	// MessageText:
	//
	// A blocking operation was interrupted by a call to WSACancelBlockingCall.
	//
	wsaeintr = 10004
	//
	// MessageId: WSAEBADF
	//
	// MessageText:
	//
	// The file handle supplied is not valid.
	//
	wsaebadf = 10009
	//
	// MessageId: WSAEACCES
	//
	// MessageText:
	//
	// An attempt was made to access a socket in a way forbidden by its access permissions.
	//
	wsaeacces = 10013
	//
	// MessageId: WSAEFAULT
	//
	// MessageText:
	//
	// The system detected an invalid pointer address in attempting to use a pointer argument in a call.
	//
	wsaefault = 10014
	//
	// MessageId: WSAEINVAL
	//
	// MessageText:
	//
	// An invalid argument was supplied.
	//
	wsaeinval = 10022
	//
	// MessageId: WSAEMFILE
	//
	// MessageText:
	//
	// Too many open sockets.
	//
	wsaemfile = 10024
	//
	// MessageId: WSAEWOULDBLOCK
	//
	// MessageText:
	//
	// A non-blocking socket operation could not be completed immediately.
	//
	wsaewouldblock = 10035
	//
	// MessageId: WSAEINPROGRESS
	//
	// MessageText:
	//
	// A blocking operation is currently executing.
	//
	wsaeinprogress = 10036
	//
	// MessageId: WSAEALREADY
	//
	// MessageText:
	//
	// An operation was attempted on a non-blocking socket that already had an operation in progress.
	//
	wsaealready = 10037
	//
	// MessageId: WSAENOTSOCK
	//
	// MessageText:
	//
	// An operation was attempted on something that is not a socket.
	//
	wsaenotsock = 10038
	//
	// MessageId: WSAEDESTADDRREQ
	//
	// MessageText:
	//
	// A required address was omitted from an operation on a socket.
	//
	wsaedestaddrreq = 10039
	//
	// MessageId: WSAEMSGSIZE
	//
	// MessageText:
	//
	// A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself.
	//
	wsaemsgsize = 10040
	//
	// MessageId: WSAEPROTOTYPE
	//
	// MessageText:
	//
	// A protocol was specified in the socket function call that does not support the semantics of the socket type requested.
	//
	wsaeprototype = 10041
	//
	// MessageId: WSAENOPROTOOPT
	//
	// MessageText:
	//
	// An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call.
	//
	wsaenoprotoopt = 10042
	//
	// MessageId: WSAEPROTONOSUPPORT
	//
	// MessageText:
	//
	// The requested protocol has not been configured into the system, or no implementation for it exists.
	//
	wsaeprotonosupport = 10043
	//
	// MessageId: WSAESOCKTNOSUPPORT
	//
	// MessageText:
	//
	// The support for the specified socket type does not exist in this address family.
	//
	wsaesocktnosupport = 10044
	//
	// MessageId: WSAEOPNOTSUPP
	//
	// MessageText:
	//
	// The attempted operation is not supported for the type of object referenced.
	//
	wsaeopnotsupp = 10045
	//
	// MessageId: WSAEPFNOSUPPORT
	//
	// MessageText:
	//
	// The protocol family has not been configured into the system or no implementation for it exists.
	//
	wsaepfnosupport = 10046
	//
	// MessageId: WSAEAFNOSUPPORT
	//
	// MessageText:
	//
	// An address incompatible with the requested protocol was used.
	//
	wsaeafnosupport = 10047
	//
	// MessageId: WSAEADDRINUSE
	//
	// MessageText:
	//
	// Only one usage of each socket address (protocol/network address/port) is normally permitted.
	//
	wsaeaddrinuse = 10048
	//
	// MessageId: WSAEADDRNOTAVAIL
	//
	// MessageText:
	//
	// The requested address is not valid in its context.
	//
	wsaeaddrnotavail = 10049
	//
	// MessageId: WSAENETDOWN
	//
	// MessageText:
	//
	// A socket operation encountered a dead network.
	//
	wsaenetdown = 10050
	//
	// MessageId: WSAENETUNREACH
	//
	// MessageText:
	//
	// A socket operation was attempted to an unreachable network.
	//
	wsaenetunreach = 10051
	//
	// MessageId: WSAENETRESET
	//
	// MessageText:
	//
	// The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress.
	//
	wsaenetreset = 10052
	//
	// MessageId: WSAECONNABORTED
	//
	// MessageText:
	//
	// An established connection was aborted by the software in your host machine.
	//
	wsaeconnaborted = 10053
	//
	// MessageId: WSAECONNRESET
	//
	// MessageText:
	//
	// An existing connection was forcibly closed by the remote host.
	//
	wsaeconnreset = 10054
	//
	// MessageId: WSAENOBUFS
	//
	// MessageText:
	//
	// An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.
	//
	wsaenobufs = 10055
	//
	// MessageId: WSAEISCONN
	//
	// MessageText:
	//
	// A connect request was made on an already connected socket.
	//
	wsaeisconn = 10056
	//
	// MessageId: WSAENOTCONN
	//
	// MessageText:
	//
	// A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.
	//
	wsaenotconn = 10057
	//
	// MessageId: WSAESHUTDOWN
	//
	// MessageText:
	//
	// A request to send or receive data was disallowed because the socket had already been shut down in that direction with a previous shutdown call.
	//
	wsaeshutdown = 10058
	//
	// MessageId: WSAETOOMANYREFS
	//
	// MessageText:
	//
	// Too many references to some kernel object.
	//
	wsaetoomanyrefs = 10059
	//
	// MessageId: WSAETIMEDOUT
	//
	// MessageText:
	//
	// A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
	//
	wsaetimedout = 10060
	//
	// MessageId: WSAECONNREFUSED
	//
	// MessageText:
	//
	// No connection could be made because the target machine actively refused it.
	//
	wsaeconnrefused = 10061
	//
	// MessageId: WSAELOOP
	//
	// MessageText:
	//
	// Cannot translate name.
	//
	wsaeloop = 10062
	//
	// MessageId: WSAENAMETOOLONG
	//
	// MessageText:
	//
	// Name component or name was too long.
	//
	wsaenametoolong = 10063
	//
	// MessageId: WSAEHOSTDOWN
	//
	// MessageText:
	//
	// A socket operation failed because the destination host was down.
	//
	wsaehostdown = 10064
	//
	// MessageId: WSAEHOSTUNREACH
	//
	// MessageText:
	//
	// A socket operation was attempted to an unreachable host.
	//
	wsaehostunreach = 10065
	//
	// MessageId: WSAENOTEMPTY
	//
	// MessageText:
	//
	// Cannot remove a directory that is not empty.
	//
	wsaenotempty = 10066
	//
	// MessageId: WSAEPROCLIM
	//
	// MessageText:
	//
	// A Windows Sockets implementation may have a limit on the number of applications that may use it simultaneously.
	//
	wsaeproclim = 10067
	//
	// MessageId: WSAEUSERS
	//
	// MessageText:
	//
	// Ran out of quota.
	//
	wsaeusers = 10068
	//
	// MessageId: WSAEDQUOT
	//
	// MessageText:
	//
	// Ran out of disk quota.
	//
	wsaedquot = 10069
	//
	// MessageId: WSAESTALE
	//
	// MessageText:
	//
	// File handle reference is no longer available.
	//
	wsaestale = 10070
	//
	// MessageId: WSAEREMOTE
	//
	// MessageText:
	//
	// Item is not available locally.
	//
	wsaeremote = 10071
	//
	// MessageId: WSASYSNOTREADY
	//
	// MessageText:
	//
	// WSAStartup cannot function at this time because the underlying system it uses to provide network services is currently unavailable.
	//
	wsasysnotready = 10091
	//
	// MessageId: WSAVERNOTSUPPORTED
	//
	// MessageText:
	//
	// The Windows Sockets version requested is not supported.
	//
	wsavernotsupported = 10092
	//
	// MessageId: WSANOTINITIALISED
	//
	// MessageText:
	//
	// Either the application has not called WSAStartup, or WSAStartup failed.
	//
	wsanotinitialised = 10093
	//
	// MessageId: WSAEDISCON
	//
	// MessageText:
	//
	// Returned by WSARecv or WSARecvFrom to indicate the remote party has initiated a graceful shutdown sequence.
	//
	wsaediscon = 10101
	//
	// MessageId: WSAENOMORE
	//
	// MessageText:
	//
	// No more results can be returned by WSALookupServiceNext.
	//
	wsaenomore = 10102
	//
	// MessageId: WSAECANCELLED
	//
	// MessageText:
	//
	// A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled.
	//
	wsaecancelled = 10103
	//
	// MessageId: WSAEINVALIDPROCTABLE
	//
	// MessageText:
	//
	// The procedure call table is invalid.
	//
	wsaeinvalidproctable = 10104
	//
	// MessageId: WSAEINVALIDPROVIDER
	//
	// MessageText:
	//
	// The requested service provider is invalid.
	//
	wsaeinvalidprovider = 10105
	//
	// MessageId: WSAEPROVIDERFAILEDINIT
	//
	// MessageText:
	//
	// The requested service provider could not be loaded or initialized.
	//
	wsaeproviderfailedinit = 10106
	//
	// MessageId: WSASYSCALLFAILURE
	//
	// MessageText:
	//
	// A system call has failed.
	//
	wsasyscallfailure = 10107
	//
	// MessageId: WSASERVICE_NOT_FOUND
	//
	// MessageText:
	//
	// No such service is known. The service cannot be found in the specified name space.
	//
	wsaservice_not_found = 10108
	//
	// MessageId: WSATYPE_NOT_FOUND
	//
	// MessageText:
	//
	// The specified class was not found.
	//
	wsatype_not_found = 10109
	//
	// MessageId: WSA_E_NO_MORE
	//
	// MessageText:
	//
	// No more results can be returned by WSALookupServiceNext.
	//
	wsa_e_no_more = 10110
	//
	// MessageId: WSA_E_CANCELLED
	//
	// MessageText:
	//
	// A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled.
	//
	wsa_e_cancelled = 10111
	//
	// MessageId: WSAEREFUSED
	//
	// MessageText:
	//
	// A database query failed because it was actively refused.
	//
	wsaerefused = 10112
	//
	// MessageId: WSAHOST_NOT_FOUND
	//
	// MessageText:
	//
	// No such host is known.
	//
	wsahost_not_found = 11001
	//
	// MessageId: WSATRY_AGAIN
	//
	// MessageText:
	//
	// This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server.
	//
	wsatry_again = 11002
	//
	// MessageId: WSANO_RECOVERY
	//
	// MessageText:
	//
	// A non-recoverable error occurred during a database lookup.
	//
	wsano_recovery = 11003
	//
	// MessageId: WSANO_DATA
	//
	// MessageText:
	//
	// The requested name is valid, but no data of the requested type was found.
	//
	wsano_data = 11004
	//
	// MessageId: WSA_QOS_RECEIVERS
	//
	// MessageText:
	//
	// At least one reserve has arrived.
	//
	wsa_qos_receivers = 11005
	//
	// MessageId: WSA_QOS_SENDERS
	//
	// MessageText:
	//
	// At least one path has arrived.
	//
	wsa_qos_senders = 11006
	//
	// MessageId: WSA_QOS_NO_SENDERS
	//
	// MessageText:
	//
	// There are no senders.
	//
	wsa_qos_no_senders = 11007
	//
	// MessageId: WSA_QOS_NO_RECEIVERS
	//
	// MessageText:
	//
	// There are no receivers.
	//
	wsa_qos_no_receivers = 11008
	//
	// MessageId: WSA_QOS_REQUEST_CONFIRMED
	//
	// MessageText:
	//
	// Reserve has been confirmed.
	//
	wsa_qos_request_confirmed = 11009
	//
	// MessageId: WSA_QOS_ADMISSION_FAILURE
	//
	// MessageText:
	//
	// Error due to lack of resources.
	//
	wsa_qos_admission_failure = 11010
	//
	// MessageId: WSA_QOS_POLICY_FAILURE
	//
	// MessageText:
	//
	// Rejected for administrative reasons - bad credentials.
	//
	wsa_qos_policy_failure = 11011
	//
	// MessageId: WSA_QOS_BAD_STYLE
	//
	// MessageText:
	//
	// Unknown or conflicting style.
	//
	wsa_qos_bad_style = 11012
	//
	// MessageId: WSA_QOS_BAD_OBJECT
	//
	// MessageText:
	//
	// Problem with some part of the filterspec or providerspecific buffer in general.
	//
	wsa_qos_bad_object = 11013
	//
	// MessageId: WSA_QOS_TRAFFIC_CTRL_ERROR
	//
	// MessageText:
	//
	// Problem with some part of the flowspec.
	//
	wsa_qos_traffic_ctrl_error = 11014
	//
	// MessageId: WSA_QOS_GENERIC_ERROR
	//
	// MessageText:
	//
	// General QOS error.
	//
	wsa_qos_generic_error = 11015
	//
	// MessageId: WSA_QOS_ESERVICETYPE
	//
	// MessageText:
	//
	// An invalid or unrecognized service type was found in the flowspec.
	//
	wsa_qos_eservicetype = 11016
	//
	// MessageId: WSA_QOS_EFLOWSPEC
	//
	// MessageText:
	//
	// An invalid or inconsistent flowspec was found in the QOS structure.
	//
	wsa_qos_eflowspec = 11017
	//
	// MessageId: WSA_QOS_EPROVSPECBUF
	//
	// MessageText:
	//
	// Invalid QOS provider-specific buffer.
	//
	wsa_qos_eprovspecbuf = 11018
	//
	// MessageId: WSA_QOS_EFILTERSTYLE
	//
	// MessageText:
	//
	// An invalid QOS filter style was used.
	//
	wsa_qos_efilterstyle = 11019
	//
	// MessageId: WSA_QOS_EFILTERTYPE
	//
	// MessageText:
	//
	// An invalid QOS filter type was used.
	//
	wsa_qos_efiltertype = 11020
	//
	// MessageId: WSA_QOS_EFILTERCOUNT
	//
	// MessageText:
	//
	// An incorrect number of QOS FILTERSPECs were specified in the FLOWDESCRIPTOR.
	//
	wsa_qos_efiltercount = 11021
	//
	// MessageId: WSA_QOS_EOBJLENGTH
	//
	// MessageText:
	//
	// An object with an invalid ObjectLength field was specified in the QOS provider-specific buffer.
	//
	wsa_qos_eobjlength = 11022
	//
	// MessageId: WSA_QOS_EFLOWCOUNT
	//
	// MessageText:
	//
	// An incorrect number of flow descriptors was specified in the QOS structure.
	//
	wsa_qos_eflowcount = 11023
	//
	// MessageId: WSA_QOS_EUNKOWNPSOBJ
	//
	// MessageText:
	//
	// An unrecognized object was found in the QOS provider-specific buffer.
	//
	wsa_qos_eunkownpsobj = 11024
	//
	// MessageId: WSA_QOS_EPOLICYOBJ
	//
	// MessageText:
	//
	// An invalid policy object was found in the QOS provider-specific buffer.
	//
	wsa_qos_epolicyobj = 11025
	//
	// MessageId: WSA_QOS_EFLOWDESC
	//
	// MessageText:
	//
	// An invalid QOS flow descriptor was found in the flow descriptor list.
	//
	wsa_qos_eflowdesc = 11026
	//
	// MessageId: WSA_QOS_EPSFLOWSPEC
	//
	// MessageText:
	//
	// An invalid or inconsistent flowspec was found in the QOS provider specific buffer.
	//
	wsa_qos_epsflowspec = 11027
	//
	// MessageId: WSA_QOS_EPSFILTERSPEC
	//
	// MessageText:
	//
	// An invalid FILTERSPEC was found in the QOS provider-specific buffer.
	//
	wsa_qos_epsfilterspec = 11028
	//
	// MessageId: WSA_QOS_ESDMODEOBJ
	//
	// MessageText:
	//
	// An invalid shape discard mode object was found in the QOS provider specific buffer.
	//
	wsa_qos_esdmodeobj = 11029
	//
	// MessageId: WSA_QOS_ESHAPERATEOBJ
	//
	// MessageText:
	//
	// An invalid shaping rate object was found in the QOS provider-specific buffer.
	//
	wsa_qos_eshaperateobj = 11030
	//
	// MessageId: WSA_QOS_RESERVED_PETYPE
	//
	// MessageText:
	//
	// A reserved policy element was found in the QOS provider-specific buffer.
	//
	wsa_qos_reserved_petype = 11031
	//
	// MessageId: WSA_SECURE_HOST_NOT_FOUND
	//
	// MessageText:
	//
	// No such host is known securely.
	//
	wsa_secure_host_not_found = 11032
	//
	// MessageId: WSA_IPSEC_NAME_POLICY_ERROR
	//
	// MessageText:
	//
	// Name based IPSEC policy could not be added.
	//
	wsa_ipsec_name_policy_error = 11033
}

WsaError is all of the socket errors that WSA provides from WSAGetLastError

#enum SocketOption

pub enum SocketOption {
	// TODO: SO_ACCEPT_CONN is not here because windows doesnt support it
	// and there is no easy way to define it
	broadcast = C.SO_BROADCAST
	debug = C.SO_DEBUG
	dont_route = C.SO_DONTROUTE
	error = C.SO_ERROR
	keep_alive = C.SO_KEEPALIVE
	linger = C.SO_LINGER
	oob_inline = C.SO_OOBINLINE
	reuse_addr = C.SO_REUSEADDR
	recieve_buf_size = C.SO_RCVBUF
	recieve_low_size = C.SO_RCVLOWAT
	recieve_timeout = C.SO_RCVTIMEO
	send_buf_size = C.SO_SNDBUF
	send_low_size = C.SO_SNDLOWAT
	send_timeout = C.SO_SNDTIMEO
	socket_type = C.SO_TYPE
	ipv6_only = C.IPV6_V6ONLY
}