ref: f4168542a453eb0882b7ab7cfe02f6150f539e28
parent: ddffd453738e97de59d5320c14bb08714cc8ef22
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Apr 27 18:33:10 EDT 2016
Remove a socket if it's already there.
--- a/lib/std/listen+posixy.myr
+++ b/lib/std/listen+posixy.myr
@@ -86,6 +86,7 @@
const announceunix = {path
var sa : sys.sockaddr_un
var sock
+ var yes
sa = [.fam = sys.Afunix]
if path.len >= sa.path.len
@@ -97,6 +98,11 @@
if sock < 0
-> `Fail "failed to create socket"
;;
+ yes = 1
+ if sys.setsockopt(sock, sys.Solsock, sys.Soreuseaddr, &yes castto(void#), sizeof(int)) < 0
+ -> `Fail "failed to set sock opts"
+ ;;
+ sys.unlink(path)
if sys.bind(sock, &sa castto(sys.sockaddr#), sizeof(sys.sockaddr_un)) < 0
-> `Fail "failed to bind address"
;;