pub struct UnixSocket { /* private fields */ }Expand description
The data of a socket is stored in the “Inner” struct. Because both ends have separate locks, care must be taken to avoid taking both locks since there is no way to tell what order to take them in.
When writing, data is buffered in the “other” end of the socket’s Inner.MessageQueue:
UnixSocket end #1 UnixSocket end #2
+---------------+ +---------------+
| | | +-------+ |Writes ––––––––––––––––>| Inner |——> Reads | | | +—––+ | | +—––+ | | | Reads <——| Inner |<–––––––––––––––– Writes | +—––+ | | | +—————+ +—————+
Implementations§
Source§impl UnixSocket
impl UnixSocket
pub fn new(_socket_type: SocketType) -> UnixSocket
Sourcepub fn new_pair<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
domain: SocketDomain,
socket_type: SocketType,
open_flags: OpenFlags,
) -> Result<(FileHandle, FileHandle), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn new_pair<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
domain: SocketDomain,
socket_type: SocketType,
open_flags: OpenFlags,
) -> Result<(FileHandle, FileHandle), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Creates a pair of connected sockets.
§Parameters
domain: The domain of the socket (e.g.,AF_UNIX).socket_type: The type of the socket (e.g.,SOCK_STREAM).
pub fn check_type_for_connect( &self, socket: &Socket, peer: &Socket, peer_address: &Option<SocketAddress>, ) -> Result<(), Errno>
pub fn bind_socket_to_node( &self, socket: &SocketHandle, address: SocketAddress, node: &FsNodeHandle, ) -> Result<(), Errno>
Trait Implementations§
Source§impl SocketOps for UnixSocket
impl SocketOps for UnixSocket
Source§fn shutdown(
&self,
_locked: &mut Locked<FileOpsCore>,
_socket: &Socket,
how: SocketShutdownFlags,
) -> Result<(), Errno>
fn shutdown( &self, _locked: &mut Locked<FileOpsCore>, _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.
Source§fn close(
&self,
_locked: &mut Locked<FileOpsCore>,
_current_task: &CurrentTask,
socket: &Socket,
)
fn close( &self, _locked: &mut Locked<FileOpsCore>, _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.
Source§fn getsockname(
&self,
_locked: &mut Locked<FileOpsCore>,
socket: &Socket,
) -> Result<SocketAddress, Errno>
fn getsockname( &self, _locked: &mut Locked<FileOpsCore>, 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.
Source§fn getpeername(
&self,
locked: &mut Locked<FileOpsCore>,
_socket: &Socket,
) -> Result<SocketAddress, Errno>
fn getpeername( &self, locked: &mut Locked<FileOpsCore>, _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.
Source§fn connect(
&self,
locked: &mut Locked<FileOpsCore>,
socket: &SocketHandle,
current_task: &CurrentTask,
peer: SocketPeer,
) -> Result<(), Errno>
fn connect( &self, locked: &mut Locked<FileOpsCore>, socket: &SocketHandle, current_task: &CurrentTask, peer: SocketPeer, ) -> Result<(), Errno>
socket to the listening peer. On success
a new socket is created and added to the accept queue.Source§fn listen(
&self,
_locked: &mut Locked<FileOpsCore>,
socket: &Socket,
backlog: i32,
credentials: ucred,
) -> Result<(), Errno>
fn listen( &self, _locked: &mut Locked<FileOpsCore>, socket: &Socket, backlog: i32, credentials: ucred, ) -> Result<(), Errno>
connect calls.Source§fn accept(
&self,
_locked: &mut Locked<FileOpsCore>,
socket: &Socket,
_current_task: &CurrentTask,
) -> Result<SocketHandle, Errno>
fn accept( &self, _locked: &mut Locked<FileOpsCore>, socket: &Socket, _current_task: &CurrentTask, ) -> Result<SocketHandle, Errno>
Source§fn bind(
&self,
_locked: &mut Locked<FileOpsCore>,
_socket: &Socket,
_current_task: &CurrentTask,
socket_address: SocketAddress,
) -> Result<(), Errno>
fn bind( &self, _locked: &mut Locked<FileOpsCore>, _socket: &Socket, _current_task: &CurrentTask, socket_address: SocketAddress, ) -> Result<(), Errno>
socket_address. Read moreSource§fn read(
&self,
_locked: &mut Locked<FileOpsCore>,
socket: &Socket,
_current_task: &CurrentTask,
data: &mut dyn OutputBuffer,
flags: SocketMessageFlags,
) -> Result<MessageReadInfo, Errno>
fn read( &self, _locked: &mut Locked<FileOpsCore>, socket: &Socket, _current_task: &CurrentTask, data: &mut dyn OutputBuffer, flags: SocketMessageFlags, ) -> Result<MessageReadInfo, Errno>
Source§fn write(
&self,
locked: &mut Locked<FileOpsCore>,
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, locked: &mut Locked<FileOpsCore>, socket: &Socket, current_task: &CurrentTask, data: &mut dyn InputBuffer, dest_address: &mut Option<SocketAddress>, ancillary_data: &mut Vec<AncillaryData>, ) -> Result<usize, Errno>
Source§fn wait_async(
&self,
_locked: &mut Locked<FileOpsCore>,
_socket: &Socket,
_current_task: &CurrentTask,
waiter: &Waiter,
events: FdEvents,
handler: EventHandler,
) -> WaitCanceler
fn wait_async( &self, _locked: &mut Locked<FileOpsCore>, _socket: &Socket, _current_task: &CurrentTask, waiter: &Waiter, events: FdEvents, handler: EventHandler, ) -> WaitCanceler
events
on the waiter. Note that no wait occurs until a
wait functions is called on the waiter. Read moreSource§fn query_events(
&self,
_locked: &mut Locked<FileOpsCore>,
_socket: &Socket,
_current_task: &CurrentTask,
) -> Result<FdEvents, Errno>
fn query_events( &self, _locked: &mut Locked<FileOpsCore>, _socket: &Socket, _current_task: &CurrentTask, ) -> Result<FdEvents, Errno>
socket.Source§fn setsockopt(
&self,
_locked: &mut Locked<FileOpsCore>,
_socket: &Socket,
current_task: &CurrentTask,
level: u32,
optname: u32,
optval: SockOptValue,
) -> Result<(), Errno>
fn setsockopt( &self, _locked: &mut Locked<FileOpsCore>, _socket: &Socket, current_task: &CurrentTask, level: u32, optname: u32, optval: SockOptValue, ) -> Result<(), Errno>
Source§fn getsockopt(
&self,
_locked: &mut Locked<FileOpsCore>,
socket: &Socket,
current_task: &CurrentTask,
level: u32,
optname: u32,
_optlen: u32,
) -> Result<Vec<u8>, Errno>
fn getsockopt( &self, _locked: &mut Locked<FileOpsCore>, socket: &Socket, current_task: &CurrentTask, level: u32, optname: u32, _optlen: u32, ) -> Result<Vec<u8>, Errno>
Source§fn ioctl(
&self,
locked: &mut Locked<Unlocked>,
socket: &Socket,
file: &FileObject,
current_task: &CurrentTask,
request: u32,
arg: SyscallArg,
) -> Result<SyscallResult, Errno>
fn ioctl( &self, locked: &mut Locked<Unlocked>, socket: &Socket, file: &FileObject, current_task: &CurrentTask, request: u32, arg: SyscallArg, ) -> Result<SyscallResult, Errno>
Source§fn get_socket_info(
&self,
) -> Result<(SocketDomain, SocketType, SocketProtocol), Errno>
fn get_socket_info( &self, ) -> Result<(SocketDomain, SocketType, SocketProtocol), Errno>
Source§fn 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>
Auto Trait Implementations§
impl !Freeze for UnixSocket
impl !RefUnwindSafe for UnixSocket
impl Send for UnixSocket
impl Sync for UnixSocket
impl Unpin for UnixSocket
impl !UnwindSafe for UnixSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<T> InstanceFromServiceTransport<T> for T
impl<T> InstanceFromServiceTransport<T> for T
§fn from_service_transport(handle: T) -> T
fn from_service_transport(handle: T) -> T
T to [Self]Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more