Skip to content
Snippets Groups Projects
Select Git revision
  • 45d18405365af2d552b728b3d5539dcfb0cf126c
  • master default protected
  • deny-not-pairing-fix-secure-simple-pairing
  • code-cleanup
  • v0.2
  • v0.1
6 results

api.h

Blame
  • Line.pmod 9.75 KiB
    /*
     * Line-buffered protocol handling.
     *
     * Henrik Grubbström 1998-05-27
     */
    
    #pike __REAL_VERSION__
    
    //! Simple nonblocking line-oriented I/O.
    class simple
    {
      protected object con;
    
      //! The sequence separating lines from eachother. "\r\n" by default.
      protected constant line_separator = "\r\n";
    
      //! If this variable has been set, multiple lines will be accumulated,
      //! until a line with a single @expr{"."@} (period) is received.
      //! @[handle_data()] will then be called with the accumulated data
      //! as the argument.
      //!
      //! @note
      //! @[handle_data()] is one-shot, ie it will be cleared when it is called.
      //!
      //! The line with the single @expr{"."@} (period) will not be in the
      //! accumulated data.
      //!
      //! @seealso
      //!   @[handle_command()]
      //!
      function(string:void) handle_data;
    
      //! This function will be called once for every line that is received.
      //!
      //! Overload this function as appropriate.
      //!
      //! @note
      //! It will not be called if @[handle_data()] has been set.
      //!
      //! @[line] will not contain the line separator.
      //!
      //! @seealso
      //! @[handle_data()]
      //!
      void handle_command(string line);
    
      protected int timeout;		// Idle time before timeout.
      protected int timeout_time;	// Time at which next timeout will occur.
    
      //! Queue some data to send.
      //!
      //! @seealso
      //! @[handle_command()], @[handle_data()], @[disconnect()]
      //!
      protected void send(string s)
      {
        send_q->put(s);
        con->set_write_callback(write_callback);
      }
    
      //! This function is called when a timeout occurrs.
      //! 
      //! Overload this function as appropriate.
      //!
      //! The default action is to shut down the connection immediately.
      //!
      //! @seealso
      //! @[create()], @[touch_time()]
      //!
      protected void do_timeout()