Files
herolib/aiprompts/v_core/net/unix.md
2025-09-02 07:28:13 +02:00

8.5 KiB

module unix

Contents

close

fn close(handle int) !

close a socket, given its file descriptor handle.

[Return to contents]

connect_stream

fn connect_stream(socket_path string) !&StreamConn

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

[Return to contents]

listen_stream

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

listen_stream creates an unix domain socket at socket_path

[Return to contents]

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)

[Return to contents]

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

[Return to contents]

ListenOptions

struct ListenOptions {
pub:
	backlog int = 128
}

[Return to contents]

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
}

[Return to contents]

addr

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

addr returns the local address of the stream

[Return to contents]

peer_addr

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

peer_addr returns the address of the remote peer of the stream

[Return to contents]

close

fn (mut c StreamConn) close() !

close closes the connection

[Return to contents]

write_ptr

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

write_ptr blocks and attempts to write all data

[Return to contents]

write

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

write blocks and attempts to write all data

[Return to contents]

write_string

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

write_string blocks and attempts to write all data

[Return to contents]

read_ptr

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

read_ptr attempts to write all data

[Return to contents]

read

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

read data into buf

[Return to contents]

read_deadline

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

read_deadline returns the read deadline

[Return to contents]

set_read_deadline

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

set_read_deadlien sets the read deadline

[Return to contents]

write_deadline

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

write_deadline returns the write deadline

[Return to contents]

set_write_deadline

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

set_write_deadline sets the write deadline

[Return to contents]

read_timeout

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

read_timeout returns the read timeout

[Return to contents]

set_read_timeout

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

set_read_timeout sets the read timeout

[Return to contents]

write_timeout

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

write_timeout returns the write timeout

[Return to contents]

set_write_timeout

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

set_write_timeout sets the write timeout

[Return to contents]

wait_for_read

fn (mut c StreamConn) wait_for_read() !

wait_for_read blocks until the socket is ready to read

[Return to contents]

wait_for_write

fn (mut c StreamConn) wait_for_write() !

wait_for_read blocks until the socket is ready to write

[Return to contents]

str

fn (c StreamConn) str() string

str returns a string representation of connection c

[Return to contents]

StreamListener

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

[Return to contents]

accept

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

accept accepts blocks until a new connection occurs

[Return to contents]

accept_deadline

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

accept_deadline returns the deadline until a new client is accepted

[Return to contents]

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

[Return to contents]

accept_timeout

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

accept_timeout returns the timeout until a new client is accepted

[Return to contents]

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

[Return to contents]

wait_for_accept

fn (mut l StreamListener) wait_for_accept() !

wait_for_accept blocks until a client can be accepted

[Return to contents]

close

fn (mut l StreamListener) close() !

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

[Return to contents]

fn (mut l StreamListener) unlink() !

unlink removes the unix socket from the file system

[Return to contents]

fn (mut l StreamListener) unlink_on_signal(signum os.Signal) !

unlink_on_signal removes the socket from the filesystem when signal signum occurs

[Return to contents]

addr

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

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

[Return to contents]

StreamSocket

struct StreamSocket {
	net.Socket
mut:
	socket_path string
}

[Return to contents]

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

[Return to contents]

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

[Return to contents]

UnixDialer

struct UnixDialer {}

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

[Return to contents]

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.

[Return to contents]

Powered by vdoc. Generated on: 2 Sep 2025 07:16:36