qLibc
qio.c File Reference

I/O handling APIs. More...

Go to the source code of this file.

Macros

#define MAX_IOSEND_SIZE   (32 * 1024)
 

Functions

int qio_wait_readable (int fd, int timeoutms)
 Test & wait until the file descriptor has readable data.
 
int qio_wait_writable (int fd, int timeoutms)
 Test & wait until the file descriptor is ready for writing.
 
ssize_t qio_read (int fd, void *buf, size_t nbytes, int timeoutms)
 Read from a file descriptor.
 
ssize_t qio_write (int fd, const void *buf, size_t nbytes, int timeoutms)
 Write to a file descriptor.
 
off_t qio_send (int outfd, int infd, off_t nbytes, int timeoutms)
 Transfer data between file descriptors.
 
ssize_t qio_gets (int fd, char *buf, size_t bufsize, int timeoutms)
 Read a line from a file descriptor into the buffer pointed to until either a terminating newline or EOF.
 
ssize_t qio_puts (int fd, const char *str, int timeoutms)
 Writes the string and a trailing newline to file descriptor.
 
ssize_t qio_printf (int fd, int timeoutms, const char *format,...)
 Formatted output to a file descriptor.
 

Detailed Description

I/O handling APIs.

Definition in file qio.c.

Macro Definition Documentation

◆ MAX_IOSEND_SIZE

#define MAX_IOSEND_SIZE   (32 * 1024)

Definition at line 44 of file qio.c.

Function Documentation

◆ qio_wait_readable()

int qio_wait_readable ( int  fd,
int  timeoutms 
)

Test & wait until the file descriptor has readable data.

Parameters
fdfile descriptor
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
Returns
1 if readable, 0 on timeout, -1 if an error occurred.
Note
The argument timeoutms can be used to set maximum wait time for a socket descriptor.

Definition at line 59 of file qio.c.

◆ qio_wait_writable()

int qio_wait_writable ( int  fd,
int  timeoutms 
)

Test & wait until the file descriptor is ready for writing.

Parameters
fdfile descriptor
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
Returns
1 if writable, 0 on timeout, -1 if an error occurred.

Definition at line 87 of file qio.c.

◆ qio_read()

ssize_t qio_read ( int  fd,
void *  buf,
size_t  nbytes,
int  timeoutms 
)

Read from a file descriptor.

Parameters
fdfile descriptor
bufdata buffer pointer to write to
nbytesthe number of bytes to read from file descriptor & write into buffer
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
Returns
the number of bytes read if successful, 0 on timeout, -1 for error.

Definition at line 118 of file qio.c.

◆ qio_write()

ssize_t qio_write ( int  fd,
const void *  buf,
size_t  nbytes,
int  timeoutms 
)

Write to a file descriptor.

Parameters
fdfile descriptor
bufdata buffer pointer to read from
nbytesthe number of bytes to write to file descriptor & read from buffer
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
Returns
the number of bytes written if successful, 0 on timeout, -1 for error.

Definition at line 159 of file qio.c.

◆ qio_send()

off_t qio_send ( int  outfd,
int  infd,
off_t  nbytes,
int  timeoutms 
)

Transfer data between file descriptors.

Parameters
outfdoutput file descriptor
infdinput file descriptor
nbytesthe number of bytes to copy between file descriptors. 0 means transfer until end of infd.
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
Returns
the number of bytes transferred if successful, 0 on timeout, -1 for error.

Definition at line 199 of file qio.c.

◆ qio_gets()

ssize_t qio_gets ( int  fd,
char *  buf,
size_t  bufsize,
int  timeoutms 
)

Read a line from a file descriptor into the buffer pointed to until either a terminating newline or EOF.

New-line characters(CR, LF ) will not be stored into buffer.

Parameters
fdfile descriptor
bufdata buffer pointer
bufsizebuffer size
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
Returns
the number of bytes read if successful, 0 on timeout, -1 for error.
Note
Be sure the return value does not mean the length of actual stored data. It means how many bytes are readed from the file descriptor, so the new-line characters will be counted, but not be stored.

Definition at line 257 of file qio.c.

◆ qio_puts()

ssize_t qio_puts ( int  fd,
const char *  str,
int  timeoutms 
)

Writes the string and a trailing newline to file descriptor.

Parameters
fdfile descriptor
strstring pointer
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
Returns
the number of bytes written including trailing newline characters if successful, 0 for timeout and -1 for errors.

Definition at line 301 of file qio.c.

◆ qio_printf()

ssize_t qio_printf ( int  fd,
int  timeoutms,
const char *  format,
  ... 
)

Formatted output to a file descriptor.

Parameters
fdfile descriptor
timeoutmswait timeout milliseconds. 0 for no wait, -1 for infinite wait
formatformat string
Returns
the number of bytes written including trailing newline characters if successful, 0 for timeout and -1 for errors.

Definition at line 325 of file qio.c.