avahi  0.7
simple-watch.h File Reference

Simple poll() based main loop implementation. More...

#include <poll.h>
#include <avahi-common/cdecl.h>
#include <avahi-common/watch.h>

Go to the source code of this file.

Typedefs

typedef struct AvahiSimplePoll AvahiSimplePoll
 A main loop object. More...
 
typedef int(* AvahiPollFunc) (struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata)
 Prototype for a poll() type function. More...
 

Functions

AvahiSimplePollavahi_simple_poll_new (void)
 Create a new main loop object. More...
 
void avahi_simple_poll_free (AvahiSimplePoll *s)
 Free a main loop object. More...
 
const AvahiPollavahi_simple_poll_get (AvahiSimplePoll *s)
 Return the abstracted poll API object for this main loop object. More...
 
int avahi_simple_poll_iterate (AvahiSimplePoll *s, int sleep_time)
 Run a single main loop iteration of this main loop. More...
 
void avahi_simple_poll_quit (AvahiSimplePoll *s)
 Request that the main loop quits. More...
 
void avahi_simple_poll_set_func (AvahiSimplePoll *s, AvahiPollFunc func, void *userdata)
 Replace the internally used poll() function. More...
 
int avahi_simple_poll_prepare (AvahiSimplePoll *s, int timeout)
 The first stage of avahi_simple_poll_iterate(), use this function only if you know what you do. More...
 
int avahi_simple_poll_run (AvahiSimplePoll *s)
 The second stage of avahi_simple_poll_iterate(), use this function only if you know what you do. More...
 
int avahi_simple_poll_dispatch (AvahiSimplePoll *s)
 The third and final stage of avahi_simple_poll_iterate(), use this function only if you know what you do. More...
 
int avahi_simple_poll_loop (AvahiSimplePoll *s)
 Call avahi_simple_poll_iterate() in a loop and return if it returns non-zero. More...
 
void avahi_simple_poll_wakeup (AvahiSimplePoll *s)
 Wakeup the main loop. More...
 

Detailed Description

Simple poll() based main loop implementation.

Definition in file simple-watch.h.

Typedef Documentation

◆ AvahiPollFunc

typedef int(* AvahiPollFunc) (struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata)

Prototype for a poll() type function.

Definition at line 63 of file simple-watch.h.

◆ AvahiSimplePoll

A main loop object.

Main loops of this type aren't very flexible since they only support a single wakeup type. Nevertheless it should suffice for small test and example applications.

Definition at line 34 of file simple-watch.h.

Function Documentation

◆ avahi_simple_poll_dispatch()

int avahi_simple_poll_dispatch ( AvahiSimplePoll s)

The third and final stage of avahi_simple_poll_iterate(), use this function only if you know what you do.

◆ avahi_simple_poll_free()

void avahi_simple_poll_free ( AvahiSimplePoll s)

Free a main loop object.

Examples:
client-browse-services.c, and client-publish-service.c.

◆ avahi_simple_poll_get()

const AvahiPoll* avahi_simple_poll_get ( AvahiSimplePoll s)

Return the abstracted poll API object for this main loop object.

The is will return the same pointer each time it is called.

Examples:
client-browse-services.c, and client-publish-service.c.

◆ avahi_simple_poll_iterate()

int avahi_simple_poll_iterate ( AvahiSimplePoll s,
int  sleep_time 
)

Run a single main loop iteration of this main loop.

If sleep_time is < 0 this will block until any of the registered events happens, then it will execute the attached callback function. If sleep_time is 0 the routine just checks if any event is pending. If yes the attached callback function is called, otherwise the function returns immediately. If sleep_time > 0 the function will block for at most the specified time in msecs. Returns -1 on error, 0 on success and 1 if a quit request has been scheduled. Usually this function should be called in a loop until it returns a non-zero value

◆ avahi_simple_poll_loop()

int avahi_simple_poll_loop ( AvahiSimplePoll s)

Call avahi_simple_poll_iterate() in a loop and return if it returns non-zero.

Examples:
client-browse-services.c, and client-publish-service.c.

◆ avahi_simple_poll_new()

AvahiSimplePoll* avahi_simple_poll_new ( void  )

Create a new main loop object.

Examples:
client-browse-services.c, and client-publish-service.c.

◆ avahi_simple_poll_prepare()

int avahi_simple_poll_prepare ( AvahiSimplePoll s,
int  timeout 
)

The first stage of avahi_simple_poll_iterate(), use this function only if you know what you do.

◆ avahi_simple_poll_quit()

void avahi_simple_poll_quit ( AvahiSimplePoll s)

Request that the main loop quits.

If this is called the next call to avahi_simple_poll_iterate() will return 1

Examples:
client-browse-services.c, and client-publish-service.c.

◆ avahi_simple_poll_run()

int avahi_simple_poll_run ( AvahiSimplePoll s)

The second stage of avahi_simple_poll_iterate(), use this function only if you know what you do.

◆ avahi_simple_poll_set_func()

void avahi_simple_poll_set_func ( AvahiSimplePoll s,
AvahiPollFunc  func,
void *  userdata 
)

Replace the internally used poll() function.

By default the system's poll() will be used

◆ avahi_simple_poll_wakeup()

void avahi_simple_poll_wakeup ( AvahiSimplePoll s)

Wakeup the main loop.

(for threaded environments)