Skip to content

Commit

Permalink
Networking: Fix a major TCP bug introduced with commit e71c09ce9777ff…
Browse files Browse the repository at this point in the history
…732cb60bd07fb43d85522f79d6. Some connection logic was reorder -- setting the socket got moved BEFORE the point where the check was made if the socket was already connected. The resulting behavior was odd: Telnet would connect, but then when you exit and reconnect, it would fail to connect. But then if try again, it would connect okay. So the symptom was connect-fail-connect-fail-...
  • Loading branch information
gregory-nutt committed Jan 29, 2015
1 parent ebf1e12 commit 7f95e4f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions net/socket/accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)

if (addr)
{
/* If an address is provided, then the lenght must also be provided. */
/* If an address is provided, then the length must also be provided. */

DEBUGASSERT(addrlen);

Expand Down Expand Up @@ -258,8 +258,6 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)

pnewsock->s_domain = psock->s_domain;
pnewsock->s_type = SOCK_STREAM;
pnewsock->s_flags |= _SF_CONNECTED;
pnewsock->s_flags &= ~_SF_CLOSED;

/* Perform the correct accept operation for this address domain */

Expand Down Expand Up @@ -306,6 +304,10 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
}
#endif /* CONFIG_NET_TCP */

/* Mark the socket as connected. */

pnewsock->s_flags |= _SF_CONNECTED;
pnewsock->s_flags &= ~_SF_CLOSED;
return newfd;

errout_with_socket:
Expand Down

0 comments on commit 7f95e4f

Please sign in to comment.