Start to whittle down src/ax25.c, include/ax25.h
This commit is contained in:
parent
66e5de9d6c
commit
153dc17c7b
3 changed files with 44 additions and 52 deletions
|
@ -48,20 +48,21 @@ typedef struct _patty_ax25_sock {
|
||||||
enum patty_ax25_sock_mode mode;
|
enum patty_ax25_sock_mode mode;
|
||||||
enum patty_ax25_sock_opts opts;
|
enum patty_ax25_sock_opts opts;
|
||||||
|
|
||||||
time_t timer_ack;
|
time_t timer_ack,
|
||||||
time_t timer_response;
|
timer_response,
|
||||||
time_t timer_keepalive;
|
timer_keepalive;
|
||||||
|
|
||||||
int n_maxlen;
|
unsigned int n_maxlen,
|
||||||
int n_retry;
|
n_retry,
|
||||||
int n_window;
|
n_window;
|
||||||
|
|
||||||
int seq_send;
|
unsigned int seq_send,
|
||||||
int seq_recv;
|
seq_recv;
|
||||||
|
|
||||||
patty_ax25_if * iface;
|
patty_ax25_if *iface;
|
||||||
patty_ax25_address * local;
|
|
||||||
patty_ax25_address * remote;
|
patty_ax25_address *local,
|
||||||
|
*remote;
|
||||||
} patty_ax25_sock;
|
} patty_ax25_sock;
|
||||||
|
|
||||||
typedef struct _patty_ax25_event {
|
typedef struct _patty_ax25_event {
|
||||||
|
@ -70,20 +71,19 @@ typedef struct _patty_ax25_event {
|
||||||
} patty_ax25_event;
|
} patty_ax25_event;
|
||||||
|
|
||||||
typedef struct _patty_ax25 {
|
typedef struct _patty_ax25 {
|
||||||
patty_list * ifaces;
|
patty_list *ifaces,
|
||||||
patty_list * socks;
|
*socks;
|
||||||
|
|
||||||
int unix_fdmax;
|
int fd,
|
||||||
fd_set unix_fds;
|
current,
|
||||||
fd_set unix_fds_pending_read;
|
fdmax;
|
||||||
fd_set unix_fds_pending_write;
|
|
||||||
fd_set unix_fds_pending_error;
|
|
||||||
|
|
||||||
patty_dict * unix_fd_lookup;
|
fd_set fds,
|
||||||
|
fds_pending_read,
|
||||||
|
fds_pending_write,
|
||||||
|
fds_pending_error;
|
||||||
|
|
||||||
patty_dict * fd_lookup;
|
patty_dict * fd_lookup;
|
||||||
int fd;
|
|
||||||
int current;
|
|
||||||
} patty_ax25;
|
} patty_ax25;
|
||||||
|
|
||||||
int patty_ax25_init(patty_ax25 *ax25);
|
int patty_ax25_init(patty_ax25 *ax25);
|
||||||
|
|
38
src/ax25.c
38
src/ax25.c
|
@ -21,15 +21,8 @@ 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);
|
||||||
|
|
||||||
|
@ -47,7 +40,6 @@ 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);
|
||||||
|
|
||||||
|
@ -196,43 +188,43 @@ error_fd_lookup:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int next_unix_fd_event(patty_ax25 *ax25, enum patty_ax25_event_type *type) {
|
static int next_fd_event(patty_ax25 *ax25, enum patty_ax25_event_type *type) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (ax25->current == 0) {
|
if (ax25->current == 0) {
|
||||||
memcpy(&ax25->unix_fds_pending_read, &ax25->unix_fds, sizeof(ax25->unix_fds));
|
memcpy(&ax25->fds_pending_read, &ax25->fds, sizeof(ax25->fds));
|
||||||
memcpy(&ax25->unix_fds_pending_write, &ax25->unix_fds, sizeof(ax25->unix_fds));
|
memcpy(&ax25->fds_pending_write, &ax25->fds, sizeof(ax25->fds));
|
||||||
memcpy(&ax25->unix_fds_pending_error, &ax25->unix_fds, sizeof(ax25->unix_fds));
|
memcpy(&ax25->fds_pending_error, &ax25->fds, sizeof(ax25->fds));
|
||||||
|
|
||||||
if (select(ax25->unix_fdmax,
|
if (select(ax25->fdmax,
|
||||||
&ax25->unix_fds_pending_read,
|
&ax25->fds_pending_read,
|
||||||
&ax25->unix_fds_pending_write,
|
&ax25->fds_pending_write,
|
||||||
&ax25->unix_fds_pending_error, NULL) < 0) {
|
&ax25->fds_pending_error, NULL) < 0) {
|
||||||
goto error_select;
|
goto error_select;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (fd=ax25->current; fd<ax25->unix_fdmax; fd++) {
|
for (fd=ax25->current; fd<ax25->fdmax; fd++) {
|
||||||
if (FD_ISSET(fd, &ax25->unix_fds_pending_read)) {
|
if (FD_ISSET(fd, &ax25->fds_pending_read)) {
|
||||||
*type = PATTY_AX25_EVENT_RECV;
|
*type = PATTY_AX25_EVENT_RECV;
|
||||||
|
|
||||||
FD_CLR(fd, &ax25->unix_fds_pending_read);
|
FD_CLR(fd, &ax25->fds_pending_read);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(fd, &ax25->unix_fds_pending_write)) {
|
if (FD_ISSET(fd, &ax25->fds_pending_write)) {
|
||||||
*type = PATTY_AX25_EVENT_SEND;
|
*type = PATTY_AX25_EVENT_SEND;
|
||||||
|
|
||||||
FD_CLR(fd, &ax25->unix_fds_pending_write);
|
FD_CLR(fd, &ax25->fds_pending_write);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(fd, &ax25->unix_fds_pending_error)) {
|
if (FD_ISSET(fd, &ax25->fds_pending_error)) {
|
||||||
*type = PATTY_AX25_EVENT_ERROR;
|
*type = PATTY_AX25_EVENT_ERROR;
|
||||||
|
|
||||||
FD_CLR(fd, &ax25->unix_fds_pending_error);
|
FD_CLR(fd, &ax25->fds_pending_error);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
16
src/if.c
16
src/if.c
|
@ -239,14 +239,14 @@ int patty_ax25_add_if(patty_ax25 *ax25, patty_ax25_if *iface) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if ((fd = patty_kiss_tnc_fd_unix(iface->tnc)) >= 0) {
|
if ((fd = patty_kiss_tnc_fd_unix(iface->tnc)) >= 0) {
|
||||||
FD_SET(fd, &ax25->unix_fds);
|
FD_SET(fd, &ax25->fds);
|
||||||
|
|
||||||
if (ax25->unix_fdmax < fd + 1) {
|
if (ax25->fdmax < fd + 1) {
|
||||||
ax25->unix_fdmax = fd + 1;
|
ax25->fdmax = fd + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patty_dict_set(ax25->unix_fd_lookup, &fd, sizeof(fd), iface) == NULL) {
|
if (patty_dict_set(ax25->fd_lookup, &fd, sizeof(fd), iface) == NULL) {
|
||||||
goto error_dict_set;
|
goto error_dict_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,13 +280,13 @@ int patty_ax25_delete_if(patty_ax25 *ax25, patty_ax25_if *iface) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = patty_kiss_tnc_fd_unix(iface->tnc)) >= 0) {
|
if ((fd = patty_kiss_tnc_fd_unix(iface->tnc)) >= 0) {
|
||||||
FD_CLR(fd, &ax25->unix_fds);
|
FD_CLR(fd, &ax25->fds);
|
||||||
|
|
||||||
if (ax25->unix_fdmax == fd) {
|
if (ax25->fdmax == fd) {
|
||||||
ax25->unix_fdmax--;
|
ax25->fdmax--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patty_dict_delete(ax25->unix_fd_lookup, &fd, sizeof(fd)) == NULL) {
|
if (patty_dict_delete(ax25->fd_lookup, &fd, sizeof(fd)) == NULL) {
|
||||||
goto error_dict_delete;
|
goto error_dict_delete;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue