parameters: (self, sock, addr)
docstring: Handle the incoming connection.
          Gevent will close the socket when the function returns.
docstring_summary: Handle the incoming connection.
          Gevent will close the socket when the function returns.
docstring_tokens: Handle the incoming connection . Gevent will close the socket when the function returns .
function: def handle(self, sock, addr):
          """Handle the incoming connection.
          Gevent will close the socket when the function returns."""
          ipaddr = addr[0]
  
          with self.task_mgmt_lock:
              task_id = self.tasks.get(ipaddr)
              if not task_id:
                  log.warning("ResultServer did not have a task for IP %s",
                              ipaddr)
                  return
  
          storagepath = cwd(analysis=task_id)
          ctx = HandlerContext(task_id, storagepath, sock)
          task_log_start(task_id)
          try:
              try:
                  protocol = self.negotiate_protocol(task_id, ctx)
              except EOFError:
                  return
  
              # Registering the context allows us to abort the handler by
              # shutting down its socket when the task is deleted; this should
              # prevent lingering sockets
              with self.task_mgmt_lock:
                  # NOTE: the task may have been cancelled during the negotation
                  # protocol and a different task for that IP address may have
                  # been registered
                  if self.tasks.get(ipaddr) != task_id:
                      log.warning("Task #%s for IP %s was cancelled during "
                                  "negotiation", task_id, ipaddr)
                      return
                  s = self.handlers.setdefault(task_id, set())
                  s.add(ctx)
  
              try:
                  with protocol:
                      protocol.handle()
              except CuckooOperationalError as e:
                  log.error(e)
              finally:
                  with self.task_mgmt_lock:
                      s.discard(ctx)
                  ctx.cancel()
                  if ctx.buf:
                      # This is usually not a good sign
                      log.warning("Task #%s with protocol %s has unprocessed "
                                  "data before getting disconnected",
                                  task_id, protocol)
  
          finally:
              task_log_stop(task_id)
function_tokens: def handle ( self , sock , addr ) : ipaddr = addr [ 0 ] with self . task_mgmt_lock : task_id = self . tasks . get ( ipaddr ) if not task_id : log . warning ( "ResultServer did not have a task for IP %s" , ipaddr ) return storagepath = cwd ( analysis = task_id ) ctx = HandlerContext ( task_id , storagepath , sock ) task_log_start ( task_id ) try : try : protocol = self . negotiate_protocol ( task_id , ctx ) except EOFError : return # Registering the context allows us to abort the handler by # shutting down its socket when the task is deleted; this should # prevent lingering sockets with self . task_mgmt_lock : # NOTE: the task may have been cancelled during the negotation # protocol and a different task for that IP address may have # been registered if self . tasks . get ( ipaddr ) != task_id : log . warning ( "Task #%s for IP %s was cancelled during " "negotiation" , task_id , ipaddr ) return s = self . handlers . setdefault ( task_id , set ( ) ) s . add ( ctx ) try : with protocol : protocol . handle ( ) except CuckooOperationalError as e : log . error ( e ) finally : with self . task_mgmt_lock : s . discard ( ctx ) ctx . cancel ( ) if ctx . buf : # This is usually not a good sign log . warning ( "Task #%s with protocol %s has unprocessed " "data before getting disconnected" , task_id , protocol ) finally : task_log_stop ( task_id )