diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c index 374af780ca..9e16d11328 100644 --- a/drivers/net/telnet.c +++ b/drivers/net/telnet.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/telnet.c * - * Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011-2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * This is a leverage of similar logic from uIP which has a compatible BSD @@ -439,15 +439,19 @@ static void telnet_sendopt(FAR struct telnet_dev_s *priv, uint8_t option, uint8_t value) { uint8_t optbuf[4]; + int ret; + optbuf[0] = TELNET_IAC; optbuf[1] = option; optbuf[2] = value; optbuf[3] = 0; telnet_dumpbuffer("Send optbuf", optbuf, 4); - if (psock_send(&priv->td_psock, optbuf, 4, 0) < 0) + + ret = psock_send(&priv->td_psock, optbuf, 4, 0); + if (ret < 0) { - nerr("ERROR: Failed to send TELNET_IAC\n"); + nerr("ERROR: Failed to send TELNET_IAC: %d\n", ret); } } diff --git a/fs/aio/aio_write.c b/fs/aio/aio_write.c index 60504f53b9..3f00af965c 100644 --- a/fs/aio/aio_write.c +++ b/fs/aio/aio_write.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/aio/aio_write.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -155,13 +155,6 @@ static void aio_write_worker(FAR void *arg) aiocbp->aio_nbytes, aiocbp->aio_offset); } - - /* errno is not set */ - - if (nwritten < 0) - { - ferr("ERROR: file_write/file_pwrite failed: %d\n", nwritten); - } } #endif #if defined(AIO_HAVE_FILEP) && defined(AIO_HAVE_PSOCK) @@ -179,18 +172,14 @@ static void aio_write_worker(FAR void *arg) nwritten = psock_send(aioc->u.aioc_psock, (FAR const void *)aiocbp->aio_buf, aiocbp->aio_nbytes, 0); - /* errno is set */ - - if (nwritten < 0) - { - int errcode = get_errno(); - ferr("ERROR: psock_send failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - nwritten = -errcode; - } } #endif + if (nwritten < 0) + { + ferr("ERROR: write/pwrite/send failed: %d\n", nwritten); + } + /* Save the result of the write */ aiocbp->aio_result = nwritten; diff --git a/graphics/vnc/server/vnc_negotiate.c b/graphics/vnc/server/vnc_negotiate.c index 910d0b6f26..026680ef56 100644 --- a/graphics/vnc/server/vnc_negotiate.c +++ b/graphics/vnc/server/vnc_negotiate.c @@ -1,7 +1,7 @@ /**************************************************************************** * graphics/vnc/vnc_negotiate.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -146,10 +146,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) nsent = psock_send(&session->connect, g_vncproto, len, 0); if (nsent < 0) { - errcode = get_errno(); - gerr("ERROR: Send ProtocolVersion failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Send ProtocolVersion failed: %d\n", (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == len); @@ -189,10 +187,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) sizeof(struct rfb_sectype_s), 0); if (nsent < 0) { - errcode = get_errno(); - gerr("ERROR: Send Security failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Send Security failed: %d\n", (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == sizeof(struct rfb_sectype_s)); @@ -212,10 +208,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) SIZEOF_RFB_SUPPORTED_SECTYPES_S(1), 0); if (nsent < 0) { - errcode = get_errno(); - gerr("ERROR: Send SupportedSecurityTypes failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Send SupportedSecurityTypes failed: %d\n", (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == SIZEOF_RFB_SUPPORTED_SECTYPES_S(1)); @@ -262,10 +256,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) sizeof(struct rfb_sectype_result_s), 0); if (nsent < 0) { - errcode = get_errno(); - gerr("ERROR: Send SecurityResult failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Send SecurityResult failed: %d\n", (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == sizeof(struct rfb_sectype_result_s)); @@ -281,10 +273,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) SIZEOF_RFB_SECTYPE_FAIL_S(len), 0); if (nsent < 0) { - errcode = get_errno(); - gerr("ERROR: Send failure reason failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Send failure reason failed: %d\n", (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == SIZEOF_RFB_SECTYPE_FAIL_S(len)); @@ -297,10 +287,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) sizeof(struct rfb_sectype_result_s), 0); if (nsent < 0) { - errcode = get_errno(); - gerr("ERROR: Send SecurityResult failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Send SecurityResult failed: %d\n", (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == sizeof(struct rfb_sectype_result_s)); @@ -378,9 +366,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) SIZEOF_RFB_SERVERINIT_S(len), 0); if (nsent < 0) { - errcode = get_errno(); - gerr("ERROR: Send ServerInit failed: %d\n", errcode); - return -errcode; + gerr("ERROR: Send ServerInit failed: %d\n", (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == SIZEOF_RFB_SERVERINIT_S(len)); diff --git a/graphics/vnc/server/vnc_raw.c b/graphics/vnc/server/vnc_raw.c index 35f9f1895d..5b548f3920 100644 --- a/graphics/vnc/server/vnc_raw.c +++ b/graphics/vnc/server/vnc_raw.c @@ -1,7 +1,7 @@ /**************************************************************************** * graphics/vnc/vnc_raw.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -482,11 +482,9 @@ int vnc_raw(FAR struct vnc_session_s *session, FAR struct nxgl_rect_s *rect) nsent = psock_send(&session->connect, src, size, 0); if (nsent < 0) { - int errcode = get_errno(); gerr("ERROR: Send FrameBufferUpdate failed: %d\n", - errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent <= size); diff --git a/graphics/vnc/server/vnc_rre.c b/graphics/vnc/server/vnc_rre.c index 5463d42b42..adf347c569 100644 --- a/graphics/vnc/server/vnc_rre.c +++ b/graphics/vnc/server/vnc_rre.c @@ -1,7 +1,7 @@ /**************************************************************************** * graphics/vnc/vnc_rre.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -295,11 +295,9 @@ int vnc_rre(FAR struct vnc_session_s *session, FAR struct nxgl_rect_s *rect) nsent = psock_send(&session->connect, rre, nbytes, 0); if (nsent < 0) { - int errcode = get_errno(); gerr("ERROR: Send RRE FrameBufferUpdate failed: %d\n", - errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + (int)nsent); + return (int)nsent; } DEBUGASSERT(nsent == nbytes); diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 848bddf4b4..b3c0da571b 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -707,8 +707,8 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, * flags Send flags * * Returned Value: - * On success, returns the number of characters sent. On error, - * -1 is returned, and errno is set appropriately: + * On success, returns the number of characters sent. On any failure, a + * negated errno value is returned. One of: * * EAGAIN or EWOULDBLOCK * The socket is marked non-blocking and the requested operation @@ -775,8 +775,8 @@ ssize_t psock_send(FAR struct socket *psock, const void *buf, size_t len, * tolen The length of the address structure * * Returned Value: - * On success, returns the number of characters sent. On a negated errno - * value is returned. One of: + * On success, returns the number of characters sent. On any failure, a + * negated errno value is returned. One of: * * EAGAIN or EWOULDBLOCK * The socket is marked non-blocking and the requested operation diff --git a/net/socket/send.c b/net/socket/send.c index 56c300870a..6a78d6565a 100644 --- a/net/socket/send.c +++ b/net/socket/send.c @@ -70,8 +70,8 @@ * flags Send flags * * Returned Value: - * On success, returns the number of characters sent. On error, - * -1 is returned, and errno is set appropriately: + * On success, returns the number of characters sent. On any failure, a + * negated errno value is returned. One of: * * EAGAIN or EWOULDBLOCK * The socket is marked non-blocking and the requested operation @@ -121,7 +121,6 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, int flags) { ssize_t ret; - int errcode; DEBUGASSERT(psock != NULL && buf != NULL); @@ -129,27 +128,20 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, if (psock == NULL || psock->s_crefs <= 0) { - errcode = EBADF; - goto errout; + return -EBADF; } /* Let the address family's send() method handle the operation */ DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_send != NULL); - ret = psock->s_sockif->si_send(psock, buf, len, flags); + ret = psock->s_sockif->si_send(psock, buf, len, flags); if (ret < 0) { nerr("ERROR: socket si_send() (or usrsock_sendto()) failed: %d\n", ret); - errcode = -ret; - goto errout; } return ret; - -errout: - set_errno(errcode); - return ERROR; } /**************************************************************************** diff --git a/net/socket/sendto.c b/net/socket/sendto.c index 2325e46ff2..1cda70f3e4 100644 --- a/net/socket/sendto.c +++ b/net/socket/sendto.c @@ -183,8 +183,8 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf, * tolen The length of the address structure * * Returned Value: - * On success, returns the number of characters sent. On error, - * -1 is returned, and errno is set appropriately: + * On success, returns the number of characters sent. On any failure, a + * negated errno value is returned. One of: * * EAGAIN or EWOULDBLOCK * The socket is marked non-blocking and the requested operation