pub trait SocketOps:
Send
+ Sync
+ AsAny {
Show 17 methods
// Required methods
fn connect(
&self,
socket: &SocketHandle,
current_task: &CurrentTask,
peer: SocketPeer,
) -> Result<(), Errno>;
fn listen(
&self,
socket: &Socket,
backlog: i32,
credentials: ucred,
) -> Result<(), Errno>;
fn accept(
&self,
socket: &Socket,
current_task: &CurrentTask,
) -> Result<SocketHandle, Errno>;
fn bind(
&self,
socket: &Socket,
current_task: &CurrentTask,
socket_address: SocketAddress,
) -> Result<(), Errno>;
fn read(
&self,
socket: &Socket,
current_task: &CurrentTask,
data: &mut dyn OutputBuffer,
flags: SocketMessageFlags,
) -> Result<MessageReadInfo, Errno>;
fn write(
&self,
socket: &Socket,
current_task: &CurrentTask,
data: &mut dyn InputBuffer,
dest_address: &mut Option<SocketAddress>,
ancillary_data: &mut Vec<AncillaryData>,
) -> Result<usize, Errno>;
fn wait_async(
&self,
socket: &Socket,
current_task: &CurrentTask,
waiter: &Waiter,
events: FdEvents,
handler: EventHandler,
) -> WaitCanceler;
fn query_events(
&self,
socket: &Socket,
current_task: &CurrentTask,
) -> Result<FdEvents, Errno>;
fn shutdown(
&self,
socket: &Socket,
how: SocketShutdownFlags,
) -> Result<(), Errno>;
fn close(&self, current_task: &CurrentTask, socket: &Socket);
fn getsockname(&self, socket: &Socket) -> Result<SocketAddress, Errno>;
fn getpeername(&self, socket: &Socket) -> Result<SocketAddress, Errno>;
// Provided methods
fn get_socket_info(
&self,
) -> Result<(SocketDomain, SocketType, SocketProtocol), Errno> { ... }
fn setsockopt(
&self,
_socket: &Socket,
_current_task: &CurrentTask,
_level: u32,
_optname: u32,
_optval: SockOptValue,
) -> Result<(), Errno> { ... }
fn getsockopt(
&self,
_socket: &Socket,
_current_task: &CurrentTask,
_level: u32,
_optname: u32,
_optlen: u32,
) -> Result<Vec<u8>, Errno> { ... }
fn ioctl(
&self,
_socket: &Socket,
_file: &FileObject,
_current_task: &CurrentTask,
_request: u32,
_arg: SyscallArg,
) -> Result<SyscallResult, Errno> { ... }
fn to_handle(
&self,
_socket: &Socket,
_current_task: &CurrentTask,
) -> Result<Option<NullableHandle>, Errno> { ... }
}Required Methods§
Sourcefn connect(
&self,
socket: &SocketHandle,
current_task: &CurrentTask,
peer: SocketPeer,
) -> Result<(), Errno>
fn connect( &self, socket: &SocketHandle, current_task: &CurrentTask, peer: SocketPeer, ) -> Result<(), Errno>
Connect the socket to the listening peer. On success
a new socket is created and added to the accept queue.
Sourcefn listen(
&self,
socket: &Socket,
backlog: i32,
credentials: ucred,
) -> Result<(), Errno>
fn listen( &self, socket: &Socket, backlog: i32, credentials: ucred, ) -> Result<(), Errno>
Start listening at the bound address for connect calls.
Sourcefn accept(
&self,
socket: &Socket,
current_task: &CurrentTask,
) -> Result<SocketHandle, Errno>
fn accept( &self, socket: &Socket, current_task: &CurrentTask, ) -> Result<SocketHandle, Errno>
Returns the eariest socket on the accept queue of this listening socket. Returns EAGAIN if the queue is empty.
Sourcefn bind(
&self,
socket: &Socket,
current_task: &CurrentTask,
socket_address: SocketAddress,
) -> Result<(), Errno>
fn bind( &self, socket: &Socket, current_task: &CurrentTask, socket_address: SocketAddress, ) -> Result<(), Errno>
Binds this socket to a socket_address.
Returns an error if the socket could not be bound.
Sourcefn read(
&self,
socket: &Socket,
current_task: &CurrentTask,
data: &mut dyn OutputBuffer,
flags: SocketMessageFlags,
) -> Result<MessageReadInfo, Errno>
fn read( &self, socket: &Socket, current_task: &CurrentTask, data: &mut dyn OutputBuffer, flags: SocketMessageFlags, ) -> Result<MessageReadInfo, Errno>
Reads the specified number of bytes from the socket, if possible.
§Parameters
task: The task to which the user buffers belong (i.e., the task to which the read bytes are written.data: The buffers to write the read data into.
Returns the number of bytes that were written to the user buffers, as well as any ancillary data associated with the read messages.
Sourcefn write(
&self,
socket: &Socket,
current_task: &CurrentTask,
data: &mut dyn InputBuffer,
dest_address: &mut Option<SocketAddress>,
ancillary_data: &mut Vec<AncillaryData>,
) -> Result<usize, Errno>
fn write( &self, socket: &Socket, current_task: &CurrentTask, data: &mut dyn InputBuffer, dest_address: &mut Option<SocketAddress>, ancillary_data: &mut Vec<AncillaryData>, ) -> Result<usize, Errno>
Writes the data in the provided user buffers to this socket.
§Parameters
task: The task to which the user buffers belong, used to read the memory.data: The data to write to the socket.ancillary_data: Optional ancillary data (a.k.a., control message) to write.
Advances the iterator to indicate how much was actually written.
Sourcefn wait_async(
&self,
socket: &Socket,
current_task: &CurrentTask,
waiter: &Waiter,
events: FdEvents,
handler: EventHandler,
) -> WaitCanceler
fn wait_async( &self, socket: &Socket, current_task: &CurrentTask, waiter: &Waiter, events: FdEvents, handler: EventHandler, ) -> WaitCanceler
Queues an asynchronous wait for the specified events
on the waiter. Note that no wait occurs until a
wait functions is called on the waiter.
§Parameters
waiter: The Waiter that can be waited on, for example by calling Waiter::wait_until.events: The events that will trigger the waiter to wake up.handler: A handler that will be called on wake-up. Returns a WaitCanceler that can be used to cancel the wait.
Sourcefn query_events(
&self,
socket: &Socket,
current_task: &CurrentTask,
) -> Result<FdEvents, Errno>
fn query_events( &self, socket: &Socket, current_task: &CurrentTask, ) -> Result<FdEvents, Errno>
Return the events that are currently active on the socket.
Sourcefn shutdown(
&self,
socket: &Socket,
how: SocketShutdownFlags,
) -> Result<(), Errno>
fn shutdown( &self, socket: &Socket, how: SocketShutdownFlags, ) -> Result<(), Errno>
Shuts down this socket according to how, preventing any future reads and/or writes.
Used by the shutdown syscalls.
Sourcefn close(&self, current_task: &CurrentTask, socket: &Socket)
fn close(&self, current_task: &CurrentTask, socket: &Socket)
Close this socket.
Called by SocketFile when the file descriptor that is holding this socket is closed.
Close differs from shutdown in two ways. First, close will call mark_peer_closed_with_unread_data if this socket has unread data, which changes how read() behaves on that socket. Second, close transitions the internal state of this socket to Closed, which breaks the reference cycle that exists in the connected state.
Sourcefn getsockname(&self, socket: &Socket) -> Result<SocketAddress, Errno>
fn getsockname(&self, socket: &Socket) -> Result<SocketAddress, Errno>
Returns the name of this socket.
The name is derived from the address and domain. A socket will always have a name, even if it is not bound to an address.
Sourcefn getpeername(&self, socket: &Socket) -> Result<SocketAddress, Errno>
fn getpeername(&self, socket: &Socket) -> Result<SocketAddress, Errno>
Returns the name of the peer of this socket, if such a peer exists.
Returns an error if the socket is not connected.
Provided Methods§
Sourcefn get_socket_info(
&self,
) -> Result<(SocketDomain, SocketType, SocketProtocol), Errno>
fn get_socket_info( &self, ) -> Result<(SocketDomain, SocketType, SocketProtocol), Errno>
Returns the domain, type and protocol of the socket. This is only used for socket that are build without previous knowledge of this information, and can be ignored if all sockets are build with it.
Sourcefn setsockopt(
&self,
_socket: &Socket,
_current_task: &CurrentTask,
_level: u32,
_optname: u32,
_optval: SockOptValue,
) -> Result<(), Errno>
fn setsockopt( &self, _socket: &Socket, _current_task: &CurrentTask, _level: u32, _optname: u32, _optval: SockOptValue, ) -> Result<(), Errno>
Sets socket-specific options.
Sourcefn getsockopt(
&self,
_socket: &Socket,
_current_task: &CurrentTask,
_level: u32,
_optname: u32,
_optlen: u32,
) -> Result<Vec<u8>, Errno>
fn getsockopt( &self, _socket: &Socket, _current_task: &CurrentTask, _level: u32, _optname: u32, _optlen: u32, ) -> Result<Vec<u8>, Errno>
Retrieves socket-specific options.
Sourcefn ioctl(
&self,
_socket: &Socket,
_file: &FileObject,
_current_task: &CurrentTask,
_request: u32,
_arg: SyscallArg,
) -> Result<SyscallResult, Errno>
fn ioctl( &self, _socket: &Socket, _file: &FileObject, _current_task: &CurrentTask, _request: u32, _arg: SyscallArg, ) -> Result<SyscallResult, Errno>
Implements ioctl.
Sourcefn to_handle(
&self,
_socket: &Socket,
_current_task: &CurrentTask,
) -> Result<Option<NullableHandle>, Errno>
fn to_handle( &self, _socket: &Socket, _current_task: &CurrentTask, ) -> Result<Option<NullableHandle>, Errno>
Return a handle that allows access to this file descritor through the zxio protocols.
If None is returned, the file will be proxied.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".