Refactoring to make proper use of lsocket.select