libdect: make struct dect_fd opaque
Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
parent
1a946cf3e0
commit
d7581ae5e0
|
@ -20,7 +20,7 @@ static void event_callback(int fd, short mask, void *data)
|
|||
if (mask & EV_WRITE)
|
||||
events |= DECT_FD_WRITE;
|
||||
|
||||
dfd->callback(dh, dfd, events);
|
||||
dect_handle_fd(dh, dfd, events);
|
||||
}
|
||||
|
||||
static int register_fd(const struct dect_handle *dh, struct dect_fd *dfd,
|
||||
|
|
|
@ -72,21 +72,10 @@ enum dect_fd_events {
|
|||
DECT_FD_WRITE = 0x2
|
||||
};
|
||||
|
||||
/**
|
||||
* struct dect_fd - libdect file descriptor
|
||||
*
|
||||
* @callback: callback to invoke for events
|
||||
* @fd: file descriptor numer
|
||||
* @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;
|
||||
void *data;
|
||||
uint8_t priv[];
|
||||
};
|
||||
struct dect_fd;
|
||||
extern void *dect_fd_priv(struct dect_fd *dfd);
|
||||
extern void dect_handle_fd(struct dect_handle *dh, struct dect_fd *dfd,
|
||||
uint32_t events);
|
||||
|
||||
struct dect_timer;
|
||||
extern void *dect_timer_priv(struct dect_timer *timer);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef _LIBDECT_FILE_H
|
||||
#define _LIBDECT_FILE_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
/**
|
||||
* struct dect_fd - libdect file descriptor
|
||||
*
|
||||
* @callback: callback to invoke for events
|
||||
* @fd: file descriptor numer
|
||||
* @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;
|
||||
void *data;
|
||||
uint8_t priv[];
|
||||
};
|
||||
|
||||
extern struct dect_fd *dect_alloc_fd(const struct dect_handle *dh);
|
||||
extern void dect_setup_fd(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_register_fd(const struct dect_handle *dh, struct dect_fd *dfd,
|
||||
uint32_t events);
|
||||
extern void dect_unregister_fd(const struct dect_handle *dh, struct dect_fd *dfd);
|
||||
|
||||
#endif /* _LIBDECT_FILE_H */
|
|
@ -7,6 +7,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <timer.h>
|
||||
#include <file.h>
|
||||
|
||||
#ifndef AF_DECT
|
||||
#define AF_DECT 38
|
||||
|
@ -59,24 +60,6 @@ struct dect_handle;
|
|||
extern void *dect_malloc(const struct dect_handle *dh, size_t size);
|
||||
extern void *dect_zalloc(const struct dect_handle *dh, size_t size);
|
||||
extern void dect_free(const struct dect_handle *dh, void *ptr);
|
||||
|
||||
extern struct dect_fd *dect_alloc_fd(const struct dect_handle *dh);
|
||||
extern void dect_setup_fd(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);
|
||||
|
||||
#include <sys/socket.h> // FIXME: socklen_t
|
||||
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_register_fd(const struct dect_handle *dh, struct dect_fd *dfd,
|
||||
uint32_t events);
|
||||
extern void dect_unregister_fd(const struct dect_handle *dh, struct dect_fd *dfd);
|
||||
|
||||
#define EXPORT_SYMBOL(x) typeof(x) (x) __visible
|
||||
#define BUG() assert(0)
|
||||
|
||||
|
|
12
src/utils.c
12
src/utils.c
|
@ -129,6 +129,12 @@ struct dect_fd *dect_alloc_fd(const struct dect_handle *dh)
|
|||
}
|
||||
EXPORT_SYMBOL(dect_alloc_fd);
|
||||
|
||||
void *dect_fd_priv(struct dect_fd *fd)
|
||||
{
|
||||
return fd->priv;
|
||||
}
|
||||
EXPORT_SYMBOL(dect_fd_priv);
|
||||
|
||||
void dect_setup_fd(struct dect_fd *fd,
|
||||
void (*cb)(struct dect_handle *, struct dect_fd *, uint32_t),
|
||||
void *data)
|
||||
|
@ -151,6 +157,12 @@ void dect_unregister_fd(const struct dect_handle *dh, struct dect_fd *dfd)
|
|||
}
|
||||
EXPORT_SYMBOL(dect_unregister_fd);
|
||||
|
||||
void dect_handle_fd(struct dect_handle *dh, struct dect_fd *dfd, uint32_t events)
|
||||
{
|
||||
dfd->callback(dh, dfd, events);
|
||||
}
|
||||
EXPORT_SYMBOL(dect_handle_fd);
|
||||
|
||||
void dect_close(const struct dect_handle *dh, struct dect_fd *dfd)
|
||||
{
|
||||
if (dfd->fd >= 0)
|
||||
|
|
Reference in New Issue