pike.git / lib / modules / Protocols.pmod / SNMP.pmod / agent.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/SNMP.pmod/agent.pike:120:    }    }   }      //! create a new instance of the agent   //!   //! @param port   //! the port number to listen for requests on   //! @param addr   //! the address to bind to for listening + //! @param usethreads + //! use threads for handler loop (if available)   //!   //! @note   //! only one agent may be bound to a port at one time   //! the agent does not currently support SMUX or AGENTX or other   //! agent multiplexing protocols. - void create(int|void port, string|void addr) { + void create(int|void port, string|void addr, int|void usethread) {    int p=port||SNMP_DEFAULT_PORT;       if(addr)    ::create(0, 0, p, addr);    else    ::create(0, 0, p); -  + #if constant(thread_create) +  if(usethread) +  { +  run_handler_thread(); +  } +  else +  { + #endif    ::set_read_callback(request_received);    ::set_nonblocking(); -  + #if constant (thread_create) +  } + #endif + }    -  + #if constant (thread_create) + void run_handler_thread() + { +  thread_create(handler);   }    -  + void handler() + { +  do +  { +  mixed r=read(); +  if(r) request_received(r); +  } +  while(1); +  + } + #endif +    //! enable manager access limits   //!   //! @param yesno   //! 1 to allow only managers to submit requests   //! 0 to allow any host to submit requests   //!   //! default setting allows all requests from all hosts   void set_managers_only(int yesno)   {    managers_security_mode=yesno;