diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 4adb262..b3b6af6 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -48,20 +48,21 @@ typedef struct _patty_ax25_sock { enum patty_ax25_sock_mode mode; enum patty_ax25_sock_opts opts; - time_t timer_ack; - time_t timer_response; - time_t timer_keepalive; + time_t timer_ack, + timer_response, + timer_keepalive; - int n_maxlen; - int n_retry; - int n_window; + unsigned int n_maxlen, + n_retry, + n_window; - int seq_send; - int seq_recv; + unsigned int seq_send, + seq_recv; - patty_ax25_if * iface; - patty_ax25_address * local; - patty_ax25_address * remote; + patty_ax25_if *iface; + + patty_ax25_address *local, + *remote; } patty_ax25_sock; typedef struct _patty_ax25_event { @@ -70,20 +71,19 @@ typedef struct _patty_ax25_event { } patty_ax25_event; typedef struct _patty_ax25 { - patty_list * ifaces; - patty_list * socks; + patty_list *ifaces, + *socks; - 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; + int fd, + current, + fdmax; - patty_dict * unix_fd_lookup; + fd_set fds, + fds_pending_read, + fds_pending_write, + fds_pending_error; patty_dict * fd_lookup; - int fd; - int current; } patty_ax25; int patty_ax25_init(patty_ax25 *ax25); diff --git a/src/ax25.c b/src/ax25.c index 42ec499..6dbdb3f 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -21,15 +21,8 @@ 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); @@ -47,7 +40,6 @@ 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); @@ -196,43 +188,43 @@ error_fd_lookup: 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; if (ax25->current == 0) { - memcpy(&ax25->unix_fds_pending_read, &ax25->unix_fds, sizeof(ax25->unix_fds)); - memcpy(&ax25->unix_fds_pending_write, &ax25->unix_fds, sizeof(ax25->unix_fds)); - memcpy(&ax25->unix_fds_pending_error, &ax25->unix_fds, sizeof(ax25->unix_fds)); + memcpy(&ax25->fds_pending_read, &ax25->fds, sizeof(ax25->fds)); + memcpy(&ax25->fds_pending_write, &ax25->fds, sizeof(ax25->fds)); + memcpy(&ax25->fds_pending_error, &ax25->fds, sizeof(ax25->fds)); - if (select(ax25->unix_fdmax, - &ax25->unix_fds_pending_read, - &ax25->unix_fds_pending_write, - &ax25->unix_fds_pending_error, NULL) < 0) { + if (select(ax25->fdmax, + &ax25->fds_pending_read, + &ax25->fds_pending_write, + &ax25->fds_pending_error, NULL) < 0) { goto error_select; } } - for (fd=ax25->current; fdunix_fdmax; fd++) { - if (FD_ISSET(fd, &ax25->unix_fds_pending_read)) { + for (fd=ax25->current; fdfdmax; fd++) { + if (FD_ISSET(fd, &ax25->fds_pending_read)) { *type = PATTY_AX25_EVENT_RECV; - FD_CLR(fd, &ax25->unix_fds_pending_read); + FD_CLR(fd, &ax25->fds_pending_read); return fd; } - if (FD_ISSET(fd, &ax25->unix_fds_pending_write)) { + if (FD_ISSET(fd, &ax25->fds_pending_write)) { *type = PATTY_AX25_EVENT_SEND; - FD_CLR(fd, &ax25->unix_fds_pending_write); + FD_CLR(fd, &ax25->fds_pending_write); return fd; } - if (FD_ISSET(fd, &ax25->unix_fds_pending_error)) { + if (FD_ISSET(fd, &ax25->fds_pending_error)) { *type = PATTY_AX25_EVENT_ERROR; - FD_CLR(fd, &ax25->unix_fds_pending_error); + FD_CLR(fd, &ax25->fds_pending_error); return fd; } diff --git a/src/if.c b/src/if.c index 9d2465e..79bbb66 100644 --- a/src/if.c +++ b/src/if.c @@ -239,14 +239,14 @@ int patty_ax25_add_if(patty_ax25 *ax25, patty_ax25_if *iface) { int fd; 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) { - ax25->unix_fdmax = fd + 1; + if (ax25->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; } @@ -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) { - FD_CLR(fd, &ax25->unix_fds); + FD_CLR(fd, &ax25->fds); - if (ax25->unix_fdmax == fd) { - ax25->unix_fdmax--; + if (ax25->fdmax == fd) { + 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; } }