if (sock == -1) {
return -1;
}
+ const int on(1);
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
+ return -2; // This is part of the binding process, so it's a bind error
+ }
if (bind(sock, bind_addr, addr_len) == -1) {
return -2;
}
WRITE("S", 1);
// FIXME: Check the output and write a test for it
send_fd(output_fd, result);
+ // Don't leak the socket
+ close(result);
} else {
WRITE("E", 1);
switch (result) {
raise ShareError("Cached socket not compatible with mode " +
share_mode + " and name " + share_name)
# Grab yet unused token
- token = 't' + str(random.randint(0, 2^32-1))
+ token = 't' + str(random.randint(0, 2 ** 32-1))
while token in self._live_tokens:
- token = 't' + str(random.randint(0, 2^32-1))
+ token = 't' + str(random.randint(0, 2 ** 32-1))
self._waiting_tokens[token] = socket
self._live_tokens.add(token)
socket.shares[token] = (share_mode, share_name)