8.5 KiB
module unix
Contents
- close
- connect_stream
- listen_stream
- shutdown
- stream_socket_from_handle
- ListenOptions
- StreamConn
- StreamListener
- StreamSocket
- UnixDialer
close
fn close(handle int) !
close a socket, given its file descriptor handle.
connect_stream
fn connect_stream(socket_path string) !&StreamConn
connect_stream returns a SOCK_STREAM connection for an unix domain socket on socket_path
listen_stream
fn listen_stream(socket_path string, options ListenOptions) !&StreamListener
listen_stream creates an unix domain socket at socket_path
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)
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
ListenOptions
struct ListenOptions {
pub:
backlog int = 128
}
StreamConn
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
}
addr
fn (c StreamConn) addr() !net.Addr
addr returns the local address of the stream
peer_addr
fn (c StreamConn) peer_addr() !net.Addr
peer_addr returns the address of the remote peer of the stream
close
fn (mut c StreamConn) close() !
close closes the connection
write_ptr
fn (mut c StreamConn) write_ptr(b &u8, len int) !int
write_ptr blocks and attempts to write all data
write
fn (mut c StreamConn) write(bytes []u8) !int
write blocks and attempts to write all data
write_string
fn (mut c StreamConn) write_string(s string) !int
write_string blocks and attempts to write all data
read_ptr
fn (mut c StreamConn) read_ptr(buf_ptr &u8, len int) !int
read_ptr attempts to write all data
read
fn (mut c StreamConn) read(mut buf []u8) !int
read data into buf
read_deadline
fn (mut c StreamConn) read_deadline() !time.Time
read_deadline returns the read deadline
set_read_deadline
fn (mut c StreamConn) set_read_deadline(deadline time.Time)
set_read_deadlien sets the read deadline
write_deadline
fn (mut c StreamConn) write_deadline() !time.Time
write_deadline returns the write deadline
set_write_deadline
fn (mut c StreamConn) set_write_deadline(deadline time.Time)
set_write_deadline sets the write deadline
read_timeout
fn (c &StreamConn) read_timeout() time.Duration
read_timeout returns the read timeout
set_read_timeout
fn (mut c StreamConn) set_read_timeout(t time.Duration)
set_read_timeout sets the read timeout
write_timeout
fn (c &StreamConn) write_timeout() time.Duration
write_timeout returns the write timeout
set_write_timeout
fn (mut c StreamConn) set_write_timeout(t time.Duration)
set_write_timeout sets the write timeout
wait_for_read
fn (mut c StreamConn) wait_for_read() !
wait_for_read blocks until the socket is ready to read
wait_for_write
fn (mut c StreamConn) wait_for_write() !
wait_for_read blocks until the socket is ready to write
str
fn (c StreamConn) str() string
str returns a string representation of connection c
StreamListener
struct StreamListener {
pub mut:
sock StreamSocket
mut:
accept_timeout time.Duration
accept_deadline time.Time
}
accept
fn (mut l StreamListener) accept() !&StreamConn
accept accepts blocks until a new connection occurs
accept_deadline
fn (l &StreamListener) accept_deadline() !time.Time
accept_deadline returns the deadline until a new client is accepted
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
accept_timeout
fn (l &StreamListener) accept_timeout() time.Duration
accept_timeout returns the timeout until a new client is accepted
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
wait_for_accept
fn (mut l StreamListener) wait_for_accept() !
wait_for_accept blocks until a client can be accepted
close
fn (mut l StreamListener) close() !
close closes the listening socket and unlinks/removes the socket file
unlink
fn (mut l StreamListener) unlink() !
unlink removes the unix socket from the file system
unlink_on_signal
fn (mut l StreamListener) unlink_on_signal(signum os.Signal) !
unlink_on_signal removes the socket from the filesystem when signal signum occurs
addr
fn (mut l StreamListener) addr() !net.Addr
addr returns the net.Addr version of the listening socket's path
StreamSocket
struct StreamSocket {
net.Socket
mut:
socket_path string
}
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
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
UnixDialer
struct UnixDialer {}
UnixDialer is a concrete instance of the Dialer interface, for creating unix socket connections.
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.