Commit ad905258 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[1428] Give attention to socket than needs it

parent 936d5cad
......@@ -875,6 +875,14 @@ class BoB:
socket = self._srv_socket.accept()
self._unix_sockets[socket.fileno()] = (socket, '')
def _socket_data(self, socket_fileno):
"""
This is called when a socket identified by the socket_fileno needs
attention. We try to read data from there. If it is closed, we remove
it.
"""
pass
def run(self, wakeup_fd):
"""
The main loop, waiting for sockets, commands and dead processes.
......@@ -899,7 +907,8 @@ class BoB:
try:
(rlist, wlist, xlist) = \
select.select([wakeup_fd, ccs_fd,
self._srv_socket.fileno()], [], [],
self._srv_socket.fileno()] +
list(self._unix_sockets.keys()), [], [],
wait_time)
except select.error as err:
if err.args[0] == errno.EINTR:
......@@ -920,6 +929,8 @@ class BoB:
os.read(wakeup_fd, 32)
elif fd == self._srv_socket.fileno():
self._srv_accept()
elif fd in self._unix_sockets:
self._socket_data(fd)
# global variables, needed for signal handlers
options = None
......
......@@ -941,6 +941,7 @@ class SocketSrvTest(unittest.TestCase):
self.__boss = BoB()
self.__select_backup = bind10_src.select.select
self.__select_called = None
self.__socket_data_called = None
def tearDown(self):
"""
......@@ -976,6 +977,10 @@ class SocketSrvTest(unittest.TestCase):
self.__select_called = (r, w, x, t)
return ([42], [], [])
def __select_data(self, r, w, x, t):
self.__select_called = (r, w, x, t)
return ([13], [], [])
def __accept(self):
"""
Hijact the accept method of the boss.
......@@ -1014,6 +1019,24 @@ class SocketSrvTest(unittest.TestCase):
# And the buffer (yet empty) is there
self.assertEqual({13: (socket, '')}, self.__boss._unix_sockets)
def __socket_data(self, socket):
self.__boss.runnable = False
self.__socket_data_called = socket
def test_socket_data(self):
"""
Test that a socket that wants attention gets it.
"""
self.__boss._srv_socket = self.__FalseSocket(self)
self.__boss._socket_data = self.__socket_data
self.__boss.ccs = self.__CCS()
self.__boss._unix_sockets = {13: (self.__FalseSocket(self, 13), '')}
self.__boss.runnable = True
bind10_src.select.select = self.__select_data
self.__boss.run(2)
self.assertEqual(13, self.__socket_data_called)
self.assertEqual(([2, 1, 42, 13], [], [], None), self.__select_called)
if __name__ == '__main__':
# store os.environ for test_unchanged_environment
original_os_environ = copy.deepcopy(os.environ)
......
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