![]() |
![]() |
![]() |
Associate an OCB with an open request
#include <sys/resmgr.h> int resmgr_open_bind( resmgr_context_t* ctp, void* ocb, const resmgr_io_funcs_t* iofuncs );
libc
The resmgr_open_bind() function is the lowest-level call in the resource manager library used for handling open messages. It associates the Open Control Block (OCB) with a process identified by the id and info members of ctp. This function must be used as part of the handling of an _IO_OPEN message. In practice, you don't call this function directly; you typically use either iofunc_open_default() or iofunc_ocb_attach() (the first calls the second, and the second calls resmgr_open_bind()).
An internal data structure is allocated that maintains the number of links to the OCB. On a file descriptor dup(), the link count is incremented and on a close() it's decremented. When the count reaches zero, the close_ocb() callout specified in io_funcs is called.
In the most general case, the OCB is an arbitrary structure that you define and can hold information describing an open file, or just a simple int to hold the open mode for checking in the read() and write() callouts.
In the typical case, however, the OCB is a structure that contains at least the members as defined by the typedef iofunc_ocb_t. This typedef defines a common OCB structure that can then be used by the POSIX layer helper functions (all functions beginning with the name iofunc_*). The advantage of this approach is that your resource manager gets POSIX behavior for free, without any additional work on your part.
The attr argument to the open() callout is also typically saved in the OCB. The well defined iofunc_ocb_t has a member called attr which must be assigned the value of the attr argument. This allows the POSIX helper functions to access information about the current open session (as stored in the OCB) as well as information about the device itself (as stored in the attributes structure, ocb -> attr).
For a detailed discussion, including several examples, see the Writing a Resource Manager chapter of the Programmer's Guide.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
iofunc_ocb_attach(), iofunc_open_default()
![]() |
![]() |
![]() |