summaryrefslogtreecommitdiffstats
path: root/inc/dnbd3/shared/fdsignal.h
blob: 960a2a96e92ee3739d71b664c25a780fb4ce102a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _FD_SIGNAL_H_
#define _FD_SIGNAL_H_

#define SIGNAL_OK (0)
#define SIGNAL_TIMEOUT (-2)
#define SIGNAL_ERROR (-1)

typedef struct _dnbd3_signal dnbd3_signal_t;

/**
 * Create a new signal, nonblocking.
 * @return NULL on error, pointer to dnbd3_signal_t on success.
 */
dnbd3_signal_t* signal_new();

/**
 * Create a new signal, blocking.
 * @return NULL on error, pointer to dnbd3_signal_t on success.
 */
dnbd3_signal_t* signal_newBlocking();

/**
 * Trigger the given signal, so a wait or clear call will succeed.
 * @return SIGNAL_OK on success, SIGNAL_ERROR on error
 */
int signal_call(const dnbd3_signal_t* const signal);

/**
 * Wait for given signal, with an optional timeout.
 * If timeout == 0, just poll once.
 * If timeout < 0, wait forever.
 * @return > 0 telling how many times the signal was called,
 *    SIGNAL_TIMEOUT if the timeout was reached,
 *    SIGNAL_ERROR if some error occured
 */
int signal_wait(const dnbd3_signal_t* const signal, int timeoutMs);

/**
 * Clears any pending signals on this signal.
 * @return number of signals that were pending,
 *    SIGNAL_ERROR if some error occured
 */
int signal_clear(const dnbd3_signal_t* const signal);

/**
 * Close the given signal.
 */
void signal_close(const dnbd3_signal_t* const signal);

/**
 * Get a file descriptor for the given signal that can be
 * waited on using poll or similar.
 * @return -1 if the signal is invalid
 */
int signal_getWaitFd(const dnbd3_signal_t* const signal);

#endif