#include <sys/ioctl.h> #include <net/nit_buf.h> ioctl(fd, I_PUSH, "nbuf");
nit_buf is a STREAMS module that buffers incoming messages, thereby reducing the number of system calls and associated overhead required to read and process them. Although designed to be used in conjunction with the other components of NIT (see nit.4p nit_buf is a general-purpose module and can be used anywhere STREAMS input buffering is required.
Upon receiving a message from below, nit_buf immediately converts all leading M_PROTO blocks in the message to M_DATA blocks, altering only the message type field and leaving the contents alone. It then prepends a header to the converted message. This header is defined as follows.
struct nit_bufhdr { u_int nhb_msglen; u_int nhb_totlen; };
After preparing a message, nit_buf attempts to add it to the end of the current chunk, using the chunk size and timeout values to govern the addition. (The chunk size and timeout values are set and inspected using the ioctl calls described below.) If adding the new message would make the current chunk grow larger than the chunk size, nit_buf closes off the current chunk, passing it up to the next module in line, and starts a new chunk, seeding it with a zero-length message. If adding the message would still make the current chunk overflow, the module passes it upward in an over-size chunk of its own. Otherwise, the module concatenates the message to the end of the current chunk.
To ensure that messages do not languish forever in an accumulating chunk, nit_buf maintains a read timeout. Whenever this timeout expires, the module closes off the current chunk, regardless of its length, and passes it upward; if no incoming messages have arrived, the chunk passed upward will have zero length. Whenever the module passes a chunk upward, it restarts the timeout period. These two rules insure that nit_buf minimizes the number of chunks it produces during periods of intense message activity and that it periodically disposes of all messages during slack intervals.
nit_buf handles other message types as follows. Upon receiving an M_FLUSH message specifying that the read queue be flushed, the module does so, clearing the currently accumulating chunk as well, and passes the message on to the module or driver above. It passes all other messages through unaltered to its upper neighbor.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97