git: 9front

Download patch

ref: 51c5808c29ca8b139692c35afececf29039d63a7
parent: 285ccfbd07badd61530f25dedf842893550eb51f
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Dec 20 19:56:49 EST 2025

devip: handle announce and connect ctl error (thanks panini)

When announce and connect handlers fail,
set the state of the connection back to Idle,
allowing retry without having to allocate
a new connection.

Before, the connection would be stuck in
"Announcing"/"Announced" or "Connecting"/"Connected"
states and refuse to accept another connect
or announce ctl message.

This makes it easier to search for a free port
by just retrying announce ctl message.

--- a/sys/src/9/ip/devip.c
+++ b/sys/src/9/ip/devip.c
@@ -1052,16 +1052,17 @@
 {
 	char *p;
 
-	if(c->state != 0)
+	if(c->state != Idle)
 		error(Econinuse);
-	c->state = Connecting;
-	c->cerr[0] = '\0';
 	if(x->connect == nil)
 		error("connect not supported");
+	c->cerr[0] = '\0';
+	c->state = Connecting;
 	p = x->connect(c, cb->f, cb->nf);
-	if(p != nil)
+	if(p != nil){
+		c->state = Idle;
 		error(p);
-
+	}
 	qunlock(c);
 	if(waserror()){
 		qlock(c);
@@ -1105,16 +1106,17 @@
 {
 	char *p;
 
-	if(c->state != 0)
+	if(c->state != Idle)
 		error(Econinuse);
-	c->state = Announcing;
-	c->cerr[0] = '\0';
 	if(x->announce == nil)
 		error("announce not supported");
+	c->cerr[0] = '\0';
+	c->state = Announcing;
 	p = x->announce(c, cb->f, cb->nf);
-	if(p != nil)
+	if(p != nil){
+		c->state = Idle;
 		error(p);
-
+	}
 	qunlock(c);
 	if(waserror()){
 		qlock(c);
--