When re-connecting already connected datagram socket ensure to clean

up its pending error state, which may be set in some rare conditions resulting
in connect() syscall returning that bogus error and making application believe
that attempt to change association has failed, while it has not in fact.

There is sockets/reconnect regression test which excersises this bug.

MFC after:	2 weeks
This commit is contained in:
Maxim Sobolev 2005-01-12 10:15:23 +00:00
parent da2fa15981
commit fdf84ec4c6

View File

@ -517,10 +517,19 @@ soconnect(so, nam, td)
*/
if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) &&
((so->so_proto->pr_flags & PR_CONNREQUIRED) ||
(error = sodisconnect(so))))
(error = sodisconnect(so)))) {
error = EISCONN;
else
} else {
SOCK_LOCK(so);
/*
* Prevent accumulated error from previous connection
* from biting us.
*/
so->so_error = 0;
SOCK_UNLOCK(so);
error = (*so->so_proto->pr_usrreqs->pru_connect)(so, nam, td);
}
return (error);
}