dect
/
libdect
Archived
13
0
Fork 0

libdect: make struct dect_fd opaque

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2010-07-03 09:30:09 +02:00
parent 1a946cf3e0
commit d7581ae5e0
5 changed files with 57 additions and 34 deletions

View File

@ -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,

View File

@ -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);

39
include/file.h Normal file
View File

@ -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 */

View File

@ -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)

View File

@ -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)