summaryrefslogtreecommitdiffstats
path: root/include/io.h
blob: ff3f60cace7c8d2c6a4e142daaf0667fa5c217c2 (plain)
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
/*
 * libdect IO handling
 *
 * Copyright (c) 2009-2010 Patrick McHardy <kaber@trash.net>
 */

#ifndef _LIBDECT_IO_H
#define _LIBDECT_IO_H

#include <sys/socket.h>
#include <utils.h>

enum dect_fd_state {
	DECT_FD_UNREGISTERED,
	DECT_FD_REGISTERED,
};

/**
 * struct dect_fd - libdect file descriptor
 *
 * @callback:		callback to invoke for events
 * @fd:			file descriptor numer
 * @state:		file descriptor registration state (debugging)
 * @data:		libdect internal data
 * @priv:		libdect user private file-descriptor storage
 */
struct dect_fd {
	void			(*callback)(struct dect_handle *,
					    struct dect_fd *, uint32_t);
	int			fd;
	enum dect_fd_state	state;
	void			*data;
	uint8_t			priv[] __aligned(__alignof__(uint64_t));
};

extern struct dect_fd *dect_fd_alloc(const struct dect_handle *dh);
extern void dect_fd_setup(struct dect_fd *fd,
			  void (*cb)(struct dect_handle *, struct dect_fd *,
				     uint32_t),
			  void *data);
extern void dect_close(const struct dect_handle *dh, struct dect_fd *dfd);

extern struct dect_fd *dect_socket(const struct dect_handle *dh,
				   int type, int protocol);
extern struct dect_fd *dect_accept(const struct dect_handle *dh,
				   const struct dect_fd *dfd,
				   struct sockaddr *addr, socklen_t len);

extern int dect_fd_register(const struct dect_handle *dh, struct dect_fd *dfd,
			    uint32_t events);
extern void dect_fd_unregister(const struct dect_handle *dh, struct dect_fd *dfd);

#endif /* _LIBDECT_IO_H */