Learn how to evaluate and integrate the VNC SDK

We're here if you need help.

EventLoopFd.h

Implement a custom file-descriptor-based event loop. (more...)

Data structures

Modifier and Type Name and Description
struct

vnc_EventLoopFd_Callback

Callback receiving notifications for a file-descriptor-based event loop.

Enums

Modifier and Type Name and Description
enum

vnc_EventLoopFd_Event

Enumeration of file descriptor events for event selection.

Functions

Modifier and Type Name and Description
function vnc_status_t

vnc_EventLoopFd_setCallback(const vnc_EventLoopFd_Callback *callback, void *userData)

Sets the event loop callback.

function vnc_status_t

vnc_EventLoopFd_markEvents(int fd, int events)

Marks event(s) that occurred on the specified file descriptor.

function int

vnc_EventLoopFd_handleEvents()

Handles events on the file descriptors and process expired timers.

Detailed description

Implement a custom file-descriptor-based event loop.

The following functions are used for integrating the VNC SDK into an existing file-descriptor-based event loop. This could either be an application’s event loop implemented directly using poll or select, or a third party event loop where the SDK’s file descriptors can be registered (for example using Qt’s QSocketNotifier).

The functions in this file are all only available on Linux, OS X, iOS, and Android, and an assertion is used to verify that vnc_init() was used to create a file-descriptor event loop.

See the basicViewerX11 sample for an example of how to integrate this into an existing application event loop using select.

To integrate into a third-party event loop (e.g. using a framework such as Qt), implement the vnc_EventLoopFd_Callback::eventUpdated and vnc_EventLoopFd_Callback::timerUpdated callbacks to create, update or destroy the appropriate notifiers for the framework. On receiving notifications, call vnc_EventLoopFd_markEvents() (in the case of an fd event) and then call vnc_EventLoopFd_handleEvents().

Enums

enum vnc_EventLoopFd_Event

Enumeration of file descriptor events for event selection.

Values:

vnc_EventLoopFd_Read = 0x01

Monitor using readfds with select() (the second argument), or POLLIN with poll().

vnc_EventLoopFd_Write = 0x02

Monitor using writefds with select() (the third argument), or POLLOUT with poll().

vnc_EventLoopFd_Except = 0x04

Monitor using exceptfds with select() (the fourth argument), or POLLPRI with poll().

Functions

vnc_status_t vnc_EventLoopFd_setCallback(const vnc_EventLoopFd_Callback *callback, void *userData)

Sets the event loop callback.

Return
vnc_success or vnc_failure, in which case call vnc_getLastError() to get the error code.
Parameters
  • callback -

    The new event loop callback.

Return Value

vnc_status_t vnc_EventLoopFd_markEvents(int fd, int events)

Marks event(s) that occurred on the specified file descriptor.

Return
vnc_success or vnc_failure, in which case call vnc_getLastError() to get the error code.
Parameters
  • fd -

    The file descriptor.

  • events -

    A mask of events to be marked for handling.

Return Value
  • InvalidArgument -

    fd is not recognized by the SDK

int vnc_EventLoopFd_handleEvents(void)

Handles events on the file descriptors and process expired timers.

Return
The number of milliseconds until the next timer expires

struct vnc_EventLoopFd_Callback
#include <EventLoopFd.h>

Callback receiving notifications for a file-descriptor-based event loop.

See
vnc_EventLoopFd_setCallback()

Public Members

void(* vnc_EventLoopFd_Callback::eventUpdated) (void *userData, int fd, int eventMask)

Notification that a file descriptor’s event mask has changed.

This callback is required.

Parameters
  • fd -

    The file descriptor whose event mask has changed.

  • eventMask -

    Specifies the events we are interested in for this descriptor. When one of the specified events occurs, the implementation should call vnc_EventLoopFd_markEvents() to mark which event(s) occurred, then call vnc_EventLoopFd_handleEvents(). An eventMask of 0 indicates the SDK is no longer using this file descriptor; it should be removed immediately from the monitored set of descriptors.

void(* vnc_EventLoopFd_Callback::timerUpdated) (void *userData, int expiryMs)

Notification that the timer expiry period has been updated.

When the specified expiry time has passed, the implementation should call vnc_EventLoopFd_handleEvents().

This callback is optional, and is only needed if integrating with a third-party event loop rather than calling vnc_EventLoopFd_handleEvents() directly to a create a custom blocking event loop.

Parameters

×