shithub: mc

Download patch

ref: b88dc2174f25b7ca08a0a7bc42bf981488de54c9
parent: b809eab49637ac9093c6295bdc3ba69f2a7b46c9
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jun 9 05:12:32 EDT 2017

Retry when we get a mixed up packet.

	There's better ways to do this, but we can fix that when
	we make this sanely multithreaded and get rid of the big
	lock.

--- a/lib/std/resolve+posixy.myr
+++ b/lib/std/resolve+posixy.myr
@@ -325,14 +325,15 @@
 
 const rquery = {srv, host, id
 	var pktbuf : byte[1024]
-	var pkt
-	var pfd
-	var r, n
+	var pkt, pfd, giveup
+	var r, n, inf
 
+	giveup = std.now() + 1000*Timeout
+:again
 	pfd = [
 		[.fd=srv, .events=sys.Pollin, .revents=0]
 	][:]
-	r = sys.poll(pfd[:], Timeout)
+	r = sys.poll(pfd[:], (std.now() - giveup : int)/1000)
 	if r < 0
 		-> `Err `Badconn
 	elif r == 0
@@ -343,7 +344,13 @@
 			-> `Err `Badconn
 		;;
 		pkt = pktbuf[:n]
-		-> hosts(pkt, host, id)
+		inf = hosts(pkt, host, id)
+		match inf
+		| `std.Err `Badresp:
+			goto again
+		| _:	
+			-> inf
+		;;
 	;;
 }