net/sockets: psock_send() is an internal OS interface an should not set the errno variable.

This commit is contained in:
Gregory Nutt 2017-09-29 17:48:15 -06:00
parent 9e8529b1d0
commit 44736b721c
8 changed files with 44 additions and 76 deletions

View File

@ -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 <gnutt@nuttx.org>
*
* 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);
}
}

View File

@ -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 <gnutt@nuttx.org>
*
* 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;

View File

@ -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 <gnutt@nuttx.org>
*
* 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));

View File

@ -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 <gnutt@nuttx.org>
*
* 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);

View File

@ -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 <gnutt@nuttx.org>
*
* 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);

View File

@ -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

View File

@ -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;
}
/****************************************************************************

View File

@ -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