Exemplo n.º 1
0
 def main(self):
     self.initialiseComponent()
     loop = True
     while loop:
         yield 1
         while self.dataReady("control"):
             temp = self.recv("control")
             if isinstance(temp, producerFinished):
                 self.send(temp, "mime-control")
             elif isinstance(temp, shutdown):
                 self.send(shutdown(), "mime-control")
                 self.send(shutdown(), "http-control")
                 #print "HTTPServer received shutdown"
                 loop = False
                 break
         
         while self.dataReady("mime-signal"):
             temp = self.recv("mime-signal")
             if isinstance(temp, producerFinished):
                 pass
                 #we don't need to care yet - wait 'til the request handler finishes
         
         while self.dataReady("http-signal"):
             temp = self.recv("http-signal")
             if isinstance(temp, producerFinished):
                 sig = producerFinished(self)
                 self.send(sig, "mime-control")                
                 self.send(sig, "signal")
                 loop = False
                 #close the connection
         
         self.pause()
             
     self.closeDownComponent()
Exemplo n.º 2
0
 def main(self):
     while not self.isDestroyed():
         time.sleep(0.05) # reduces CPU usage but a timer component would be better
         yield 1
         if self.dataReady("control"):
             msg = self.recv("control")
             if isinstance(msg, producerFinished) or isinstance(msg, shutdown):
                 self.send(msg, "signal")
                 self.window.destroy()
         if self.dataReady("inbox"):
             msg = self.recv("inbox")
             if isinstance(msg, TIPCNewTorrentCreated):
                 torrentname = self.pendingtorrents.pop(0)
                 labeltext = Tkinter.StringVar() # allow us to change the label's text on the fly
                 newlabel = Tkinter.Label(self.window, textvariable=labeltext)                    
                 self.torrents[msg.torrentid] = (torrentname, newlabel, labeltext)
                 labeltext.set(torrentname + " - 0%")
                 
                 newlabel.grid(row=len(self.torrents), column=0, columnspan=2, sticky=Tkinter.N+Tkinter.E+Tkinter.W+Tkinter.S)
                 self.window.rowconfigure(len(self.torrents), weight=1)
                 
             elif isinstance(msg, TIPCTorrentStartFail) or isinstance(msg, TIPCTorrentAlreadyDownloading):
                 self.pendingtorrents.pop(0) # the oldest torrent not yet started failed so remove it from the list of pending torrents
             
             elif isinstance(msg, TIPCTorrentStatusUpdate):
                 # print msg.statsdictionary.get("fractionDone","-1")
                 self.torrents[msg.torrentid][2].set(self.torrents[msg.torrentid][0] + " - " + str(int(msg.statsdictionary.get("fractionDone","0") * 100)) + "%")
         
         self.tkupdate()
     self.send(shutdown(), "signal") 
     self.send(shutdown(), "fetchersignal")
Exemplo n.º 3
0
    def main(self):
        self.initialiseComponent()
        loop = True
        while loop:
            yield 1
            while self.dataReady("control"):
                temp = self.recv("control")
                if isinstance(temp, producerFinished):
                    self.send(temp, "mime-control")
                elif isinstance(temp, shutdownMicroprocess) or isinstance(
                        temp, shutdown):
                    self.send(shutdown(), "mime-control")
                    self.send(shutdown(), "http-control")
                    #print "HTTPServer received shutdown"
                    loop = False
                    break

            while self.dataReady("mime-signal"):
                temp = self.recv("mime-signal")
                if isinstance(temp, producerFinished):
                    pass
                    #we don't need to care yet - wait 'til the request handler finishes

            while self.dataReady("http-signal"):
                temp = self.recv("http-signal")
                if isinstance(temp, producerFinished):
                    sig = producerFinished(self)
                    self.send(sig, "mime-control")
                    self.send(sig, "signal")
                    loop = False
                    #close the connection

            self.pause()

        self.closeDownComponent()
Exemplo n.º 4
0
    def main(self):
        keepconnectionopen = True
        while keepconnectionopen:
            yield 1
            while not self.anyReady():
                self.pause()
                yield 1
            while self.dataReady(
                    "control"):  # Control messages from the socket
                temp = self.recv("control")
                if isinstance(
                        temp, producerFinished
                ):  # Socket has stopped sending us data (can still send data to it)
                    self.send(
                        temp, "Psignal"
                    )  # pass on to the HTTP Parser. (eg could be a POST request)
#                    print "PRODUCER SHUTDOWN"

                elif isinstance(
                        temp,
                        shutdown):  # Socket is telling us connection is dead
                    self.send(shutdown(), "Psignal")
                    self.send(shutdown(), "Hsignal")
                    keepconnectionopen = False
#                    print "SOCKET DEAD"

            while self.dataReady(
                    "Pcontrol"):  # Control messages from the HTTP Parser
                temp = self.recv("Pcontrol")
                if isinstance(
                        temp, producerFinished
                ):  # HTTP Parser is telling us they're done parsing
                    pass  # XXXX Handling of shutdown messages from parser ???
                    #                    print "PARSER FINISHED"
                    self.send(temp, "Hsignal")  # Pass on to the HTTP Handler

            while self.dataReady(
                    "Hcontrol"):  # Control messages from the HTTP Handler
                temp = self.recv("Hcontrol")
                if isinstance(temp, producerFinished
                              ):  # Have finished sending data to the client
                    sig = producerFinished(self)  #
                    self.send(
                        sig, "Psignal"
                    )  # Make sure HTTP Parser is shutting down - (should send a "shutdown" message)
                    self.send(sig, "signal")
                    keepconnectionopen = False


#                    print "HTTP HANDLER DEAD"

        self.send(producerFinished(),
                  "signal")  # We're done, close the connection.
        yield 1  # And quit
Exemplo n.º 5
0
    def main(self):
        while not self.isDestroyed():
            time.sleep(
                0.05
            )  # reduces CPU usage but a timer component would be better
            yield 1
            if self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(
                        msg, shutdown):
                    self.send(msg, "signal")
                    self.window.destroy()
            if self.dataReady("inbox"):
                msg = self.recv("inbox")
                if isinstance(msg, TIPCNewTorrentCreated):
                    torrentname = self.pendingtorrents.pop(0)
                    labeltext = Tkinter.StringVar(
                    )  # allow us to change the label's text on the fly
                    newlabel = Tkinter.Label(self.window,
                                             textvariable=labeltext)
                    self.torrents[msg.torrentid] = (torrentname, newlabel,
                                                    labeltext)
                    labeltext.set(torrentname + " - 0%")

                    newlabel.grid(row=len(self.torrents),
                                  column=0,
                                  columnspan=2,
                                  sticky=Tkinter.N + Tkinter.E + Tkinter.W +
                                  Tkinter.S)
                    self.window.rowconfigure(len(self.torrents), weight=1)

                elif isinstance(msg, TIPCTorrentStartFail) or isinstance(
                        msg, TIPCTorrentAlreadyDownloading):
                    self.pendingtorrents.pop(
                        0
                    )  # the oldest torrent not yet started failed so remove it from the list of pending torrents

                elif isinstance(msg, TIPCTorrentStatusUpdate):
                    # print msg.statsdictionary.get("fractionDone","-1")
                    self.torrents[msg.torrentid][2].set(
                        self.torrents[msg.torrentid][0] + " - " + str(
                            int(
                                msg.statsdictionary.get("fractionDone", "0") *
                                100)) + "%")

            self.tkupdate()
        self.send(shutdown(), "signal")
        self.send(shutdown(), "fetchersignal")
Exemplo n.º 6
0
    def main(self):
        self.timebomb.activate()
        self.child.activate()
        yield 1
        while not (self.child._isStopped() or
                   (self.dataReady('_trigger')
                    and self.recv('_trigger') is True)):
            self.pause()
            yield 1
        if not self.timebomb._isStopped():
            self.send(producerFinished(), '_disarm')

        shutdown_messages = [
            producerFinished(),
            shutdownMicroprocess(),
            serverShutdown(),
            shutdown()
        ]
        for msg in shutdown_messages:
            if not self.child._isStopped():
                self.send(msg, "_sigkill")
                yield 1
                yield 1
            else:
                break

        self.removeChild(self.child)
        yield 1
        if not self.child._isStopped():
            self.child.stop()
            yield 1
            if 'signal' in self.Outboxes:
                self.send(shutdownMicroprocess(), 'signal')
                yield 1
Exemplo n.º 7
0
   def main(self):
       selectorService, selectorShutdownService, newSelector = Selector.getSelectorServices(self.tracker)
       if newSelector:
           newSelector.activate()
       self.link((self, "_selectorSignal"),selectorService)
       self.link((self, "_selectorShutdownSignal"),selectorShutdownService)
       self.selectorService = selectorService
       self.selectorShutdownService = selectorShutdownService
       self.send(newReader(self, ((self, "newconnection"), self.listener)), "_selectorSignal")
       yield 1
       while 1:
           if not self.anyReady():
               self.pause()
           if self.anyClosedSockets():
               for i in xrange(10):
                  yield 1
           self.handleNewConnection() # Data ready means that we have a connection waiting.
           if self.dataReady("control"):
               data = self.recv("control")
               if isinstance(data, serverShutdown):
                   break
           yield 1
       self.send(removeReader(self, self.listener), "_selectorSignal") 
#       for i in xrange(100): yield 1
       self.send(shutdown(), "_selectorShutdownSignal")
Exemplo n.º 8
0
   def stop(self):
       self.send(removeReader(self, self.listener), "_selectorSignal") 
#       for i in xrange(100): yield 1
       self.send(shutdown(), "_selectorShutdownSignal")
       self.listener.close() # Ensure we close the server socket. Only really likely to
                             # be called from the scheduler shutting down due to a stop.
       super(TCPServer,self).stop()
Exemplo n.º 9
0
   def main(self):
       if self.listener is None:
           self.send(shutdownMicroprocess, 'signal') # FIXME: Should probably be producerFinished. 
                                                     # FIXME: (ie advisory that I've finished, rather than
                                                     # FIXME: demand next component to shutdown)
           yield 1
           return  # NOTE: Change from suggested fix. (Simplifies code logic/makes diff smaller)

       selectorService, selectorShutdownService, newSelector = Selector.getSelectorServices(self.tracker)
       if newSelector:
           newSelector.activate()
       self.link((self, "_selectorSignal"),selectorService)
       self.link((self, "_selectorShutdownSignal"),selectorShutdownService)
       self.selectorService = selectorService
       self.selectorShutdownService = selectorShutdownService
       self.send(newReader(self, ((self, "newconnection"), self.listener)), "_selectorSignal")
       yield 1
       while 1:
           if not self.anyReady():
               self.pause()
               yield 1
           if self.anyClosedSockets():
               for i in xrange(10):
                  yield 1
           self.handleNewConnection() # Data ready means that we have a connection waiting.
           if self.dataReady("control"):
               data = self.recv("control")
               if isinstance(data, serverShutdown):
                   break
           yield 1
       self.send(removeReader(self, self.listener), "_selectorSignal") 
       self.send(shutdown(), "_selectorShutdownSignal")
Exemplo n.º 10
0
 def stop(self):
     if self.listener is not None:
         self.send(removeReader(self, self.listener), "_selectorSignal") 
         self.send(shutdown(), "_selectorShutdownSignal")
         self.listener.close() # Ensure we close the server socket. Only really likely to
                               # be called from the scheduler shutting down due to a stop.
         self.listener = None
     super(TCPServer,self).stop()
Exemplo n.º 11
0
 def shutdownKids(self):
     """Close TCP connection and HTTP parser"""
     if self.tcpclient != None and self.httpparser != None:
         self.send(producerFinished(), "_tcpsignal")
         self.send(shutdown(), "_parsersignal")
         self.removeChild(self.tcpclient)
         self.removeChild(self.httpparser)
         self.tcpclient = None
         self.httpparser = None
Exemplo n.º 12
0
 def shutdownKids(self):
     """Close TCP connection and HTTP parser"""
     if self.tcpclient != None and self.httpparser != None:
         self.send(producerFinished(), "_tcpsignal")
         self.send(shutdown(), "_parsersignal")
         self.removeChild(self.tcpclient)
         self.removeChild(self.httpparser)
         self.tcpclient = None
         self.httpparser = None
Exemplo n.º 13
0
    def main(self):
        keepconnectionopen= True
        while keepconnectionopen:
            yield 1
            while not self.anyReady():
                self.pause()
                yield 1
            while self.dataReady("control"):           # Control messages from the socket
                temp = self.recv("control")
                if isinstance(temp, producerFinished): # Socket has stopped sending us data (can still send data to it)
                    self.send(temp, "Psignal")         # pass on to the HTTP Parser. (eg could be a POST request)
#                    print "PRODUCER SHUTDOWN"

                elif isinstance(temp, shutdown):       # Socket is telling us connection is dead
                    self.send(shutdown(), "Psignal")
                    self.send(shutdown(), "Hsignal")
                    keepconnectionopen = False
#                    print "SOCKET DEAD"

            while self.dataReady("Pcontrol"):          # Control messages from the HTTP Parser
                temp = self.recv("Pcontrol")
                if isinstance(temp, producerFinished): # HTTP Parser is telling us they're done parsing
                    pass                               # XXXX Handling of shutdown messages from parser ???
#                    print "PARSER FINISHED"
                    self.send(temp, "Hsignal") # Pass on to the HTTP Handler

            while self.dataReady("Hcontrol"):          # Control messages from the HTTP Handler
                temp = self.recv("Hcontrol")
                if isinstance(temp, producerFinished): # Have finished sending data to the client
                    sig = producerFinished(self)       #
                    self.send(sig, "Psignal")          # Make sure HTTP Parser is shutting down - (should send a "shutdown" message)
                    self.send(sig, "signal")
                    keepconnectionopen = False
#                    print "HTTP HANDLER DEAD"

        self.send(producerFinished(), "signal")        # We're done, close the connection.
        yield 1                                        # And quit
Exemplo n.º 14
0
    def test_shutdownMessageCausesShutdown(self):
        """main - If the component recieves a shutdown() message, the component shuts down"""
        P = HTTPParser()
        P.activate()

        P._deliver(shutdown(), "control")

        componentExit = False
        for i in xrange(2000):
            try:
                P.next()
            except StopIteration:
                componentExit = True
                break
        if not componentExit:
            self.fail("When sent a shutdown message, the component should shutdown")
Exemplo n.º 15
0
    def test_shutdownMessageCausesShutdown(self):
        """main - If the component recieves a shutdown() message, the component shuts down"""
        S = Selector()
        S.activate()

        S._deliver(shutdown(),"control")

        componentExit = False
        for i in xrange(2000):
            try:
                S.next()
            except StopIteration:
                componentExit = True
                break
        if not componentExit:
            self.fail("When sent a shutdown message, the component should shutdown")
Exemplo n.º 16
0
    def main(self):
        while not self.isDestroyed():
            time.sleep(
                0.05
            )  # reduces CPU usage but a separate timer component would be better
            yield 1

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(
                        msg, shutdown):
                    # close this window, causing us to exit the main loop
                    # (it makes self.isDestroyed() == True)
                    self.window.destroy()

            while self.dataReady("inbox"):
                msg = self.recv("inbox")
                if isinstance(msg, TIPCNewTorrentCreated):
                    self.addTorrentToList(msg)

                elif isinstance(msg, TIPCTorrentStartFail) or isinstance(
                        msg, TIPCTorrentAlreadyDownloading):
                    # the oldest torrent not yet started failed to start so
                    # remove it from the list of pending torrents
                    print "Oops - torrent start failed!\n"
                    self.pendingtorrents.pop(0)

                elif isinstance(msg, TIPCTorrentStatusUpdate):
                    # change the label for that torrent to show the new percentage completion
                    # newlabelcaption = "{the torrent name} - {the percentage completion of the download}%"
                    newlabelcaption = self.torrents[
                        msg.torrentid][0] + " - " + str(
                            int(
                                msg.statsdictionary.get("fractionDone", "0") *
                                100)) + "%"
                    self.torrents[msg.torrentid][2].set(newlabelcaption)

            # update the screen
            self.tkupdate()

        # shutdown the TorrentPatron
        self.send(shutdown(), "signal")

        # and tell the HTTP client that we've finished which should cause
        # it to terminate gracefully, of its own accord
        self.send(producerFinished(self), "fetchersignal")
Exemplo n.º 17
0
    def main(self):
        self.notifySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.notifySocket.setblocking(False)
        self.notifySocket.bind(("127.0.0.1",1678))
        self.notifySocket.connect(("127.0.0.1",1678))
        
        self.selector =  _SelectorCore(self.notifySocket)
        self.addChildren(self.selector)
        self.selector.activate()
        self.link((self,"_toNotify"),(self.selector, "notify"))
        self.link((self,"_toControl"),(self.selector, "control"))

#        self.send( newReader( (self,"_sink"), self.notifySocket), "_toNotify")

        shutdownMessage = shutdown()
        
        while not self.childrenDone():
            if not self.anyReady():
                self.pause()
            yield 1
            
            wakeSelector=False
            
            while self.dataReady("notify"):
                message=self.recv("notify")
                self.send(message, "_toNotify")
                wakeSelector=True
            
            while self.dataReady("control"):
                message = self.recv("control")
                if isinstance(message,shutdown):
                   if self.trackedby is not None:
#                       print "we are indeed tracked"
                       self.trackedby.deRegisterService("selector")
                       self.trackedby.deRegisterService("selectorshutdown")
                       self.send(message, "_toControl")
                       shutdownMessage=message
                       wakeSelector=True

            if wakeSelector:
                self.notifySocket.send("X")


        self.send(shutdownMessage, "signal")
Exemplo n.º 18
0
 def main(self):
     """Main loop"""
     
     if self.waitForTrigger:
         while not self.anyReady():
             self.pause()
             yield 1
         
     # stop the selector
     selectorService, selectorShutdownService, newSelectorService = Selector.getSelectorServices(self.tracker) # get a reference to a     
     link = self.link((self,"selector_shutdown"),selectorShutdownService)
     
     self.send(shutdown(),"selector_shutdown")
     self.unlink(thelinkage=link)
     
     if self.dataReady("control"):
         self.send(self.recv("control"), "signal")
     else:
         self.send(producerFinished(self), "signal")
Exemplo n.º 19
0
    def main(self):
        while not self.isDestroyed():
            time.sleep(0.05)  # reduces CPU usage but a separate timer component would be better
            yield 1

            while self.dataReady("control"):
                msg = self.recv("control")
                if isinstance(msg, producerFinished) or isinstance(msg, shutdown):
                    # close this window, causing us to exit the main loop
                    # (it makes self.isDestroyed() == True)
                    self.window.destroy()

            while self.dataReady("inbox"):
                msg = self.recv("inbox")
                if isinstance(msg, TIPCNewTorrentCreated):
                    self.addTorrentToList(msg)

                elif isinstance(msg, TIPCTorrentStartFail) or isinstance(msg, TIPCTorrentAlreadyDownloading):
                    # the oldest torrent not yet started failed to start so
                    # remove it from the list of pending torrents
                    print "Oops - torrent start failed!\n"
                    self.pendingtorrents.pop(0)

                elif isinstance(msg, TIPCTorrentStatusUpdate):
                    # change the label for that torrent to show the new percentage completion
                    # newlabelcaption = "{the torrent name} - {the percentage completion of the download}%"
                    newlabelcaption = (
                        self.torrents[msg.torrentid][0]
                        + " - "
                        + str(int(msg.statsdictionary.get("fractionDone", "0") * 100))
                        + "%"
                    )
                    self.torrents[msg.torrentid][2].set(newlabelcaption)

            # update the screen
            self.tkupdate()

        # shutdown the TorrentPatron
        self.send(shutdown(), "signal")

        # and tell the HTTP client that we've finished which should cause
        # it to terminate gracefully, of its own accord
        self.send(producerFinished(self), "fetchersignal")
Exemplo n.º 20
0
    def main(self):
        self.notifySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.notifySocket.setblocking(False)
        self.notifySocket.bind(("127.0.0.1", 1678))
        self.notifySocket.connect(("127.0.0.1", 1678))

        self.selector = _SelectorCore(self.notifySocket)
        self.addChildren(self.selector)
        self.selector.activate()
        self.link((self, "_toNotify"), (self.selector, "notify"))
        self.link((self, "_toControl"), (self.selector, "control"))

        #        self.send( newReader( (self,"_sink"), self.notifySocket), "_toNotify")

        shutdownMessage = shutdown()

        while not self.childrenDone():
            if not self.anyReady():
                self.pause()
            yield 1

            wakeSelector = False

            while self.dataReady("notify"):
                message = self.recv("notify")
                self.send(message, "_toNotify")
                wakeSelector = True

            while self.dataReady("control"):
                message = self.recv("control")
                if isinstance(message, shutdown):
                    if self.trackedby is not None:
                        #                       print "we are indeed tracked"
                        self.trackedby.deRegisterService("selector")
                        self.trackedby.deRegisterService("selectorshutdown")
                        self.send(message, "_toControl")
                        shutdownMessage = message
                        wakeSelector = True

            if wakeSelector:
                self.notifySocket.send("X")

        self.send(shutdownMessage, "signal")
Exemplo n.º 21
0
    def main(self):
        """Main loop"""

        if self.waitForTrigger:
            while not self.anyReady():
                self.pause()
                yield 1

        # stop the selector
        selectorService, selectorShutdownService, newSelectorService = Selector.getSelectorServices(
            self.tracker)  # get a reference to a
        link = self.link((self, "selector_shutdown"), selectorShutdownService)

        self.send(shutdown(), "selector_shutdown")
        self.unlink(thelinkage=link)

        if self.dataReady("control"):
            self.send(self.recv("control"), "signal")
        else:
            self.send(producerFinished(self), "signal")
Exemplo n.º 22
0
    def main(self):
        """Main loop"""
        while 1:
            #print "TorrentService main loop"
            yield 1
            while self.dataReady("notify"):
                message = self.recv("notify")
                self.debug("NOTIFY")
                self.debug(message)
                if isinstance(message, TIPCServiceAdd):
                    self.addClient(message.replyService)
                elif isinstance(message, TIPCServiceRemove):
                    self.removeClient(message.replyService)
                elif isinstance(message, TIPCServicePassOn):
                    replyService = message.replyService
                    message = message.message
                    #Requests to TorrentClient
                    if isinstance(message, TIPCCreateNewTorrent) or isinstance(message, str):
                        self.pendingAdd.append(replyService)
                        self.send(message, "outbox")
                    else:
                        self.send(message, "outbox")

            while self.dataReady("inbox"):
                message = self.recv("inbox")
                self.debug("INBOX")
                self.debug(message)
                if isinstance(message, TIPCNewTorrentCreated):
                    replyService = self.pendingAdd.pop(0)
                    self.torrentBelongsTo[message.torrentid] = replyService
                    self.sendToClient(message, replyService)
                elif isinstance(message, TIPCTorrentAlreadyDownloading) or isinstance(message, TIPCTorrentStartFail):
                    replyService = self.pendingAdd.pop(0)            
                    self.sendToClient(message, replyService)                
                elif isinstance(message, TIPCTorrentStatusUpdate):
                    replyService = self.torrentBelongsTo[message.torrentid]
                    self.sendToClient(message, replyService)
                else:
                    self.debug("Unknown message to TorrentService from TorrentClient!\n")
                    self.debug(message)

            while self.dataReady("control"):
                message = self.recv("control")
                self.debug("CONTROL")
                self.debug(message)
                if isinstance(message, shutdown):
                    return
                    
            if self.myclients == 0:
                self.send(shutdown(), "signal")
                torrentclientfinished = False
                while not torrentclientfinished:
                    yield 1            
                    while self.dataReady("_torrentcontrol"):
                        msg = self.recv("_torrentcontrol")
                        if isinstance(msg, producerFinished):
                            torrentclientfinished = True
                            yield 1
                            break
                    self.pause()
                
                if not self.dataReady("notify"):
                    TorrentService.endTorrentServices()
                else:
                    #whoops we need to start again doh!
                    initTorrentClient()
                    
            self.pause()                
Exemplo n.º 23
0
    def main(self):
        """Main loop"""
        while 1:
            #print "TorrentService main loop"
            yield 1
            while self.dataReady("notify"):
                message = self.recv("notify")
                self.debug("NOTIFY")
                self.debug(message)
                if isinstance(message, TIPCServiceAdd):
                    self.addClient(message.replyService)
                elif isinstance(message, TIPCServiceRemove):
                    self.removeClient(message.replyService)
                elif isinstance(message, TIPCServicePassOn):
                    replyService = message.replyService
                    message = message.message
                    #Requests to TorrentClient
                    if isinstance(message, TIPCCreateNewTorrent) or isinstance(
                            message, str):
                        self.pendingAdd.append(replyService)
                        self.send(message, "outbox")
                    else:
                        self.send(message, "outbox")

            while self.dataReady("inbox"):
                message = self.recv("inbox")
                self.debug("INBOX")
                self.debug(message)
                if isinstance(message, TIPCNewTorrentCreated):
                    replyService = self.pendingAdd.pop(0)
                    self.torrentBelongsTo[message.torrentid] = replyService
                    self.sendToClient(message, replyService)
                elif isinstance(message,
                                TIPCTorrentAlreadyDownloading) or isinstance(
                                    message, TIPCTorrentStartFail):
                    replyService = self.pendingAdd.pop(0)
                    self.sendToClient(message, replyService)
                elif isinstance(message, TIPCTorrentStatusUpdate):
                    replyService = self.torrentBelongsTo[message.torrentid]
                    self.sendToClient(message, replyService)
                else:
                    self.debug(
                        "Unknown message to TorrentService from TorrentClient!\n"
                    )
                    self.debug(message)

            while self.dataReady("control"):
                message = self.recv("control")
                self.debug("CONTROL")
                self.debug(message)
                if isinstance(message, shutdown):
                    return

            if self.myclients == 0:
                self.send(shutdown(), "signal")
                torrentclientfinished = False
                while not torrentclientfinished:
                    yield 1
                    while self.dataReady("_torrentcontrol"):
                        msg = self.recv("_torrentcontrol")
                        if isinstance(msg, producerFinished):
                            torrentclientfinished = True
                            yield 1
                            break
                    self.pause()

                if not self.dataReady("notify"):
                    TorrentService.endTorrentServices()
                else:
                    #whoops we need to start again doh!
                    initTorrentClient()

            self.pause()
Exemplo n.º 24
0
 def main(self):
     self.timebomb.activate()
     self.child.activate()
     yield 1
     while not (self.child._isStopped() or (self.dataReady('_trigger') and self.recv('_trigger') is True)):
         self.pause()
         yield 1
     if not self.timebomb._isStopped():
         self.send(producerFinished(), '_disarm')
     
     shutdown_messages = [ producerFinished(), shutdownMicroprocess(), serverShutdown(), shutdown() ]
     for msg in shutdown_messages:
         if not self.child._isStopped():
             self.send( msg, "_sigkill")
             yield 1
             yield 1
         else:
             break
          
     self.removeChild(self.child)
     yield 1
     if not self.child._isStopped():
         self.child.stop()
         yield 1
         if 'signal' in self.Outboxes:
             self.send(shutdownMicroprocess(), 'signal')
             yield 1