Example #1
0
 def run(self):
     global GLOBAL_TERMINATE
     if 'event' in globals(): event.signal(2,self._lib_out).add()
     if select_enabled:
         while GLOBAL_TERMINATE == False:
             self.select_handle()
     elif 'event' in globals(): event.dispatch()
Example #2
0
def main():
    if len(sys.argv) > 1:
        url = sys.argv[1]
    else:
        url = 'http://localhost:8888/msgbus/chatdemo'

    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
    if not path.startswith('/msgbus/'):
        raise ValueError, 'invalid msgbus URL: %s' % url
    channel = path[8:]
    username, password, hostname, port = parse_netloc(scheme, netloc)

    # XXX - stdin b0rkage!
    os.putenv('EVENT_NOKQUEUE', '1')
    os.putenv('EVENT_NOPOLL', '1')
    
    event.init()
    event.read(0, recv_stdin, channel)
    evmsg.open(hostname, port, scheme == 'https')
    if username and password:
        evmsg.set_auth(username, password)
    sub = evmsg.subscribe(channel, '*', '*', recv_chat)
    event.signal(2, event.abort)

    print 'pub/sub to', url
    event.dispatch()
Example #3
0
    def main(self, argv=sys.argv[1:], subclasses=None):
        """Run any Handler subclass in __main__ scope.
        """
        # XXX - even with only select enabled, BPF immediate doesn't
        # work on OSX, and we only get read events on full buffers.
        if sys.platform in ('darwin', 'win32'):
            os.putenv('EVENT_NOKQUEUE', '1')
            os.putenv('EVENT_NOPOLL', '1')

        if not subclasses:
            subclasses = find_subclasses(Handler, __import__('__main__'))
            if not subclasses:
                raise RuntimeError, 'no Handler subclasses found'

        event.init()
        self.setup()
        self.getopt(argv)

        # XXX - configure pcap filter
        global config
        config['pcap']['prefilter'] = ' '.join(self.args)

        for cls in subclasses:
            handlers[cls.name] = cls()
        for sig in (signal.SIGINT, signal.SIGTERM):
            event.signal(sig, event.abort)

        event.dispatch()

        for h in handlers.itervalues():
            h.teardown()
        self.teardown()
Example #4
0
def runEventLoop():
    global loop_running
    if not loop_running:
        event.init()
        event.signal(2, die)
        stackless.tasklet(eventLoop)()
        loop_running = True
Example #5
0
def runEventLoop():
    global loop_running
    if not loop_running:
        event.init()
        event.signal(2, die)
        stackless.tasklet(eventLoop)()
        loop_running = True
Example #6
0
def main():
    if len(sys.argv) > 1:
        url = sys.argv[1]
    else:
        url = 'http://localhost:8888/msgbus/chatdemo'

    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
    if not path.startswith('/msgbus/'):
        raise ValueError, 'invalid msgbus URL: %s' % url
    channel = path[8:]
    username, password, hostname, port = parse_netloc(scheme, netloc)

    # XXX - stdin b0rkage!
    os.putenv('EVENT_NOKQUEUE', '1')
    os.putenv('EVENT_NOPOLL', '1')

    event.init()
    event.read(0, recv_stdin, channel)
    evmsg.open(hostname, port, scheme == 'https')
    if username and password:
        evmsg.set_auth(username, password)
    sub = evmsg.subscribe(channel, '*', '*', recv_chat)
    event.signal(2, event.abort)

    print 'pub/sub to', url
    event.dispatch()
Example #7
0
def runEventLoop():
    global loop_running
    if not loop_running:
        event.init()
        event.signal(2, die)
        event.signal(3, die)
        eventLoop()
        loop_running = True
Example #8
0
 def test_signal2(self):
     def __signal2_cb(sig):
         if sig:
             event.abort()
         else:
             os.kill(os.getpid(), signal.SIGUSR1)
     print 'test_signal2'
     event.signal(signal.SIGUSR1, __signal2_cb, signal.SIGUSR1)
     event.timeout(2, __signal2_cb)
Example #9
0
    def test_signal2(self):
        def __signal2_cb(sig):
            if sig:
                event.abort()
            else:
                os.kill(os.getpid(), signal.SIGUSR1)

        print 'test_signal2'
        event.signal(signal.SIGUSR1, __signal2_cb, signal.SIGUSR1)
        event.timeout(2, __signal2_cb)
Example #10
0
def main():
    op = optparse.OptionParser(usage='%prog [OPTIONS] [URL|channel]')
    op.add_option('-q',
                  dest='quiet',
                  help='enable quiet output',
                  action='store_true')
    op.add_option('-s',
                  dest='sender',
                  default='*',
                  help='subscribe to messages from this sender')
    op.add_option('-t',
                  dest='type',
                  default='*',
                  help='subscribe to messages of this type')
    opts, args = op.parse_args(sys.argv[1:])
    if not args:
        url = 'http://localhost:8888/msgbus/'
        channel = ''
    elif args[0].startswith('http'):
        url = args[0]
        channel = url.split('/')[-1]
    else:
        url = 'http://localhost:8888/msgbus/%s' % args[0]
        channel = args[0]

    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
    if not path.startswith('/msgbus/'):
        raise ValueError, 'invalid msgbus URL: %s' % url
    channel = path[8:]
    username, password, hostname, port = parse_netloc(scheme, netloc)

    d = {'quiet': opts.quiet, 'cnt': 0}
    start = time.time()

    event.init()

    evmsg.open(hostname, port, scheme == 'https')
    if username and password:
        evmsg.set_auth(username, password)
    sub = evmsg.subscribe(channel, opts.type, opts.sender, recv_msg, d)

    event.signal(2, event.abort)

    print >> sys.stderr, 'subscribed to', url
    event.dispatch()

    secs = time.time() - start
    print >>sys.stderr, 'received %d msgs over %d secs (%.1f mps)' % \
          (d['cnt'], secs, float(d['cnt']) / secs)
Example #11
0
 def signal(self, signalnum, handler):
     def wrapper():
         try:
             handler(signalnum, None)
         except:
             self.signal_exc_info = sys.exc_info()
             event.abort()
     return event_wrapper(event.signal(signalnum, wrapper))
Example #12
0
def main(argv):
    # initialize libevent
    event.init()

    # set the SIGINT handler
    event.signal(signal.SIGINT, _sigint)

    # create an incoming (listen) socket, and bind
    listen_sock = socket.socket()
    listen_sock.setblocking(0)
    listen_sock.bind(("localhost", listen_port))

    # start listening, set event
    listen_sock.listen(20)
    event.event(listen_read, None, event.EV_READ | event.EV_PERSIST, listen_sock).add()

    # start event loop
    event.dispatch()
Example #13
0
def main():
    op = optparse.OptionParser(usage='%prog [OPTIONS] [URL|channel]')
    op.add_option('-q', dest='quiet', help='enable quiet output',
                  action='store_true')
    op.add_option('-s', dest='sender', default='*',
                  help='subscribe to messages from this sender')
    op.add_option('-t', dest='type', default='*',
                  help='subscribe to messages of this type')
    opts, args = op.parse_args(sys.argv[1:])
    if not args:
        url = 'http://localhost:8888/msgbus/'
        channel = ''
    elif args[0].startswith('http'):
        url = args[0]
        channel = url.split('/')[-1]
    else:
        url = 'http://localhost:8888/msgbus/%s' % args[0]
        channel = args[0]
        
    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
    if not path.startswith('/msgbus/'):
        raise ValueError, 'invalid msgbus URL: %s' % url
    channel = path[8:]
    username, password, hostname, port = parse_netloc(scheme, netloc)
    
    d = { 'quiet':opts.quiet, 'cnt':0 }
    start = time.time()
    
    event.init()

    evmsg.open(hostname, port, scheme == 'https')
    if username and password:
        evmsg.set_auth(username, password)
    sub = evmsg.subscribe(channel, opts.type, opts.sender, recv_msg, d)
    
    event.signal(2, event.abort)
    
    print >>sys.stderr, 'subscribed to', url
    event.dispatch()

    secs = time.time() - start
    print >>sys.stderr, 'received %d msgs over %d secs (%.1f mps)' % \
          (d['cnt'], secs, float(d['cnt']) / secs)
Example #14
0
if cmd_options.enable_test is True:
    options = {'conn_max': 300}
    options2 = {'conn_max': 300}

    inpt = {
        'outside_port': 9000,
        'type_guid': 'apple',
        'server_guid': 'co_jp',
        'server_host': 'www.apple.co.jp',
        'server_port': 80
    }
    inpt2 = {
        'outside_port': 9000,
        'type_guid': 'apple',
        'server_guid': 'com',
        'server_host': 'www.apple.com',
        'server_port': 80
    }

    r.register_port(inpt['outside_port'], inpt['type_guid'],
                    inpt['server_guid'], inpt['server_host'],
                    inpt['server_port'], options)
    r.register_port(inpt2['outside_port'], inpt2['type_guid'],
                    inpt2['server_guid'], inpt2['server_host'],
                    inpt2['server_port'], options2)

event.signal(2, _lib_out, r).add()
globals()['shutdown_in_progress'] = False
#Server(r).start()
event.dispatch()
Example #15
0
            return xmlrpclib.Fault(1, "Datastar RPC (%s): %s" % sys.exc_info()[:2])

    def export_delete(self,inpt):
        try:
            result = self.unregistersession(inpt['handle'],inpt['type_guid'],inpt['server_guid'])
            if result == True:
                return {'code':1,'status':'unregistered'}
            else:
                return {'code':0,'status':'unknown error'}
        except:
            return xmlrpclib.Fault(1, "Datastar RPC: %s" % traceback.format_exc())

def _lib_out():
    event.abort()

r = Router()

if cmd_options.enable_test == True:
    options = {'conn_max':300}
    options2 = {'conn_max':300}

    inpt = {'outside_port':9000,'type_guid':'apple','server_guid':'co_jp','server_host':'www.apple.co.jp','server_port':80}
    inpt2 = {'outside_port':9000,'type_guid':'apple','server_guid':'com','server_host':'www.apple.com','server_port':80}

    r.register_port(inpt['outside_port'],inpt['type_guid'],inpt['server_guid'],inpt['server_host'],inpt['server_port'],options)
    r.register_port(inpt2['outside_port'],inpt2['type_guid'],inpt2['server_guid'],inpt2['server_host'],inpt2['server_port'],options2)

event.signal(2,_lib_out).add()
#Server(r).start()
event.dispatch()
Example #16
0
def default_kb_handling():
    """Let event loop react to keyboard interrupt.
    """
    event.signal(2, _kb_handler)