pike.git / lib / modules / Protocols.pmod / Line.pmod

version» Context lines:

pike.git/lib/modules/Protocols.pmod/Line.pmod:1:   /* -  * $Id: Line.pmod,v 1.22 2003/04/07 17:12:02 nilsson Exp $ +  * $Id: Line.pmod,v 1.23 2008/06/28 16:36:56 nilsson Exp $    *    * Line-buffered protocol handling.    *    * Henrik Grubbström 1998-05-27    */      #pike __REAL_VERSION__      //! Simple nonblocking line-oriented I/O.   class simple   { -  static object con; +  protected object con;       //! The sequence separating lines from eachother. "\r\n" by default. -  static constant line_separator = "\r\n"; +  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
pike.git/lib/modules/Protocols.pmod/Line.pmod:39:    //! @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);    -  static int timeout; // Idle time before timeout. -  static int timeout_time; // Time at which next timeout will occur. +  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()]    //! -  static void send(string s) +  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()]    //! -  static void do_timeout() +  protected void do_timeout()    {    if (con) {    catch {    con->set_nonblocking(0,0,0); // Make sure all callbacks are cleared.    };    catch {    con->close();    };    catch {    // FIXME: Don't do this. It will break SSL connections. /nisse    destruct(con);    };    }    }    -  static void _timeout_cb() +  protected void _timeout_cb()    {    if (timeout > 0) {    // Timeouts are enabled.       int t = time();       if (t >= timeout_time) {    // Time out    do_timeout();    } else {
pike.git/lib/modules/Protocols.pmod/Line.pmod:107:    //! @seealso    //! @[create()], @[do_timeout()]    //!    void touch_time()    {    if (timeout > 0) {    timeout_time = time() + timeout;    }    }    -  static string multi_line_buffer = ""; -  static void _handle_command(string line) +  protected string multi_line_buffer = ""; +  protected void _handle_command(string line)    {    if (handle_data) {    if (line != ".") {    multi_line_buffer += line + line_separator;    } else {    function(string:void) handle = handle_data;    string data = multi_line_buffer;    handle_data = 0;    multi_line_buffer = "";    handle(data);    }    } else {    handle_command(line);    }    }    -  static string read_buffer = ""; +  protected string read_buffer = "";       //! Read a line from the input.    //!    //! @returns    //! Returns @expr{0@} when more input is needed.    //! Returns the requested line otherwise.    //!    //! @note    //! The returned line will not contain the line separator.    //!    //! @seealso    //! @[handle_command()], @[line_separator]    //! -  static string read_line() +  protected string read_line()    {    // FIXME: Should probably keep track of where the search ended last time.    int i = search(read_buffer, line_separator);    if (i == -1) {    return 0;    }    string data = read_buffer[..i-1]; // Not the line separator.    read_buffer = read_buffer[i+sizeof(line_separator)..];       return data;
pike.git/lib/modules/Protocols.pmod/Line.pmod:161:       //! Called when data has been received.    //!    //! Overload as appropriate.    //!    //! Calls the handle callbacks repeatedly until no more lines are available.    //!    //! @seealso    //! @[handle_data()], @[handle_command()], @[read_line()]    //! -  static void read_callback(mixed ignored, string data) +  protected void read_callback(mixed ignored, string data)    {    touch_time();       read_buffer += data;       string line;       while( (line = read_line()) )    _handle_command(line);    }
pike.git/lib/modules/Protocols.pmod/Line.pmod:184:    //!    //! The elements in the queue are either strings with data to send,    //! or @expr{0@} (zero) which is the end of file marker. The connection    //! will be closed when the end of file marker is reached.    //!    //! @seealso    //! @[send()], @[disconnect()]    //!    object(ADT.Queue) send_q = ADT.Queue();    -  static string write_buffer = ""; -  static void write_callback(mixed ignored) +  protected string write_buffer = ""; +  protected void write_callback(mixed ignored)    {    touch_time();       while (!sizeof(write_buffer)) {    if (send_q->is_empty()) {    con->set_write_callback(0);    return;    } else {    write_buffer = send_q->get();    if (!write_buffer) {
pike.git/lib/modules/Protocols.pmod/Line.pmod:260:    }       //! This function is called when the connection has been closed    //! at the other end.    //!    //! Overload this function as appropriate.    //!    //! The default action is to shut down the connection on this side    //! as well.    //! -  static void close_callback() +  protected void close_callback()    {    if (handle_data || sizeof(read_buffer) || sizeof(multi_line_buffer)) {    werror("close_callback(): Unexpected close!\n");    }    con->set_nonblocking(0,0,0); // Make sure all callbacks are cleared.    con->close();    con = 0;    }       //! Create a simple nonblocking line-based protocol handler.
pike.git/lib/modules/Protocols.pmod/Line.pmod:375:    //! @seealso    //! @[Protocols.Line.simple()->handle_command()]    function(string:void) handle_line;       //! Function called once for every received line.    void handle_command(string line)    {    handle_line(line);    }    -  static void read_callback(mixed ignored, string data) +  protected void read_callback(mixed ignored, string data)    {    touch_time();       read_buffer += data;       while(1) {    if (handle_literal)    {    if (sizeof(read_buffer) < literal_length)    return;