const (
no_timeout = time.Duration(0)
)
no_timeout should be given to functions when no timeout is wanted (i.e. all functions return instantly)
const (
infinite_timeout = time.Duration(-1)
)
infinite_timeout should be given to functions when an infinite_timeout is wanted (i.e. functions only ever return with data)
const (
err_new_socket_failed = error_with_code('net: new_socket failed to create socket',
errors_base + 1)
err_option_not_settable = error_with_code('net: set_option_xxx option not settable',
errors_base + 2)
err_option_wrong_type = error_with_code('net: set_option_xxx option wrong type',
errors_base + 3)
err_port_out_of_range = error_with_code('', errors_base + 5)
err_no_udp_remote = error_with_code('', errors_base + 6)
err_connect_failed = error_with_code('net: connect failed', errors_base + 7)
err_connect_timed_out = error_with_code('net: connect timed out', errors_base + 8)
err_timed_out = error_with_code('net: op timed out', errors_base + 9)
err_timed_out_code = errors_base + 9
)
Well defined errors that are returned from socket functions
const (
msg_nosignal = 0x4000
)
fn dial_tcp(address string) ?&TcpConn
fn dial_udp(laddr string, raddr string) ?&UdpConn
fn listen_tcp(port int) ?&TcpListener
fn listen_udp(port int) ?&UdpConn
fn resolve_addr(addr string, family SocketFamily, typ SocketType) ?Addr
fn socket_error(potential_code int) ?int
fn split_address(addr string) ?(string, u16)
split address splits an address into its host name and its 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(error_code int) ?
fn (mut s TcpSocket) set_option_bool(opt SocketOption, value bool) ?
fn (mut s TcpSocket) set_option_int(opt SocketOption, value int) ?
fn (s &TcpSocket) address() ?Addr
address gets the address of a socket
fn (s &UdpSocket) remote() ?Addr
fn (mut s UdpSocket) set_option_bool(opt SocketOption, value bool) ?
enum SocketFamily {
unix = C.AF_UNIX
inet = C.AF_INET
}
SocketFamily are the available address families
enum SocketType {
udp = C.SOCK_DGRAM
tcp = C.SOCK_STREAM
dgram = C.SOCK_DGRAM
stream = C.SOCK_STREAM
seqpacket = C.SOCK_SEQPACKET
}
SocketType are the available sockets
struct Addr {
addr C.sockaddr
len int
pub:
saddr string
port int
}
Addr represents an ip address
fn (a Addr) str() string
struct C.fd_set {}
struct TcpConn {
pub mut:
sock TcpSocket
mut:
write_deadline time.Time
read_deadline time.Time
read_timeout time.Duration
write_timeout time.Duration
}
fn (mut c TcpConn) close() ?
fn (c &TcpConn) peer_addr() ?Addr
fn (c &TcpConn) peer_ip() ?string
fn (mut c TcpConn) read(mut buf []byte) ?int
fn (mut c TcpConn) read_deadline() ?time.Time
fn (mut con TcpConn) read_line() string
read_line is a simple, non customizable, blocking line reader. It will always return a line, ending with CRLF, or just '', on EOF. NB: 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 (mut c TcpConn) read_ptr(buf_ptr &byte, len int) ?int
fn (c &TcpConn) read_timeout() time.Duration
fn (mut c TcpConn) set_read_deadline(deadline time.Time)
fn (mut c TcpConn) set_read_timeout(t time.Duration)
fn (mut c TcpConn) set_write_deadline(deadline time.Time)
fn (mut c TcpConn) set_write_timeout(t time.Duration)
fn (c TcpConn) str() string
fn (mut c TcpConn) wait_for_read() ?
fn (mut c TcpConn) wait_for_write() ?
fn (mut c TcpConn) write(bytes []byte) ?int
write blocks and attempts to write all data
fn (mut c TcpConn) write_deadline() ?time.Time
fn (mut c TcpConn) write_ptr(b &byte, len int) ?int
write_ptr blocks and attempts to write all data
fn (mut c TcpConn) write_str(s string) ?int
write_str blocks and attempts to write all data
fn (mut c TcpConn) write_string(s string) ?int
write_string blocks and attempts to write all data
fn (c &TcpConn) write_timeout() time.Duration
struct TcpListener {
pub mut:
sock TcpSocket
mut:
accept_timeout time.Duration
accept_deadline time.Time
}
fn (mut l TcpListener) accept() ?&TcpConn
fn (c &TcpListener) accept_deadline() ?time.Time
fn (mut c TcpListener) set_accept_deadline(deadline time.Time)
fn (c &TcpListener) accept_timeout() time.Duration
fn (mut c TcpListener) set_accept_timeout(t time.Duration)
fn (mut c TcpListener) wait_for_accept() ?
fn (mut c TcpListener) close() ?
fn (c &TcpListener) address() ?Addr
struct UdpConn {
pub mut:
sock UdpSocket
mut:
write_deadline time.Time
read_deadline time.Time
read_timeout time.Duration
write_timeout time.Duration
}
fn (mut c UdpConn) write_ptr(b &byte, len int) ?int
fn (mut c UdpConn) write(buf []byte) ?int
fn (mut c UdpConn) write_str(s string) ?int
fn (mut c UdpConn) write_string(s string) ?int
fn (mut c UdpConn) write_to_ptr(addr Addr, b &byte, len int) ?int
fn (mut c UdpConn) write_to(addr Addr, buf []byte) ?int
write_to blocks and writes the buf to the remote addr specified
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 (mut c UdpConn) read(mut buf []byte) ?(int, Addr)
read reads from the socket into buf up to buf.len returning the number of bytes read
fn (c &UdpConn) read_deadline() ?time.Time
fn (mut c UdpConn) set_read_deadline(deadline time.Time)
fn (c &UdpConn) write_deadline() ?time.Time
fn (mut c UdpConn) set_write_deadline(deadline time.Time)
fn (c &UdpConn) read_timeout() time.Duration
fn (mut c UdpConn) set_read_timeout(t time.Duration)
fn (c &UdpConn) write_timeout() time.Duration
fn (mut c UdpConn) set_write_timeout(t time.Duration)
fn (mut c UdpConn) wait_for_read() ?
fn (mut c UdpConn) wait_for_write() ?
fn (c &UdpConn) str() string
fn (mut c UdpConn) close() ?