add IPv6 support
This commit is contained in:
@@ -340,6 +340,7 @@ def display():
|
||||
|
||||
|
||||
def log(m, service="heartbeat"):
|
||||
if DEBUG: print "Log: %s" % m
|
||||
msg = time.strftime("%b %d %H:%M:%S", time.localtime(time.time()))+": "+m+"\n"
|
||||
msgs.append(msg)
|
||||
if logfmt == "msg":
|
||||
@@ -396,7 +397,7 @@ def fromaddr(name, addr, boot, interval, acks):
|
||||
|
||||
#
|
||||
#
|
||||
def readsock():
|
||||
def readsock(sock):
|
||||
global htab, win
|
||||
data, addr = sock.recvfrom(1024)
|
||||
pairs = string.split(data, ';')
|
||||
@@ -475,7 +476,9 @@ def readsock():
|
||||
del hosts[name].cmds[0]
|
||||
log("%s command initiated" % name)
|
||||
try:
|
||||
sock.sendto(rmsg, addr)
|
||||
ss=sock.sendto(rmsg, addr)
|
||||
if DEBUG:
|
||||
log("msg from %s,%s, sent %s bytes back" % (addr[0], addr[1], ss))
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -791,11 +794,16 @@ atexit.register(on_exit)
|
||||
ilist = []
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
sock.bind(("", hb_port))
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
ilist.append(sock)
|
||||
|
||||
sock6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
||||
sock6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock6.bind(("", hb_port))
|
||||
ilist.append(sock6)
|
||||
|
||||
|
||||
serv = HtmlServer((hbd_host, hbd_port), HtmlHandler)
|
||||
ilist.append(serv.fileno())
|
||||
|
||||
@@ -861,10 +869,12 @@ while running:
|
||||
except:
|
||||
sys.exit(1)
|
||||
for fh in sr[0]:
|
||||
if fh == sock:
|
||||
readsock()
|
||||
if fh == serv.fileno():
|
||||
if fh in [sock, sock6]:
|
||||
readsock(fh)
|
||||
elif fh == serv.fileno():
|
||||
serv.handle_request()
|
||||
else:
|
||||
print("what happend just now")
|
||||
if now >= next:
|
||||
next = now+1
|
||||
checkoverdue()
|
||||
|
||||
Reference in New Issue
Block a user