dect
/
libdect
Archived
13
0
Fork 0

utils: add fd initialization helper

Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Patrick McHardy 2009-05-23 00:53:28 +02:00
parent a28db0bc1a
commit e795362c37
5 changed files with 21 additions and 13 deletions

View File

@ -15,6 +15,9 @@
#define __aligned(x) __attribute__((aligned(x)))
#define __packed __attribute__((packed))
extern void dect_debug(const char *fmt, ...) __fmtstring(1, 2);
extern void dect_hexdump(const char *prefix, const uint8_t *buf, size_t size);
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);
@ -27,12 +30,12 @@ extern void dect_start_timer(const struct dect_handle *dh,
struct dect_timer *timer, unsigned int timeout);
extern void dect_stop_timer(const struct dect_handle *dh, struct dect_timer *timer);
struct dect_fd *dect_alloc_fd(const struct dect_handle *dh);
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 void dect_debug(const char *fmt, ...) __fmtstring(1, 2);
extern void dect_hexdump(const char *prefix, const uint8_t *buf, size_t size);
#include <sys/socket.h> // FIXME: socklen_t
extern struct dect_fd *dect_socket(const struct dect_handle *dh,
int type, int protocol);

View File

@ -339,8 +339,7 @@ static int dect_call_connect_uplane(const struct dect_handle *dh,
if (connect(call->lu_sap->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
goto err2;
call->lu_sap->data = call;
call->lu_sap->callback = dect_cc_lu_event;
dect_setup_fd(call->lu_sap, dect_cc_lu_event, call);
if (dect_register_fd(dh, call->lu_sap, DECT_FD_READ) < 0)
goto err2;
cc_debug(call, "U-Plane connected");

View File

@ -453,8 +453,7 @@ static struct dect_data_link *dect_ddl_establish(struct dect_handle *dh,
ddl->dlei.dect_lln = 1;
ddl->dlei.dect_sapi = 0;
ddl->dfd->callback = dect_lce_data_link_event;
ddl->dfd->data = ddl;
dect_setup_fd(ddl->dfd, dect_lce_data_link_event, ddl);
if (dect_register_fd(dh, ddl->dfd, DECT_FD_WRITE) < 0)
goto err2;
@ -787,8 +786,7 @@ static void dect_lce_ssap_listener_event(struct dect_handle *dh,
goto err2;
ddl->dfd = nfd;
nfd->callback = dect_lce_data_link_event;
nfd->data = ddl;
dect_setup_fd(nfd, dect_lce_data_link_event, ddl);
if (dect_register_fd(dh, nfd, DECT_FD_READ) < 0)
goto err3;
@ -827,7 +825,7 @@ int dect_lce_init(struct dect_handle *dh)
if (bind(dh->b_sap->fd, (struct sockaddr *)&b_addr, sizeof(b_addr)) < 0)
goto err2;
dh->b_sap->callback = dect_lce_bsap_event;
dect_setup_fd(dh->b_sap, dect_lce_bsap_event, NULL);
if (dect_register_fd(dh, dh->b_sap, DECT_FD_READ) < 0)
goto err2;
@ -846,7 +844,7 @@ int dect_lce_init(struct dect_handle *dh)
if (listen(dh->s_sap->fd, 10) < 0)
goto err4;
dh->s_sap->callback = dect_lce_ssap_listener_event;
dect_setup_fd(dh->s_sap, dect_lce_ssap_listener_event, NULL);
if (dect_register_fd(dh, dh->s_sap, DECT_FD_READ) < 0)
goto err4;

View File

@ -103,7 +103,7 @@ int dect_netlink_init(struct dect_handle *dh)
goto err2;
dh->nlfd->fd = nl_socket_get_fd(dh->nlsock);
dh->nlfd->callback = dect_netlink_event;
dect_setup_fd(dh->nlfd, dect_netlink_event, NULL);
if (dect_register_fd(dh, dh->nlfd, DECT_FD_READ))
goto err3;

View File

@ -87,6 +87,14 @@ struct dect_fd *dect_alloc_fd(const struct dect_handle *dh)
return dfd;
}
void dect_setup_fd(struct dect_fd *fd,
void (*cb)(struct dect_handle *, struct dect_fd *, uint32_t),
void *data)
{
fd->callback = cb;
fd->data = data;
}
int dect_register_fd(const struct dect_handle *dh, struct dect_fd *dfd,
uint32_t events)
{