Skip to content

net.unix #

fn close #

fn close(handle int) !

close a socket, given its file descriptor handle.

fn connect_stream #

fn connect_stream(socket_path string) !&StreamConn

connect_stream returns a SOCK_STREAM connection for an unix domain socket on socket_path

fn listen_stream #

fn listen_stream(socket_path string, options ListenOptions) !&StreamListener

listen_stream creates an unix domain socket at socket_path

fn shutdown #

fn shutdown(handle int, config net.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 stream_socket_from_handle #

fn stream_socket_from_handle(sockfd int) !&StreamSocket

stream_socket_from_handle returns a StreamSocket instance from the raw file descriptor sockfd

struct ListenOptions #

@[params]
struct ListenOptions {
pub:
	backlog int = 128
}

struct StreamConn #

@[heap]
struct StreamConn {
pub mut:
	sock StreamSocket
mut:
	handle         int
	write_deadline time.Time
	read_deadline  time.Time
	read_timeout   time.Duration
	write_timeout  time.Duration
	is_blocking    bool
}

fn (StreamConn) addr #

fn (c StreamConn) addr() !net.Addr

addr returns the local address of the stream

fn (StreamConn) peer_addr #

fn (c StreamConn) peer_addr() !net.Addr

peer_addr returns the address of the remote peer of the stream

fn (StreamConn) close #

fn (mut c StreamConn) close() !

close closes the connection

fn (StreamConn) write_ptr #

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

write_ptr blocks and attempts to write all data

fn (StreamConn) write #

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

write blocks and attempts to write all data

fn (StreamConn) write_string #

fn (mut c StreamConn) write_string(s string) !int

write_string blocks and attempts to write all data

fn (StreamConn) read_ptr #

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

read_ptr attempts to write all data

fn (StreamConn) read #

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

read data into buf

fn (StreamConn) read_deadline #

fn (mut c StreamConn) read_deadline() !time.Time

read_deadline returns the read deadline

fn (StreamConn) set_read_deadline #

fn (mut c StreamConn) set_read_deadline(deadline time.Time)

set_read_deadlien sets the read deadline

fn (StreamConn) write_deadline #

fn (mut c StreamConn) write_deadline() !time.Time

write_deadline returns the write deadline

fn (StreamConn) set_write_deadline #

fn (mut c StreamConn) set_write_deadline(deadline time.Time)

set_write_deadline sets the write deadline

fn (StreamConn) read_timeout #

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

read_timeout returns the read timeout

fn (StreamConn) set_read_timeout #

fn (mut c StreamConn) set_read_timeout(t time.Duration)

set_read_timeout sets the read timeout

fn (StreamConn) write_timeout #

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

write_timeout returns the write timeout

fn (StreamConn) set_write_timeout #

fn (mut c StreamConn) set_write_timeout(t time.Duration)

set_write_timeout sets the write timeout

fn (StreamConn) wait_for_read #

fn (mut c StreamConn) wait_for_read() !

wait_for_read blocks until the socket is ready to read

fn (StreamConn) wait_for_write #

fn (mut c StreamConn) wait_for_write() !

wait_for_read blocks until the socket is ready to write

fn (StreamConn) str #

fn (c StreamConn) str() string

str returns a string representation of connection c

struct StreamListener #

struct StreamListener {
pub mut:
	sock StreamSocket
mut:
	accept_timeout  time.Duration
	accept_deadline time.Time
}

fn (StreamListener) accept #

fn (mut l StreamListener) accept() !&StreamConn

accept accepts blocks until a new connection occurs

fn (StreamListener) accept_deadline #

fn (l &StreamListener) accept_deadline() !time.Time

accept_deadline returns the deadline until a new client is accepted

fn (StreamListener) set_accept_deadline #

fn (mut l StreamListener) set_accept_deadline(deadline time.Time)

set_accept_deadline sets the deadlinme until a new client is accepted

fn (StreamListener) accept_timeout #

fn (l &StreamListener) accept_timeout() time.Duration

accept_timeout returns the timeout until a new client is accepted

fn (StreamListener) set_accept_timeout #

fn (mut l StreamListener) set_accept_timeout(t time.Duration)

set_accept_timeout sets the timeout until a new client is accepted

fn (StreamListener) wait_for_accept #

fn (mut l StreamListener) wait_for_accept() !

wait_for_accept blocks until a client can be accepted

fn (StreamListener) close #

fn (mut l StreamListener) close() !

close closes the listening socket and unlinks/removes the socket file

fn (StreamListener) addr #

fn (mut l StreamListener) addr() !net.Addr

addr returns the net.Addr version of the listening socket's path

struct StreamSocket #

struct StreamSocket {
	net.Socket
mut:
	socket_path string
}

fn (StreamSocket) set_option_bool #

fn (mut s StreamSocket) set_option_bool(opt net.SocketOption, value bool) !

set_option_bool sets a boolean option on the socket

fn (StreamSocket) set_option_int #

fn (mut s StreamSocket) set_option_int(opt net.SocketOption, value int) !

set_option_bool sets an int option on the socket

struct UnixDialer #

struct UnixDialer {}

UnixDialer is a concrete instance of the Dialer interface, for creating unix socket connections.

fn (UnixDialer) dial #

fn (u UnixDialer) dial(address string) !net.Connection

dial will try to create a new abstract connection to the given address. It will return an error, if that is not possible.