summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
97162e5)
If the caller tries to bind, and has previously set the `SO_REUSEADDR'
flag, then unlink any existing socket unless there's an active listener
already.
* Returns zero on success; -1 on failure.
*/
#define ENCF_FRESH 1u
* Returns zero on success; -1 on failure.
*/
#define ENCF_FRESH 1u
+#define ENCF_REUSEADDR 2u
static int encode_inet_addr(struct sockaddr_un *sun,
const struct sockaddr *sa,
unsigned f)
static int encode_inet_addr(struct sockaddr_un *sun,
const struct sockaddr *sa,
unsigned f)
* want an existing socket, then we're done.
*/
rc = encode_single_inet_addr(sa, sun, 0);
* want an existing socket, then we're done.
*/
rc = encode_single_inet_addr(sa, sun, 0);
+ if ((f&ENCF_REUSEADDR) && !(rc&LISTEN)) unlink(sun->sun_path);
if ((rc&USED) || (f&ENCF_FRESH)) goto found;
/* We're looking for a socket which already exists. This is
if ((rc&USED) || (f&ENCF_FRESH)) goto found;
/* We're looking for a socket which already exists. This is
{
struct sockaddr_un sun;
int rc;
{
struct sockaddr_un sun;
int rc;
+ unsigned f;
+ int reusep;
+ socklen_t n;
Dpid;
D({ char buf[ADDRBUFSZ];
Dpid;
D({ char buf[ADDRBUFSZ];
if (fixup_real_ip_socket(sk, sa->sa_family, 0))
return (-1);
} else {
if (fixup_real_ip_socket(sk, sa->sa_family, 0))
return (-1);
} else {
- encode_inet_addr(&sun, sa, ENCF_FRESH);
+ f = ENCF_FRESH;
+ n = sizeof(reusep);
+ if (!getsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &reusep, &n) && reusep)
+ f |= ENCF_REUSEADDR;
+ encode_inet_addr(&sun, sa, f);
sa = SA(&sun);
len = SUN_LEN(&sun);
}
sa = SA(&sun);
len = SUN_LEN(&sun);
}