Read limits

A read limits is a similar mechanism that causes pubread() to throw an exception as soon as a predetermined number of bytes gets read from the underlying file descriptor.

#include <x/fdreadlimit.H>

x::fdreadlimit fd_with_readlimit(fdreadlimit::create(fd));

fd_with_readlimit->set_read_limit(1000000);

This example sets a counter. x::fdreadlimit's pubread() throws an exception after 1000000 bytes are counted while reading from the file descriptor. cancel_read_limit() removes the previously set read limit.

A read limit is a mechanism to place an automatic upper limit on amount of data received from an external source. Both a read limit, and a read timeout, can be installed at the same time:


	  x::fdtimeout fd_with_timeout(x::fdtimeout::create(fd));
	  x::fdreadlimit fd_with_readlimit(fdreadlimit::create(fd_with_timeout));

	  fd_with_timeout->set_read_timeout(60)
	  fd_with_readlimit->set_read_limit(1000000);

	  x::istream i(fd_with_readlimit->getistream());
	

This example attaches an x::fdtimeout to the file descriptor object, then attaches a x::fdreadlimit to the timeout object. Both x::fdtimeout's and x::fdreadlimit's create() take the x::fdbase file descriptor transport superclass, and each class implements the interface.

Note

Only one timeout and a read limit object can be attached to an underlying file descriptor object, but this can be done in either order.

Reading and writing, in the above example from fd_with_readlimit implements the functionality of both the read limit and the timeout object.

Note

Only the behavior of pubread() is affected by a read limit. Other methods are not affected, and are passed through to the underlying object.

Exceeding the read limit throws a EOVERFLOW x::sysexception.