mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-12 06:46:48 +00:00
Fix error codes in send
, recv
, accept
This commit is contained in:
parent
a8592a16ea
commit
a345e11b96
@ -54,7 +54,10 @@ impl TryFrom<SocketAddr> for UnixSocketAddr {
|
|||||||
fn try_from(value: SocketAddr) -> Result<Self> {
|
fn try_from(value: SocketAddr) -> Result<Self> {
|
||||||
match value {
|
match value {
|
||||||
SocketAddr::Unix(unix_socket_addr) => Ok(unix_socket_addr),
|
SocketAddr::Unix(unix_socket_addr) => Ok(unix_socket_addr),
|
||||||
_ => return_errno_with_message!(Errno::EINVAL, "Invalid unix socket addr"),
|
_ => return_errno_with_message!(
|
||||||
|
Errno::EINVAL,
|
||||||
|
"the socket address is not a valid UNIX domain socket address"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,9 @@ impl UnixStreamSocket {
|
|||||||
fn try_send(&self, buf: &[u8], _flags: SendRecvFlags) -> Result<usize> {
|
fn try_send(&self, buf: &[u8], _flags: SendRecvFlags) -> Result<usize> {
|
||||||
match self.state.read().as_ref() {
|
match self.state.read().as_ref() {
|
||||||
State::Connected(connected) => connected.try_write(buf),
|
State::Connected(connected) => connected.try_write(buf),
|
||||||
_ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"),
|
State::Init(_) | State::Listen(_) => {
|
||||||
|
return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +95,9 @@ impl UnixStreamSocket {
|
|||||||
fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<usize> {
|
fn try_recv(&self, buf: &mut [u8], _flags: SendRecvFlags) -> Result<usize> {
|
||||||
match self.state.read().as_ref() {
|
match self.state.read().as_ref() {
|
||||||
State::Connected(connected) => connected.try_read(buf),
|
State::Connected(connected) => connected.try_read(buf),
|
||||||
_ => return_errno_with_message!(Errno::ENOTCONN, "the socket is not connected"),
|
State::Init(_) | State::Listen(_) => {
|
||||||
|
return_errno_with_message!(Errno::EINVAL, "the socket is not connected")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +139,9 @@ impl UnixStreamSocket {
|
|||||||
fn try_accept(&self) -> Result<(Arc<dyn FileLike>, SocketAddr)> {
|
fn try_accept(&self) -> Result<(Arc<dyn FileLike>, SocketAddr)> {
|
||||||
match self.state.read().as_ref() {
|
match self.state.read().as_ref() {
|
||||||
State::Listen(listen) => listen.try_accept() as _,
|
State::Listen(listen) => listen.try_accept() as _,
|
||||||
_ => return_errno_with_message!(Errno::EINVAL, "the socket is not listening"),
|
State::Init(_) | State::Connected(_) => {
|
||||||
|
return_errno_with_message!(Errno::EINVAL, "the socket is not listening")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +247,42 @@ FN_TEST(listen)
|
|||||||
}
|
}
|
||||||
END_TEST()
|
END_TEST()
|
||||||
|
|
||||||
|
FN_TEST(accept)
|
||||||
|
{
|
||||||
|
TEST_ERRNO(accept(sk_unbound, NULL, NULL), EINVAL);
|
||||||
|
|
||||||
|
TEST_ERRNO(accept(sk_bound, NULL, NULL), EINVAL);
|
||||||
|
|
||||||
|
TEST_ERRNO(accept(sk_connected, NULL, NULL), EINVAL);
|
||||||
|
|
||||||
|
TEST_ERRNO(accept(sk_accepted, NULL, NULL), EINVAL);
|
||||||
|
}
|
||||||
|
END_TEST()
|
||||||
|
|
||||||
|
FN_TEST(send)
|
||||||
|
{
|
||||||
|
char buf[1] = { 'z' };
|
||||||
|
|
||||||
|
TEST_ERRNO(send(sk_unbound, buf, 1, 0), ENOTCONN);
|
||||||
|
|
||||||
|
TEST_ERRNO(send(sk_bound, buf, 1, 0), ENOTCONN);
|
||||||
|
|
||||||
|
TEST_ERRNO(send(sk_listen, buf, 1, 0), ENOTCONN);
|
||||||
|
}
|
||||||
|
END_TEST()
|
||||||
|
|
||||||
|
FN_TEST(recv)
|
||||||
|
{
|
||||||
|
char buf[1] = { 'z' };
|
||||||
|
|
||||||
|
TEST_ERRNO(recv(sk_unbound, buf, 1, 0), EINVAL);
|
||||||
|
|
||||||
|
TEST_ERRNO(recv(sk_bound, buf, 1, 0), EINVAL);
|
||||||
|
|
||||||
|
TEST_ERRNO(recv(sk_listen, buf, 1, 0), EINVAL);
|
||||||
|
}
|
||||||
|
END_TEST()
|
||||||
|
|
||||||
FN_TEST(ns_path)
|
FN_TEST(ns_path)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user