Commit fba6ae8c authored by Joanne Hugé's avatar Joanne Hugé

Start adding comments where necessary

parent f1e95660
...@@ -193,6 +193,8 @@ class Babel(object): ...@@ -193,6 +193,8 @@ class Babel(object):
self.locked = set() self.locked = set()
self.reset() self.reset()
# Create new socket, try assigning it next time select is called
# Called at __init__ and then if current socket fails
def reset(self): def reset(self):
try: try:
del self.socket, self.request_dump del self.socket, self.request_dump
...@@ -203,6 +205,10 @@ class Babel(object): ...@@ -203,6 +205,10 @@ class Babel(object):
self.read_buffer.want(header.size) self.read_buffer.want(header.size)
s = socket.socket(socket.AF_UNIX, s = socket.socket(socket.AF_UNIX,
socket.SOCK_STREAM | socket.SOCK_CLOEXEC) socket.SOCK_STREAM | socket.SOCK_CLOEXEC)
# Will be called instead of default select function until connection
# with new socket succeeds
# If it succeeds, default select gets called at the end and gets
# set again as self.select
def select(*args): def select(*args):
try: try:
s.connect(self.socket_path) s.connect(self.socket_path)
...@@ -217,7 +223,11 @@ class Babel(object): ...@@ -217,7 +223,11 @@ class Babel(object):
self.select = select self.select = select
self.close = s.close self.close = s.close
# This function is only called after reset until connection to new socket is
# successful, then self.send(Dump(11)) is used
def request_dump(self): def request_dump(self):
# If connection to new socket is currently failing,
# then mark the dump as handled by calling handle_dump with empty parameters
if self.select({}, {}, ()): if self.select({}, {}, ()):
self.handle_dump((), (), (), ()) self.handle_dump((), (), (), ())
else: else:
...@@ -228,6 +238,9 @@ class Babel(object): ...@@ -228,6 +238,9 @@ class Babel(object):
def send(self, packet): def send(self, packet):
packet.write(self.write_buffer) packet.write(self.write_buffer)
# Adds socket to the list of read / write file descriptors
# to poll in the main loop
# Assigns _read and _write callbacks to socket
def select(self, r, w, t): def select(self, r, w, t):
s = self.socket s = self.socket
r[s] = self._read r[s] = self._read
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment