コード例 #1
0
   def handleNewConnection(self):
      """\
      Handle notifications from the selector service of new connection requests.

      Accepts and sets up new connections, wiring them up and passing them on via
      the "protocolHandlerSignal" outbox.
      """
      while self.dataReady("newconnection"):
         data = self.recv("newconnection")
         # If we recieve information on data ready, for a server it means we have a new connection
         # to handle
         try:
            newsock, CSA = self.createConnectedSocket(self.listener)
         except socket.error, e:
            (errorno,errmsg) = e
            if errorno != errno.EAGAIN:
               if errorno != errno.EWOULDBLOCK:
                  raise e
         else:
             pass

             self.socket_handlers[newsock] = CSA

             self.send(_ki.newCSA(self, CSA, newsock), "protocolHandlerSignal")
             self.send(newReader(CSA, ((CSA, "ReadReady"), newsock)), "_selectorSignal")            
             self.send(newWriter(CSA, ((CSA, "SendReady"), newsock)), "_selectorSignal")            
             self.addChildren(CSA)
             self.link((CSA, "CreatorFeedback"),(self,"_feedbackFromCSA"))
コード例 #2
0
    def closeSocket(self, shutdownMessage):
        """\
      Respond to a socketShutdown message by closing the socket.

      Sends a removeReader and removeWriter message to the selectorComponent.
      Sends a shutdownCSA(self, theCSA) message to "protocolHandlerSignal" outbox.
      """
        theComponent, (
            sock, howdied) = shutdownMessage.caller, shutdownMessage.message
        shutdownMessage.caller, shutdownMessage.message = None, None
        shutdownMessage = None
        #      print ("SOCKET HANDLERS BEFORE", self.socket_handlers)
        #      print ("TCPServer.closeSocket", theComponent,(sock,howdied))
        ### FIXME: Pass on how died as well in TCPServer!
        found = False
        for s in self.socket_handlers:
            if self.socket_handlers[s] == theComponent:
                found = True
                break
        if found:
            sock = s

        if sock is not None:
            theComponent = self.socket_handlers[sock]
            sock.close()

        if theComponent:
            # tell the selector about it shutting down

            self.send(removeReader(theComponent, sock), "_selectorSignal")
            self.send(removeWriter(theComponent, sock), "_selectorSignal")

            # tell protocol handlers
            self.send(_ki.shutdownCSA(self, theComponent),
                      "protocolHandlerSignal")  # "signal")
            # Delete the child component
            #          print; print ("DELETING", theComponent)
            self.removeChild(theComponent)
            if sock:
                del self.socket_handlers[sock]
            sock = None
コード例 #3
0
ファイル: TCPServer.py プロジェクト: casibbald/kamaelia
   def closeSocket(self, shutdownMessage):
      """\
      Respond to a socketShutdown message by closing the socket.

      Sends a removeReader and removeWriter message to the selectorComponent.
      Sends a shutdownCSA(self, theCSA) message to "protocolHandlerSignal" outbox.
      """
      theComponent,(sock,howdied) = shutdownMessage.caller, shutdownMessage.message
      shutdownMessage.caller, shutdownMessage.message = None, None
      shutdownMessage = None
#      print "SOCKET HANDLERS BEFORE", self.socket_handlers
#      print "TCPServer.closeSocket", theComponent,(sock,howdied)
      ### FIXME: Pass on how died as well in TCPServer!
      found = False
      for s in self.socket_handlers:
          if self.socket_handlers[s]==theComponent:
              found = True
              break
      if found:
        sock = s

      if sock is not None:
          theComponent = self.socket_handlers[sock]
          sock.close()

      if theComponent:
          # tell the selector about it shutting down

          self.send(removeReader(theComponent, sock), "_selectorSignal")            
          self.send(removeWriter(theComponent, sock), "_selectorSignal")

          # tell protocol handlers
          self.send(_ki.shutdownCSA(self, theComponent), "protocolHandlerSignal")# "signal")
          # Delete the child component
#          print; print "DELETING", theComponent
          self.removeChild(theComponent)
          if sock:
              del self.socket_handlers[sock]
          sock = None
コード例 #4
0
ファイル: TCPServer.py プロジェクト: 3rdandUrban-dev/Nuxleus
   def closeSocket(self, shutdownMessage):
      """\
      Respond to a socketShutdown message by closing the socket.

      Sends a removeReader and removeWriter message to the selectorComponent.
      Sends a shutdownCSA(self, theCSA) message to "protocolHandlerSignal" outbox.
      """
      theComponent,(sock,howdied) = shutdownMessage.caller, shutdownMessage.message
      ### FIXME: Pass on how died as well in TCPServer!
      theComponent = self.socket_handlers[sock]
      sock.close()
      
      # tell the selector about it shutting down
      
      self.send(removeReader(theComponent, sock), "_selectorSignal")            
      self.send(removeWriter(theComponent, sock), "_selectorSignal")
#      self.send(removeReader(theComponent, theComponent.socket), "_selectorSignal")            
#      self.send(removeWriter(theComponent, theComponent.socket), "_selectorSignal")

      # tell protocol handlers
      self.send(_ki.shutdownCSA(self, theComponent), "protocolHandlerSignal")# "signal")
      # Delete the child component
      self.removeChild(theComponent)