src/line_proto.h
changeset 10 9fe218576d13
parent 8 be88e543c8ff
child 11 14e79683c48c
equal deleted inserted replaced
9:4c4c906cc649 10:9fe218576d13
    11  * The state handle
    11  * The state handle
    12  */
    12  */
    13 struct line_proto;
    13 struct line_proto;
    14 
    14 
    15 /*
    15 /*
       
    16  * The callback for receiving lines
       
    17  */
       
    18 typedef void (*line_proto_read_cb)(struct line_proto *lp, const char *line, void *arg);
       
    19 
       
    20 /*
    16  * Create a new line_proto off the the given sock_stream. The newly allocated line_proto will be returned via *lp_ptr.
    21  * Create a new line_proto off the the given sock_stream. The newly allocated line_proto will be returned via *lp_ptr.
       
    22  *
       
    23  * The incoming lines are buffered in a buffer of \a buf_size bytes. This imposes a maximum limit on the line length.
       
    24  *
       
    25  * The given callback function/argument will be used to provide event-based recv support.
    17  */
    26  */
    18 err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, struct error_info *err);
    27 err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, size_t buf_size,
       
    28         line_proto_read_cb cb_func, void *cb_arg, struct error_info *err);
    19 
    29 
    20 /*
    30 /*
    21  * Receive one line into the given buffer. The line will be terminated with '\r\n', and said terminator will be
    31  * Receive one line into the given buffer. The line will be terminated with '\r\n', and said terminator will be
    22  * NUL'd out, so the buffer is safe for use as a C-string after succesfull return.
    32  * NUL'd out, so the buffer is safe for use as a C-string after succesfull return.
    23  *
    33  *
    24  * Note: currently this uses the buffer to store intermediate state, so always pass the same buffer (for now).
    34  * Note: currently this uses the buffer to store intermediate state, so always pass the same buffer (for now).
    25  */
    35  */
    26 err_t line_proto_read (struct line_proto *lp, char *buf, size_t len);
    36 err_t line_proto_read (struct line_proto *lp, const char **line_ptr);
    27 
    37 
    28 /*
    38 /*
    29  * Get current error_info*
    39  * Get current error_info*
    30  */
    40  */
    31 const struct error_info* line_proto_error (struct line_proto *lp);
    41 const struct error_info* line_proto_error (struct line_proto *lp);