Exemplo n.º 1
0
 def receiveDone(self, request):
     try:
         tasklet = self.makeTasklet(request)
         TaskManager.add_task(tasklet.run)
         TaskManager.schedule()
     except Exception, e:
         Logger.exception()
         body, content_type = http_response_500(self.request)
         Logger.debug('<====', self.request.path, content_type, repr(body))
Exemplo n.º 2
0
 def handle(self, *args, **kwargs):
     if Logger.is_debug_network():
         peer = kwargs.get('peer', 'INNER')
         mode = kwargs.get('proto', 'TCP')
         Logger.debug('==== RECV %s FROM %s: %08X %s' %
                      (mode, peer, self.cmd, repr(self.raw)))
     if Message.is_inner(self.cmd):
         cmd = Message.to_outer(self.cmd)
         mi = MsgLine.unpack(self.raw)
         self.onInnerMessage(cmd, mi, *args, **kwargs)
     else:
         self.onOuterMessage(self.cmd, self.raw, *args, **kwargs)
Exemplo n.º 3
0
 def handle(self, *args, **kwargs):
     Logger.debug('====>', self.request.path)
     try:
         mo = self.onMessage(*args, **kwargs)
         if self.request._disconnected:
             Logger.info('<====', self.request.path, 'connection lost')
             return
         if isinstance(mo, MsgPack):
             body, content_type = http_response(
                 self.request, mo.pack(), content_type='application/json')
         else:
             body, content_type = http_response(self.request, mo)
     except SystemException, e:
         body, content_type = http_response_500(self.request)
Exemplo n.º 4
0
 def onOuterMessage(self, cmd, raw, *args, **kwargs):
     Logger.debug('HANDLE OUTER MESSAGE', raw, args, kwargs)
Exemplo n.º 5
0
 def onInnerMessage(self, cmd, mi, *args, **kwargs):
     Logger.debug('HANDLE INNER MESSAGE', self.raw, args, kwargs)
Exemplo n.º 6
0
    def __init__(self, request):
        self.request = request

    def handle(self, *args, **kwargs):
        Logger.debug('====>', self.request.path)
        try:
            mo = self.onMessage(*args, **kwargs)
            if self.request._disconnected:
                Logger.info('<====', self.request.path, 'connection lost')
                return
            if isinstance(mo, MsgPack):
                body, content_type = http_response(
                    self.request, mo.pack(), content_type='application/json')
            else:
                body, content_type = http_response(self.request, mo)
        except SystemException, e:
            body, content_type = http_response_500(self.request)
        except NotFoundException, e:
            # body = resource.NoResource('Not Found').render(self.request)
            body, content_type = http_response_404(self.request)
        except ForbiddenException, e:
            # body = resource.ForbiddenResource('Forbidden Access').render(self.request)
            body, content_type = http_response_403(self.request)
        except Exception, e:
            Logger.exception(kwargs)
            body, content_type = http_response_500(self.request)
        Logger.debug('<====', self.request.path, content_type, repr(body))

    def onMessage(self, *args, **kwargs):
        raise NotImplementedError
Exemplo n.º 7
0
        randint = (randint / 65536) % 32768
        randchar = randint % 255
        out.append(chr(ord(data[i]) ^ randchar))
    return "".join(out)


ffi = cffi.FFI()

with open("code.h") as f:
    data = f.read()
    ffi.cdef(data)

libc = ffi.dlopen("./code.so")

char_buf = ffi.new("unsigned char[]", 65536)

s = '{"birds":[{"t":205,"i":252,"n":3000,"s":60,"p":[1,1280,370,0,370]},{"t":104,"i":253,"n":3017,"s":30,"p":[1,0,356,1280,377]},{"t":107,"i":254,"n":3033,"s":30,"p":[1,0,301,1280,405]},{"t":115,"i":255,"n":3041,"s":30,"p":[3,147,720,213,362,578,0]},{"t":177,"i":256,"n":3054,"s":30,"p":[3,371,0,617,522,246,720]},{"t":176,"i":257,"n":3071,"s":30,"p":[3,138,0,237,220,451,720]},{"t":114,"i":258,"n":3083,"s":30,"p":[3,1280,484,822,560,242,0]},{"t":117,"i":259,"n":3089,"s":30,"p":[3,0,395,313,384,1005,0]},{"t":102,"i":260,"n":3096,"s":30,"p":[1,1045,720,0,113]},{"t":111,"i":261,"n":3103,"s":30,"p":[3,859,720,997,575,0,269]},{"t":116,"i":262,"n":3122,"s":30,"p":[1,1065,720,689,0]},{"t":109,"i":263,"n":3139,"s":30,"p":[3,1280,632,359,140,0,513]},{"t":109,"i":264,"n":3155,"s":30,"p":[3,1280,109,721,439,0,376]},{"t":112,"i":265,"n":3166,"s":30,"p":[3,1114,0,499,471,0,393]},{"t":106,"i":266,"n":3181,"s":30,"p":[1,1280,500,450,0]},{"t":182,"i":267,"n":3191,"s":30,"p":[3,1280,181,447,263,161,720]},{"t":104,"i":268,"n":3211,"s":30,"p":[1,272,720,205,0]},{"t":117,"i":269,"n":3229,"s":30,"p":[1,0,329,867,720]},{"t":117,"i":270,"n":3247,"s":30,"p":[3,1280,159,1163,516,0,75]},{"t":103,"i":271,"n":3252,"s":30,"p":[1,818,720,0,306]},{"t":102,"i":272,"n":3262,"s":30,"p":[1,327,720,1280,124]},{"t":113,"i":273,"n":3282,"s":30,"p":[3,0,642,983,146,1280,452]},{"t":178,"i":274,"n":3294,"s":30,"p":[3,175,0,713,194,862,720]}],"events":[{"in":3000,"type":1,"show":60}],"uptime":294102}'

Logger.open_std_log()
count = 1000000
start = time.time()
Logger.debug("----------------------------")
for i in xrange(count):
    libc.code(100, s, len(s), char_buf)
    data = ffi.buffer(char_buf, len(s))[:]
    # print code(100, s)
Logger.debug("----------------------------")
end = time.time()

print(end - start) * 1000000 / count