Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

io_t - input/output abstraction object


Functions

ssize_t io_pipe (io_t *out, io_t *in)
 Write the input stream to the output stream.
int io_dup (io_t *io, io_t **pio)
 Duplicate an IO handle.
ssize_t io_copy (io_t *out, io_t *in, size_t size)
 Copy a block of data between two io_t objects.
ssize_t io_seek (io_t *io, size_t off)
 Seek to the given position.
ssize_t io_tell (io_t *io)
 Return the current file position.
int io_free (io_t *io)
 Free an io_t object.
ssize_t io_read (io_t *io, char *buf, size_t size)
 Read a block of data from an io_t object.
ssize_t io_printf (io_t *io, const char *fmt,...)
 Write a string to io using printf-style format strings.
ssize_t io_flush (io_t *io)
 Flush the write buffer.
ssize_t io_write (io_t *io, const char *buf, size_t size)
 Write a block of data to an io_t object.
ssize_t io_putc (io_t *io, char c)
 Write a char to an io_t object.
ssize_t io_getc (io_t *io, char *pc)
 Read a char from an io_t object.
ssize_t io_gets (io_t *io, char *buf, size_t size)
 Read a line from an io_t object.
int io_codec_add_head (io_t *io, codec_t *c)
 Insert a codec at the head the codec chain.
int io_codec_add_tail (io_t *io, codec_t *c)
 Append a codec to the codec chain.
int io_codecs_remove (io_t *io)
 Flush, remove and free all codecs in the codec chain.
int io_name_set (io_t *io, const char *name)
 Set the name of an io_t object.
int io_name_get (io_t *io, char *name, size_t sz)
 Return the name of the given io_t object.
int io_is_secure (io_t *io)
int io_prv_create (size_t dev_sz, io_t **pio)

Detailed Description


Function Documentation

int io_codec_add_head io_t io,
codec_t c
 

Parameters:
io the io_t object
c the codec to append
Returns:
0 on success, non-zero on error

Definition at line 815 of file io.c.

References io_s::codec_chain, codec_t, and io_t.

int io_codec_add_tail io_t io,
codec_t c
 

Parameters:
io the io_t object
c the codec to append
Returns:
0 on success, non-zero on error

Definition at line 834 of file io.c.

References io_s::codec_chain, codec_t, and io_t.

Referenced by emb_open(), session_prv_load_from_io(), session_prv_save_to_io(), and translate().

int io_codecs_remove io_t io  ) 
 

Parameters:
io the io_t object
Returns:
0 on success, non-zero on error

Definition at line 852 of file io.c.

References io_s::codec_chain, codec_free(), codec_t, io_t, and io_s::wbuf.

Referenced by io_free(), session_prv_load_from_io(), session_prv_save_to_buf(), and session_prv_save_to_io().

ssize_t io_copy io_t out,
io_t in,
size_t  size
 

Read from in a block of data size bytes long and write it to the out output io_t object

Parameters:
out output io_t object
in input io_t object
size number of bytes to copy
Returns:
the number of bytes copied (that can be less the size in case of EOF on in) or -1 on error.

Definition at line 117 of file io.c.

References io_read(), io_t, io_write(), and MIN.

int io_dup io_t io,
io_t **  pio
 

Create a copy of io and store it to *pio. The returned object will share the same underlaying IO device, the same codecs connected to io and the same input and output buffers. Buffers, codecs and IO devices will not be released until all io_t object associated to it will be freed.

Parameters:
io the io_t object to be dupped
pio on success will contain the duplicated io_t object
Returns:
0 on success, not zero on failure
See also:
io_free

Definition at line 92 of file io.c.

References io_t, and io_s::refcnt.

ssize_t io_flush io_t io  ) 
 

Force a write of all buffered data to the output device.

Parameters:
io the io_t object to be flushed
Returns:
zero on success, -1 on error

Definition at line 622 of file io.c.

References io_t, io_s::wbuf, io_s::wcount, and io_s::write.

Referenced by io_free(), io_seek(), io_tell(), and io_write().

int io_free io_t io  ) 
 

Free the given io_t object. If io has been dup'd and the reference count is not zero then this function will only decrement it and return. Otherwise io will be flushed, the codec applied to it (if any) freed and any other resource associated to it released.

Parameters:
io the io_t object to be free'd
Returns:
0 on success, non-zero on error
See also:
io_dup

Definition at line 427 of file io.c.

References io_codecs_remove(), io_flush(), io_t, io_s::name, io_s::rbuf, io_s::refcnt, io_s::term, io_s::ubuf, and io_s::wbuf.

Referenced by app_init(), io_fd_create(), io_mem_create(), io_ssl_create(), request_free(), response_free(), session_prv_load_from_buf(), session_prv_save_to_buf(), translate(), and u_tmpfile_open().

ssize_t io_getc io_t io,
char *  pc
[inline]
 

Read a char from the io_t object io and save it at *pc.

Parameters:
io the io_t object
pc on success will hold the read character
Returns:
the number of bytes read (i.e. 1) on success or -1 on error.

Definition at line 712 of file io.c.

References io_read(), and io_t.

Referenced by translate_opaque_to_c().

ssize_t io_gets io_t io,
char *  buf,
size_t  size
 

Read a line from in and save it to buf that must be at least size bytes long.

Parameters:
io the io_t object
buf destination buffer
size size of buf
Returns:
the length of the line on success, 0 on EOF or -1 on error.

Definition at line 747 of file io.c.

References io_t, MIN, io_s::rbuf, io_s::rcount, and io_s::roff.

Referenced by request_parse_header(), and u_getline().

int io_is_secure io_t io  ) 
 

Definition at line 945 of file io.c.

References io_t, and io_s::is_secure.

int io_name_get io_t io,
char *  name,
size_t  sz
 

Save in name the name of io.

Parameters:
io the io_t object
name on success will contain the name of the given io
sz size of name
Returns:
0 on success, non-zero on error

Definition at line 916 of file io.c.

References io_t, MIN, and io_s::name.

Referenced by translate().

int io_name_set io_t io,
const char *  name
 

Set the name of the given io to name. A name is a label that can be used to store any naming scheme (file names, URI, etc.)

Parameters:
io the io_t object
name the name to be given to io
Returns:
0 on success, non-zero on error

Definition at line 886 of file io.c.

References io_t, and io_s::name.

Referenced by u_file_open(), and u_tmpfile_open().

ssize_t io_pipe io_t out,
io_t in
 

Read all data from in and copy it to out

Parameters:
out output IO object
in input IO object
Returns:
the number of bytes read from in and written to out or -1 on error

Definition at line 48 of file io.c.

References io_read(), io_t, and io_write().

ssize_t io_printf io_t io,
const char *  fmt,
  ...
 

Printf-like function used to easily write strings to io using well-known printf format strings. See printf(3) manual for format description.

Parameters:
io the io_t object to write to
fmt printf-style format string
... format string arguments
Returns:
the number of chars written on success, -1 on error

Definition at line 572 of file io.c.

References io_t, and io_write().

Referenced by response_print_header_to_io(), session_prv_save_var(), translate_opaque_to_c(), and u_printf_ccstr().

int io_prv_create size_t  dev_sz,
io_t **  pio
 

Definition at line 957 of file io.c.

References io_s::codec_chain, io_t, io_s::refcnt, and io_s::size.

ssize_t io_putc io_t io,
char  c
[inline]
 

Write the character c to io

Parameters:
io the io_t object
c the char to write
Returns:
the number of bytes written (i.e. 1) on success or -1 on error.

Definition at line 697 of file io.c.

References io_t, and io_write().

Referenced by u_printf_ccstr().

ssize_t io_read io_t io,
char *  buf,
size_t  size
 

Read size bytes from io and save them to buf (that must be big enough).

Parameters:
io the io_t object onto which the read operation is performed
buf the buffer that will contain the read bytes
size number of bytes to read
Returns:
the number of bytes read and saved to buf, 0 on end of file condition, and -1 on error.

Definition at line 525 of file io.c.

References io_s::eof, io_t, MIN, io_s::rbuf, io_s::rcount, and io_s::roff.

Referenced by io_copy(), io_getc(), io_pipe(), and u_md5io().

ssize_t io_seek io_t io,
size_t  off
 

Moves the read/write file offset so that the next read or the next write will start at the given position. Note that not all io_t devices support seeking (e.g. sockets don't) so this function will always fail when used on those devices.

Parameters:
io the io_t object
off absolute offset to move to
Returns:
the given offset on success, -1 on error

Definition at line 159 of file io.c.

References io_flush(), io_t, and io_s::seek.

Referenced by translate().

ssize_t io_tell io_t io  ) 
 

Return the current file position. There exists a unique read and write position offset.

Parameters:
io the io_t object
Returns:
the given offset on success, -1 on error

Definition at line 180 of file io.c.

References io_flush(), io_t, and io_s::tell.

Referenced by session_prv_save_to_buf().

ssize_t io_write io_t io,
const char *  buf,
size_t  size
 

Write size bytes of buf to io.

Parameters:
io the io_t object
buf the buffer with the bytes to write
size number of bytes to write
Returns:
the number of bytes written or -1 on error.

Definition at line 656 of file io.c.

References io_flush(), io_t, IO_WBUF_AVAIL, IO_WBUF_FULL, io_s::wbuf, and io_s::wcount.

Referenced by io_copy(), io_pipe(), io_printf(), and io_putc().


←Products
© 2005-2006 - KoanLogic S.r.l. - All rights reserved