Yet another repair for the previouis botched recvfrom() fix; Fix telnet driver: It needs to break out of the read loop if 0 (meaning not conneced) of a value < 0 (an error) is encountered.

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5541 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2013-01-20 00:41:33 +00:00
parent 598b4b2879
commit 28a0cf4aa0
4 changed files with 47 additions and 21 deletions
+2
View File
@@ -490,3 +490,5 @@
* apps/builtin/: Extensions from Mike Smith. * apps/builtin/: Extensions from Mike Smith.
* apps/examples/ftpd/Makefile: Name ftpd_start is not the name of * apps/examples/ftpd/Makefile: Name ftpd_start is not the name of
the entrypoint. Should be ftpd_main (from Yan T.) the entrypoint. Should be ftpd_main (from Yan T.)
* apps/netutils/telnetd/telnetd_driver: Was stuck in a loop if
recv[from]() ever returned a value <= 0.
+16 -2
View File
@@ -558,6 +558,8 @@ static ssize_t telnetd_read(FAR struct file *filep, FAR char *buffer, size_t len
{ {
if (priv->td_pending > 0) if (priv->td_pending > 0)
{ {
/* Process the buffered telnet data */
FAR const char *src = &priv->td_rxbuffer[priv->td_offset]; FAR const char *src = &priv->td_rxbuffer[priv->td_offset];
ret = telnetd_receive(priv, src, priv->td_pending, buffer, len); ret = telnetd_receive(priv, src, priv->td_pending, buffer, len);
} }
@@ -568,13 +570,25 @@ static ssize_t telnetd_read(FAR struct file *filep, FAR char *buffer, size_t len
{ {
ret = psock_recv(&priv->td_psock, priv->td_rxbuffer, ret = psock_recv(&priv->td_psock, priv->td_rxbuffer,
CONFIG_TELNETD_RXBUFFER_SIZE, 0); CONFIG_TELNETD_RXBUFFER_SIZE, 0);
/* Did we receive anything? */
if (ret > 0) if (ret > 0)
{ {
/* Process the received telnet data */ /* Yes.. Process the newly received telnet data */
telnetd_dumpbuffer("Received buffer", priv->td_rxbuffer, ret); telnetd_dumpbuffer("Received buffer", priv->td_rxbuffer, ret);
ret = telnetd_receive(priv, priv->td_rxbuffer, ret, buffer, len); ret = telnetd_receive(priv, priv->td_rxbuffer, ret, buffer, len);
} }
/* Otherwise the peer closed the connection (ret == 0) or an error
* occurred (ret < 0).
*/
else
{
break;
}
} }
} }
while (ret == 0); while (ret == 0);
@@ -746,7 +760,7 @@ FAR char *telnetd_driver(int sd, FAR struct telnetd_s *daemon)
* instance resided in the daemon's socket array). * instance resided in the daemon's socket array).
*/ */
psock = sockfd_socket(sd); psock = sockfd_socket(sd);
if (!psock) if (!psock)
{ {
nlldbg("Failed to convert sd=%d to a socket structure\n", sd); nlldbg("Failed to convert sd=%d to a socket structure\n", sd);
+3
View File
@@ -3993,3 +3993,6 @@
(gracefully). recv[from]() returned success and the closure (gracefully). recv[from]() returned success and the closure
was never detected. Hmmm.. I don't know why the network monitor was never detected. Hmmm.. I don't know why the network monitor
did not catch this event. This is an important bug fix. did not catch this event. This is an important bug fix.
* net/recvfrom(): Fix a introduced with the last bugfix. If
the peer does an orderly closure of the socket, report 0 not
-ENOTCONN
+26 -19
View File
@@ -571,40 +571,47 @@ static uint16_t recvfrom_tcpinterrupt(struct uip_driver_s *dev, void *conn,
* gracefully disconnected * gracefully disconnected
* _SF_CONNECTED==0 && _SF_CLOSED==0 - the socket was * _SF_CONNECTED==0 && _SF_CLOSED==0 - the socket was
* rudely disconnected * rudely disconnected
*
* These flag settings are probably not necessary if
* CONFIG_NET_TCP_RECVDELAY == 0; in that case we know that
* pstate->rf_recvlen == 0 and we will always return -ENOTCONN.
*/ */
psock = pstate->rf_sock; psock = pstate->rf_sock;
if ((flags & UIP_CLOSE) != 0) if ((flags & UIP_CLOSE) != 0)
{ {
/* Report that the connection was gracefully closed */
psock->s_flags &= ~_SF_CONNECTED; psock->s_flags &= ~_SF_CONNECTED;
psock->s_flags |= _SF_CLOSED; psock->s_flags |= _SF_CLOSED;
}
else
{
psock->s_flags &= ~(_SF_CONNECTED |_SF_CLOSED);
}
/* If no data has been received, then return ENOTCONN. /* This case should always return success (zero)! The value of
* Otherwise, let this return success. The failure will * rf_recvlen, if zero, will indicate that the connection was
* be reported the next time that recv[from]() is called. * gracefully closed.
*/ */
#if CONFIG_NET_TCP_RECVDELAY > 0
if (pstate->rf_recvlen > 0)
{
pstate->rf_result = 0; pstate->rf_result = 0;
} }
else else
{ {
pstate->rf_result = -ENOTCONN; /* Report that the connection was rudely lost */
}
psock->s_flags &= ~(_SF_CONNECTED |_SF_CLOSED);
/* If no data has been received, then return ENOTCONN.
* Otherwise, let this return success. The failure will
* be reported the next time that recv[from]() is called.
*/
#if CONFIG_NET_TCP_RECVDELAY > 0
if (pstate->rf_recvlen > 0)
{
pstate->rf_result = 0;
}
else
{
pstate->rf_result = -ENOTCONN;
}
#else #else
pstate->rf_result = -ENOTCONN; pstate->rf_result = -ENOTCONN;
#endif #endif
}
/* Wake up the waiting thread */ /* Wake up the waiting thread */