My final commit
This commit is contained in:
parent
a2b21eb848
commit
4e5634cbc7
3 changed files with 29 additions and 15 deletions
|
@ -60,8 +60,7 @@ typedef struct _patty_ax25_sock {
|
|||
|
||||
typedef struct _patty_ax25_event {
|
||||
enum patty_ax25_event_type type;
|
||||
|
||||
int fd;
|
||||
patty_ax25_sock * sock;
|
||||
} patty_ax25_event;
|
||||
|
||||
struct _patty_ax25 {
|
||||
|
@ -70,11 +69,12 @@ struct _patty_ax25 {
|
|||
|
||||
int unix_fdmax;
|
||||
fd_set unix_fds;
|
||||
|
||||
fd_set unix_fds_pending_read;
|
||||
fd_set unix_fds_pending_write;
|
||||
fd_set unix_fds_pending_error;
|
||||
|
||||
patty_dict * unix_fd_lookup;
|
||||
|
||||
patty_dict * fd_lookup;
|
||||
int fd;
|
||||
int current;
|
||||
|
|
28
src/ax25.c
28
src/ax25.c
|
@ -21,8 +21,15 @@ int patty_ax25_init(patty_ax25 *ax25) {
|
|||
goto error_dict_new_fd_lookup;
|
||||
}
|
||||
|
||||
if ((ax25->unix_fd_lookup = patty_dict_new()) == NULL) {
|
||||
goto error_dict_new_unix_fd_lookup;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_dict_new_unix_fd_lookup:
|
||||
patty_dict_destroy(ax25->fd_lookup);
|
||||
|
||||
error_dict_new_fd_lookup:
|
||||
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) {
|
||||
patty_dict_destroy(ax25->unix_fd_lookup);
|
||||
patty_dict_destroy(ax25->fd_lookup);
|
||||
patty_list_destroy(ax25->socks);
|
||||
|
||||
|
@ -188,7 +196,7 @@ error_fd_lookup:
|
|||
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;
|
||||
|
||||
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,
|
||||
&ax25->unix_fds_pending_read,
|
||||
&ax25->unix_fds_pending_write,
|
||||
&ax25->unix_fds_pending_error,
|
||||
NULL) < 0) {
|
||||
&ax25->unix_fds_pending_error, NULL) < 0) {
|
||||
goto error_select;
|
||||
}
|
||||
}
|
||||
|
||||
for (fd=ax25->current; fd<ax25->unix_fdmax; fd++) {
|
||||
if (FD_ISSET(fd, &ax25->unix_fds_pending_read)) {
|
||||
ev->type = PATTY_AX25_EVENT_RECV;
|
||||
ev->fd = fd;
|
||||
*type = PATTY_AX25_EVENT_RECV;
|
||||
|
||||
FD_CLR(fd, &ax25->unix_fds_pending_read);
|
||||
|
||||
return 0;
|
||||
return fd;
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, &ax25->unix_fds_pending_write)) {
|
||||
ev->type = PATTY_AX25_EVENT_SEND;
|
||||
ev->fd = fd;
|
||||
*type = PATTY_AX25_EVENT_SEND;
|
||||
|
||||
FD_CLR(fd, &ax25->unix_fds_pending_write);
|
||||
|
||||
return 0;
|
||||
return fd;
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, &ax25->unix_fds_pending_error)) {
|
||||
ev->type = PATTY_AX25_EVENT_ERROR;
|
||||
ev->fd = fd;
|
||||
*type = PATTY_AX25_EVENT_ERROR;
|
||||
|
||||
FD_CLR(fd, &ax25->unix_fds_pending_error);
|
||||
|
||||
return 0;
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
src/if.c
10
src/if.c
|
@ -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) {
|
||||
goto error_list_append;
|
||||
}
|
||||
|
@ -253,6 +257,7 @@ int patty_ax25_add_if(patty_ax25 *ax25, patty_ax25_if *iface) {
|
|||
return 0;
|
||||
|
||||
error_list_append:
|
||||
error_dict_set:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -280,10 +285,15 @@ int patty_ax25_delete_if(patty_ax25 *ax25, patty_ax25_if *iface) {
|
|||
if (ax25->unix_fdmax == fd) {
|
||||
ax25->unix_fdmax--;
|
||||
}
|
||||
|
||||
if (patty_dict_delete(ax25->unix_fd_lookup, &fd, sizeof(fd)) == NULL) {
|
||||
goto error_dict_delete;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_dict_delete:
|
||||
error_list_splice:
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue