#[inline(always)]
fn bind_socket_with_length<SA>(socket_file_descriptor: &impl FileDescriptor, socket_address: &SA, length: usize) -> Result<(), SocketBindError>
{
use self::SocketBindError::*;
use self::FilePathInvalidReason::*;
let result = unsafe { bind(socket_file_descriptor.as_raw_fd(), socket_address as *const SA as *const sockaddr_storage, length as socklen_t) };
if likely!(result == 0)
{
Ok(())
}
else if likely!(result == -1)
{
Err
(
match errno().0
{
EACCES => PermissionDenied,
EADDRINUSE => AddressInUse,
ENOMEM => KernelWouldBeOutOfMemory,
EBADF => panic!("`sockfd` is not a valid descriptor"),
EINVAL => panic!("already bound, or the `addrlen` is wrong, or the socket was not in the `AF_UNIX` family"),
ENOTSOCK => panic!("`sockfd` is not a socket file descriptor"),
EADDRNOTAVAIL => FilePathInvalid(AddressUnavailable),
EFAULT => panic!("`addr` points outside the user's accessible address space"),
ELOOP => FilePathInvalid(TooManySymbolicLinksInFilePath),
ENOENT => FilePathInvalid(DoesNotExist),
ENOTDIR => FilePathInvalid(FilePathPrefixComponentIsNotADirectory),
EROFS => FilePathInvalid(FilePathIsReadOnly),
EAFNOSUPPORT => panic!("Invalid `sa_family_t` value"),
_ => unreachable_code(format_args!("")),
}
)
}
else
{
unreachable_code(format_args!(""))
}
}