P_net_read, P_net_write, P_net_printf 3porty 2011-05-09 libporty manual

NAME

P_net_read, P_net_write, P_net_printf

SYNPOSIS

#include <libporty/net/network.h>

P_size_t P_net_read (P_net_socket sock , void * buf , P_size_t count );
P_size_t P_net_write (P_net_socket sock , void * buf , P_size_t count );
extern int P_net_printf_minbuff, P_net_printf_maxbuff;
P_size_t P_net_printf (P_net_socket sock , const char * format , ...);

Link with -lporty_net

DESCRIPTION

Read or write a socket. There is no guarantee for reading/writing all count bytes in a single call. P_net_printf may be slow on platforms not supporting dprintf(). Before using P_net_printf, the user shall always set up P_net_printf_minbuff, P_net_printf_maxbuff. The former should contain the average length of messages printed with P_net_printf, the latter should contain the largest message. Writing more than P_net_printf_maxbuff bytes in a single call may cause an abort().

RETURN VALUE

Return number of bytes read or written or -1 on error.

NOTES

On platforms supporting vdprintf, P_net_printf will use that directly, ignoring all buffer size hints. Most of the other systems still support vsnprintf; in that case each call a buffer of P_net_printf_minbuff is allocated and is doubled until printing all arguments using vsnprintf succeeded or if maxbuff is reached. If maxbuff is still not large enough, -1 is returned. This may be slow if maxbuff> minbuff. Finally, on platforms without support for any of the above, a maxbuff large buffer is allocated, sprintf is called on the arguments and return value is checked: if it printed more than maxbuff, it is a buffer overflow and P_net_print aborts.

P_net_read, P_net_write, P_net_printf 3porty 2011-05-09 libporty manual