diff --git a/net/tcp/Make.defs b/net/tcp/Make.defs index 28cab4a2afc..32009fe3af9 100644 --- a/net/tcp/Make.defs +++ b/net/tcp/Make.defs @@ -54,7 +54,7 @@ endif ifneq ($(CONFIG_DISABLE_POLL),y) ifeq ($(CONFIG_NET_TCP_READAHEAD),y) -NET_CSRCS += tcp_netpoll.c +SOCK_CSRCS += tcp_netpoll.c endif endif diff --git a/net/udp/Make.defs b/net/udp/Make.defs index 5c8918ea9a3..7cb743bfac6 100644 --- a/net/udp/Make.defs +++ b/net/udp/Make.defs @@ -40,7 +40,7 @@ ifneq ($(CONFIG_NET_UDP_NO_STACK),y) # Socket layer -NET_CSRCS += udp_psock_send.c +SOCK_CSRCS += udp_psock_send.c ifeq ($(CONFIG_NET_UDP_WRITE_BUFFERS),y) SOCK_CSRCS += udp_psock_sendto_buffered.c @@ -50,7 +50,7 @@ endif ifneq ($(CONFIG_DISABLE_POLL),y) ifeq ($(CONFIG_NET_UDP_READAHEAD),y) -NET_CSRCS += udp_netpoll.c +SOCK_CSRCS += udp_netpoll.c endif endif diff --git a/net/udp/udp_psock_send.c b/net/udp/udp_psock_send.c index a89153aaddd..2bbfaffb13a 100644 --- a/net/udp/udp_psock_send.c +++ b/net/udp/udp_psock_send.c @@ -40,7 +40,6 @@ #include #include -#include #include #include @@ -64,24 +63,26 @@ ssize_t psock_udp_send(FAR struct socket *psock, FAR const void *buf, size_t len) { - FAR struct udp_conn_s *conn; - - DEBUGASSERT(psock != NULL && psock->s_crefs > 0); + DEBUGASSERT(psock != NULL && psock->s_crefs > 0 && psock->s_conn != NULL); DEBUGASSERT(psock->s_type == SOCK_DGRAM); - conn = (FAR struct udp_conn_s *)psock->s_conn; - DEBUGASSERT(conn); - - /* Was the UDP socket connected via connect()? */ + /* Was the UDP socket connected via connect()? + * REVISIT: This same test is performed in psock_udp_sendto() where + * -EDESTADDRREQ is returned. There is a fine distinction in the + * meaning of the reported errors that I am not sure I have correct. + */ if (!_SS_ISCONNECTED(psock->s_flags)) { - /* No, then it is not legal to call send() with this socket. */ + /* No, then it is not legal to call send() with this socket. + * ENOTCONN - The socket is not connected or otherwise has not had + * the peer pre-specified. + */ return -ENOTCONN; } - /* Yes, then let psock_sendto to the work */ + /* Let psock_sendto() do all of the work work */ return psock_udp_sendto(psock, buf, len, 0, NULL, 0); } diff --git a/net/udp/udp_psock_sendto_buffered.c b/net/udp/udp_psock_sendto_buffered.c index 6a66b2865f9..cca6f89b6ba 100644 --- a/net/udp/udp_psock_sendto_buffered.c +++ b/net/udp/udp_psock_sendto_buffered.c @@ -627,6 +627,10 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, if (to != NULL && _SS_ISCONNECTED(psock->s_flags)) { + /* EISCONN - A destination address was specified and the socket is + * already connected. + */ + return -EISCONN; } @@ -636,6 +640,10 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, else if (to == NULL && !_SS_ISCONNECTED(psock->s_flags)) { + /* EDESTADDRREQ - The socket is not connection-mode and no peer + * address is set. + */ + return -EDESTADDRREQ; } diff --git a/net/udp/udp_psock_sendto_unbuffered.c b/net/udp/udp_psock_sendto_unbuffered.c index d9cccbc1fed..e0c8d516cf1 100644 --- a/net/udp/udp_psock_sendto_unbuffered.c +++ b/net/udp/udp_psock_sendto_unbuffered.c @@ -332,6 +332,10 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, if (to != NULL && _SS_ISCONNECTED(psock->s_flags)) { + /* EISCONN - A destination address was specified and the socket is + * already connected. + */ + return -EISCONN; } @@ -341,6 +345,10 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, else if (to == NULL && !_SS_ISCONNECTED(psock->s_flags)) { + /* EDESTADDRREQ - The socket is not connection-mode and no peer\ + * address is set. + */ + return -EDESTADDRREQ; }