NetHack Proxy Reference Manual |
---|
Packet I/OPacket I/O — Reading and writing data with higher-level information on packet sizes |
#include <nhproxy/nhproxy.h> int (*nhproxy_io_func) (nhproxy_genericptr_t handle, nhproxy_genericptr_t buf, unsigned int len); #define NHPROXY_IO_RDONLY #define NHPROXY_IO_WRONLY #define NHPROXY_IO_NBLOCK #define NHPROXY_IO_NOAUTOFILL #define NHPROXY_IO_LINEBUF #define NHPROXY_IO_SIMPLEBUFFER #define NHPROXY_IO_PENDING NhProxyIO* nhproxy_io_open (nhproxy_io_func func, nhproxy_genericptr_t handle, unsigned int flags); nhproxy_bool_t nhproxy_io_close (NhProxyIO *io); unsigned int nhproxy_io_getmode (NhProxyIO *io); void nhproxy_io_setmode (NhProxyIO *io, unsigned int flags); void nhproxy_io_setautofill_limit (NhProxyIO *io, unsigned int limit); void nhproxy_io_setnbfunc (NhProxyIO *io, nhproxy_io_func func); int nhproxy_io_filbuf (NhProxyIO *io, nhproxy_bool_t blocking); int nhproxy_io_getc (NhProxyIO *io); int nhproxy_io_read (NhProxyIO *io, char *buf, int nb); int nhproxy_io_fread (nhproxy_genericptr_t buffer, int size, int nmemb, NhProxyIO *io); char* nhproxy_io_getpacket (NhProxyIO *io, int *nb); int nhproxy_io_willblock (NhProxyIO *io); nhproxy_bool_t nhproxy_io_flush (NhProxyIO *io); int nhproxy_io_fputc (int c, NhProxyIO *io); int nhproxy_io_write (NhProxyIO *io, char *buf, int nb); int nhproxy_io_writet (NhProxyIO *io, char *buf, int nb); int nhproxy_io_vprintf (NhProxyIO *io, char *fmt, va_list ap); int nhproxy_io_printf (NhProxyIO *io, char *fmt, ...);
int (*nhproxy_io_func) (nhproxy_genericptr_t handle, nhproxy_genericptr_t buf, unsigned int len);
handle : | |
buf : | |
len : | |
Returns : |
NhProxyIO* nhproxy_io_open (nhproxy_io_func func, nhproxy_genericptr_t handle, unsigned int flags);
func : | |
handle : | |
flags : | |
Returns : |
void nhproxy_io_setautofill_limit (NhProxyIO *io, unsigned int limit);
io : | |
limit : |
int nhproxy_io_filbuf (NhProxyIO *io, nhproxy_bool_t blocking);
io : | The stream to act on. |
blocking : | True if nhproxy_io_fulbuf() should wait for input before returning. |
Returns : | >0 if buffer now non-empty, else 0 on EOF, -1 on error, or -2 on would block |
int nhproxy_io_read (NhProxyIO *io, char *buf, int nb);
reads between 1 and nb bytes from the stream. A read will only be requested on the underlying I/O system if there would otherwise be no bytes to return to the caller (and not even then if NHPROXY_IO_NOAUTOFILL is set). This prevents blocking but means that using nhproxy_io_read() to read fixed sized datums is not useful. For example,
nhproxy_io_read(io, &datum, sizeof(datum));
may easily only partially read datum even though the rest of datum is available for reading. Where the caller knows in advance that an infinite block will not occur when reading, nhproxy_io_fread() should be used instead:
nhproxy_io_fread(&datum, sizeof(datum), 1, io);
io : | The stream to act on. |
buf : | The buffer to write to. |
nb : | The maximum number of bytes to read. |
Returns : | The number of bytes read or -1 on error. |
int nhproxy_io_fread (nhproxy_genericptr_t buffer, int size, int nmemb, NhProxyIO *io);
reads up to nmemb members of the given size and returns the number read. Where fewer members were read than requested then an EOF or ERROR has occured. Any partially read member will still be available for reading after nhproxy_io_fread() returns.
buffer : | The buffer to read into. |
size : | The size of each member. |
nmemb : | The number of members to read. |
io : | The stream to act on. |
Returns : | The number of members read or a negative value if the member size is too large. |
char* nhproxy_io_getpacket (NhProxyIO *io, int *nb);
gets the last packet read under certain circumstances. This will always work if the caller sets no-autofill mode and calls nhproxy_io_fillbuf() on an empty buffer. Calls to nhproxy_io_fread() must also be avoided since this can cause simple buffer mode to be cancelled (nhproxy_io_fread() could be re-written to avoid this if it became important).
io : | The stream to act on. |
nb : | The address of an integer in which to write the number of bytes read. |
Returns : | The packet read or NULL on error. |
int nhproxy_io_write (NhProxyIO *io, char *buf, int nb);
io : | |
buf : | |
nb : | |
Returns : |
int nhproxy_io_writet (NhProxyIO *io, char *buf, int nb);
io : | |
buf : | |
nb : | |
Returns : |
int nhproxy_io_vprintf (NhProxyIO *io, char *fmt, va_list ap);
io : | |
fmt : | |
ap : | |
Returns : |
<< External Data Representation | Non-blocking I/O >> |