@@ -0,0 +1,1255 @@
+%0Afrom server_socket_multiplexer import ServerMultiplexedSelect,ServerMockSocket%0Aimport select%0Aimport socket%0A%0A# Note: Make sure that this module is loaded after all other modules except%0A# of_01%0A%0Adef launch():%0A  # Server side:%0A  #  - Instantiate ServerMultipexedSelect (this will create a true%0A  #    socket for the pinger)%0A  #  - override select.select with ServerMultiplexedSelect%0A  #  - override socket.socket%0A  #    - takes two params: protocol, socket type%0A  #    - if not SOCK_STREAM type, return a normal socket%0A  #  - we don't know bind address until bind() is called%0A  #  - after bind(), create true socket, create SocketDemultiplexer%0A  # All subsequent sockets will be instantiated through accept()%0A  mux_select = ServerMultiplexedSelect()%0A  # Monkey patch select.select%0A  select._old_select = select.select%0A  select.select = mux_select.select%0A  # Monkey patch socket.socket%0A  socket._old_socket = socket.socket%0A  def socket_patch(protocol, sock_type):%0A    if sock_type == socket.SOCK_STREAM:%0A      return ServerMockSocket(protocol, sock_type,%0A                 set_true_listen_socket=mux_select.set_true_listen_socket)%0A    else:%0A      socket._old_socket(protocol, sock_type)%0A  socket.socket = socket_patch%0A  # TODO(cs): will mux_select be GC'ed?%0A%0A

Implement monkey patching. It works!