priomethods.rst (3759B)
1 PRIOMethods 2 =========== 3 4 The table of I/O methods used in a file descriptor. 5 6 7 Syntax 8 ------ 9 10 .. code:: 11 12 #include <prio.h> 13 14 struct PRIOMethods { 15 PRDescType file_type; 16 PRCloseFN close; 17 PRReadFN read; 18 PRWriteFN write; 19 PRAvailableFN available; 20 PRAvailable64FN available64; 21 PRFsyncFN fsync; 22 PRSeekFN seek; 23 PRSeek64FN seek64; 24 PRFileInfoFN fileInfo; 25 PRFileInfo64FN fileInfo64; 26 PRWritevFN writev; 27 PRConnectFN connect; 28 PRAcceptFN accept; 29 PRBindFN bind; 30 PRListenFN listen; 31 PRShutdownFN shutdown; 32 PRRecvFN recv; 33 PRSendFN send; 34 PRRecvfromFN recvfrom; 35 PRSendtoFN sendto; 36 PRPollFN poll; 37 PRAcceptreadFN acceptread; 38 PRTransmitfileFN transmitfile; 39 PRGetsocknameFN getsockname; 40 PRGetpeernameFN getpeername; 41 PRGetsockoptFN getsockopt; 42 PRSetsockoptFN setsockopt; 43 }; 44 45 typedef struct PRIOMethods PRIOMethods; 46 47 48 Parameters 49 ~~~~~~~~~~ 50 51 ``file_type`` 52 Type of file represented (tos). 53 ``close`` 54 Close file and destroy descriptor. 55 ``read`` 56 Read up to the specified number of bytes into buffer. 57 ``write`` 58 Write specified number of bytes from buffer. 59 ``available`` 60 Determine number of bytes available for reading. 61 ``available64`` 62 Same as previous field, except 64-bit. 63 ``fsync`` 64 Flush all in-memory buffers of file to permanent store. 65 ``seek`` 66 Position the file pointer to the desired place. 67 ``seek64`` 68 Same as previous field, except 64-bit. 69 ``fileInfo`` 70 Get information about an open file. 71 ``fileInfo64`` 72 Same as previous field, except 64-bit. 73 ``writev`` 74 Write from a vector of buffers. 75 ``connect`` 76 Connect to the specified network address. 77 ``accept`` 78 Accept a connection from a network peer. 79 ``bind`` 80 Associate a network address with the file descriptor. 81 ``listen`` 82 Prepare to listen for network connections. 83 ``shutdown`` 84 Shut down a network connection. 85 ``recv`` 86 Receive up to the specified number of bytes. 87 ``send`` 88 Send all the bytes specified. 89 ``recvfrom`` 90 Receive up to the specified number of bytes and report network 91 source. 92 ``sendto`` 93 Send bytes to specified network address. 94 ``poll`` 95 Test the file descriptor to see if it is ready for I/O. 96 ``acceptread`` 97 Accept and read from a new network file descriptor. 98 ``transmitfile`` 99 Transmit an entire file to the specified socket. 100 ``getsockname`` 101 Get network address associated with a file descriptor. 102 ``getpeername`` 103 Get peer's network address. 104 ``getsockopt`` 105 Get current setting of specified socket option. 106 ``setsockopt`` 107 Set value of specified socket option. 108 109 110 Description 111 ----------- 112 113 You don't need to know the type declaration for each function listed in 114 the method table unless you are implementing a layer. For information 115 about each function, see the corresponding function description in this 116 document. For example, the ``write`` method in :ref:`PRIOMethods` 117 implements the :ref:`PR_Write` function. For type definition details, see 118 ``prio.h``. 119 120 The I/O methods table provides procedural access to the functions of the 121 file descriptor. It is the responsibility of a layer implementer to 122 provide suitable functions at every entry point (that is, for every 123 function in the I/O methods table). If a layer provides no 124 functionality, it should call the next lower (higher) function of the 125 same name (for example, the "close" method would return 126 ``fd->lower->method->close(fd->lower)``). 127 128 Not all functions in the methods table are implemented for all types of 129 files. For example, the seek method is implemented for normal files but 130 not for sockets. In cases where this partial implementation occurs, the 131 function returns an error indication with an error code of 132 ``PR_INVALID_METHOD_ERROR``.