My final commit

This commit is contained in:
XANTRONIX Development 2015-08-12 21:45:23 -05:00 committed by XANTRONIX Industrial
parent a2b21eb848
commit 4e5634cbc7
3 changed files with 29 additions and 15 deletions

View file

@ -60,8 +60,7 @@ typedef struct _patty_ax25_sock {
typedef struct _patty_ax25_event { typedef struct _patty_ax25_event {
enum patty_ax25_event_type type; enum patty_ax25_event_type type;
patty_ax25_sock * sock;
int fd;
} patty_ax25_event; } patty_ax25_event;
struct _patty_ax25 { struct _patty_ax25 {
@ -70,11 +69,12 @@ struct _patty_ax25 {
int unix_fdmax; int unix_fdmax;
fd_set unix_fds; fd_set unix_fds;
fd_set unix_fds_pending_read; fd_set unix_fds_pending_read;
fd_set unix_fds_pending_write; fd_set unix_fds_pending_write;
fd_set unix_fds_pending_error; fd_set unix_fds_pending_error;
patty_dict * unix_fd_lookup;
patty_dict * fd_lookup; patty_dict * fd_lookup;
int fd; int fd;
int current; int current;

View file

@ -21,8 +21,15 @@ int patty_ax25_init(patty_ax25 *ax25) {
goto error_dict_new_fd_lookup; goto error_dict_new_fd_lookup;
} }
if ((ax25->unix_fd_lookup = patty_dict_new()) == NULL) {
goto error_dict_new_unix_fd_lookup;
}
return 0; return 0;
error_dict_new_unix_fd_lookup:
patty_dict_destroy(ax25->fd_lookup);
error_dict_new_fd_lookup: error_dict_new_fd_lookup:
patty_list_destroy(ax25->socks); patty_list_destroy(ax25->socks);
@ -40,6 +47,7 @@ static int destroy_if(patty_ax25_if *iface, void *ctx) {
} }
void patty_ax25_stop(patty_ax25 *ax25) { void patty_ax25_stop(patty_ax25 *ax25) {
patty_dict_destroy(ax25->unix_fd_lookup);
patty_dict_destroy(ax25->fd_lookup); patty_dict_destroy(ax25->fd_lookup);
patty_list_destroy(ax25->socks); patty_list_destroy(ax25->socks);
@ -188,7 +196,7 @@ error_fd_lookup:
return -1; return -1;
} }
int patty_ax25_next_event(patty_ax25 *ax25, patty_ax25_event *ev) { static int next_unix_fd_event(patty_ax25 *ax25, enum patty_ax25_event_type *type) {
int fd; int fd;
if (ax25->current == 0) { if (ax25->current == 0) {
@ -199,38 +207,34 @@ int patty_ax25_next_event(patty_ax25 *ax25, patty_ax25_event *ev) {
if (select(ax25->unix_fdmax, if (select(ax25->unix_fdmax,
&ax25->unix_fds_pending_read, &ax25->unix_fds_pending_read,
&ax25->unix_fds_pending_write, &ax25->unix_fds_pending_write,
&ax25->unix_fds_pending_error, &ax25->unix_fds_pending_error, NULL) < 0) {
NULL) < 0) {
goto error_select; goto error_select;
} }
} }
for (fd=ax25->current; fd<ax25->unix_fdmax; fd++) { for (fd=ax25->current; fd<ax25->unix_fdmax; fd++) {
if (FD_ISSET(fd, &ax25->unix_fds_pending_read)) { if (FD_ISSET(fd, &ax25->unix_fds_pending_read)) {
ev->type = PATTY_AX25_EVENT_RECV; *type = PATTY_AX25_EVENT_RECV;
ev->fd = fd;
FD_CLR(fd, &ax25->unix_fds_pending_read); FD_CLR(fd, &ax25->unix_fds_pending_read);
return 0; return fd;
} }
if (FD_ISSET(fd, &ax25->unix_fds_pending_write)) { if (FD_ISSET(fd, &ax25->unix_fds_pending_write)) {
ev->type = PATTY_AX25_EVENT_SEND; *type = PATTY_AX25_EVENT_SEND;
ev->fd = fd;
FD_CLR(fd, &ax25->unix_fds_pending_write); FD_CLR(fd, &ax25->unix_fds_pending_write);
return 0; return fd;
} }
if (FD_ISSET(fd, &ax25->unix_fds_pending_error)) { if (FD_ISSET(fd, &ax25->unix_fds_pending_error)) {
ev->type = PATTY_AX25_EVENT_ERROR; *type = PATTY_AX25_EVENT_ERROR;
ev->fd = fd;
FD_CLR(fd, &ax25->unix_fds_pending_error); FD_CLR(fd, &ax25->unix_fds_pending_error);
return 0; return fd;
} }
} }

View file

@ -246,6 +246,10 @@ int patty_ax25_add_if(patty_ax25 *ax25, patty_ax25_if *iface) {
} }
} }
if (patty_dict_set(ax25->unix_fd_lookup, &fd, sizeof(fd), iface) == NULL) {
goto error_dict_set;
}
if (patty_list_append(ax25->ifaces, iface) == NULL) { if (patty_list_append(ax25->ifaces, iface) == NULL) {
goto error_list_append; goto error_list_append;
} }
@ -253,6 +257,7 @@ int patty_ax25_add_if(patty_ax25 *ax25, patty_ax25_if *iface) {
return 0; return 0;
error_list_append: error_list_append:
error_dict_set:
return -1; return -1;
} }
@ -280,10 +285,15 @@ int patty_ax25_delete_if(patty_ax25 *ax25, patty_ax25_if *iface) {
if (ax25->unix_fdmax == fd) { if (ax25->unix_fdmax == fd) {
ax25->unix_fdmax--; ax25->unix_fdmax--;
} }
if (patty_dict_delete(ax25->unix_fd_lookup, &fd, sizeof(fd)) == NULL) {
goto error_dict_delete;
}
} }
return 0; return 0;
error_dict_delete:
error_list_splice: error_list_splice:
return -1; return -1;
} }