PtAppAddFd(), PtAppAddFdPri()

Install a file-descriptor function

Synopsis:

int PtAppAddFd( PtAppContext_t app,
                int fd,
                unsigned mode,
                PtFdProc_t fun,
                void *data);

int PtAppAddFdPri( PtAppContext_t app,
                int fd,
                unsigned mode,
                PtFdProc_t fun,
                void *data,
                int priority);

Arguments:

app
The address of the application context, a structure that manages all the data associated with this application. This must be specified as NULL , so that the default context is used.
fd
The file descriptor to attach an FD handler to.
mode
Defines what kind of conditions the application is interested in:
Pt_FD_READ
Data available for reading.
Pt_FD_WRITE
Buffer space available for writing.
Pt_FD_OBAND
Out-of-band data available.

These values correspond to conditions defined for the ionotify() or select() functions. You can OR two or all three values together. You can change the mode later by calling PtAppSetFdMode().

fun
Defines the FD handler function to be called. This function is of type PtFdProc_t:
    typedef int PtFdProcF_t( int fd, void *data, unsigned mode );
    typedef PtFdProcF_t *PtFdProc_t;
    

The fd and data arguments have the same value as the fd and data arguments to PtAppAddFd(). The mode argument indicates which conditions were actually met.

The fun function should return Pt_CONTINUE to remain on the list of fd functions, or Pt_END to be removed automatically from it.

data
A pointer to data that you want to pass as the second argument to the FD handler function.
priority
PtAppAddFdPri() only.
Specifies the priority of the Photon pulse that's created (see PtAppCreatePulse()).

Library:

ph

Description:

These functions install an “FD function” that informs the application about device events.

If your application needs to perform I/O such as reading from or writing to a pipe, you should add an FD handler. An FD handler is a function that's called by the main event loop when a given file descriptor (FD) is ready for input or output.

Multiple FD functions attached to the same file descriptor aren't supported. PtAppAddFd() fails with errno set to EBUSY if you try to attach another function to the same FD.

Returns:

0
Success.
-1
An error occurred.

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PtAppCreatePulse(), PtAppRemoveFd(), PtAppSetFdMode(), PtFdProc_t

Other I/O mechanisms in the Interprocess Communication chapter of the Photon Programmer's Guide