Stop relying on struct ordering and packing for peer.

This commit is contained in:
Ian Gulliver
2016-03-08 20:47:22 -08:00
parent d39cd62991
commit 3985182304
7 changed files with 14 additions and 16 deletions

View File

@@ -68,7 +68,7 @@ static void exec_del(struct exec *exec) {
} }
static void exec_close_handler(struct peer *peer) { static void exec_close_handler(struct peer *peer) {
struct exec *exec = (struct exec *) peer; struct exec *exec = container_of(peer, struct exec, peer);
exec_harvest(exec); exec_harvest(exec);
uint32_t delay = wakeup_get_retry_delay_ms(1); uint32_t delay = wakeup_get_retry_delay_ms(1);
LOG(exec->id, "Will retry in %ds", delay / 1000); LOG(exec->id, "Will retry in %ds", delay / 1000);
@@ -159,7 +159,7 @@ static void exec_spawn(struct exec *exec) {
} }
static void exec_spawn_wrapper(struct peer *peer) { static void exec_spawn_wrapper(struct peer *peer) {
struct exec *exec = (struct exec *) peer; struct exec *exec = container_of(peer, struct exec, peer);
exec_spawn(exec); exec_spawn(exec);
} }

View File

@@ -76,7 +76,7 @@ static void file_retry(struct file *file) {
} }
static void file_handle_close(struct peer *peer) { static void file_handle_close(struct peer *peer) {
struct file *file = (struct file *) peer; struct file *file = container_of(peer, struct file, peer);
LOG(file->id, "File closed: %s", file->path); LOG(file->id, "File closed: %s", file->path);
if (file->retry) { if (file->retry) {
@@ -106,7 +106,7 @@ static void file_open(struct file *file) {
} }
static void file_open_wrapper(struct peer *peer) { static void file_open_wrapper(struct peer *peer) {
struct file *file = (struct file *) peer; struct file *file = container_of(peer, struct file, peer);
file_open(file); file_open(file);
} }

View File

@@ -48,7 +48,7 @@ static void incoming_retry(struct incoming *incoming) {
} }
static void incoming_handler(struct peer *peer) { static void incoming_handler(struct peer *peer) {
struct incoming *incoming = (struct incoming *) peer; struct incoming *incoming = container_of(peer, struct incoming, peer);
struct sockaddr peer_addr, local_addr; struct sockaddr peer_addr, local_addr;
socklen_t peer_addrlen = sizeof(peer_addr), local_addrlen = sizeof(local_addr); socklen_t peer_addrlen = sizeof(peer_addr), local_addrlen = sizeof(local_addr);
@@ -87,7 +87,7 @@ static void incoming_del(struct incoming *incoming) {
} }
static void incoming_listen(struct peer *peer) { static void incoming_listen(struct peer *peer) {
struct incoming *incoming = (struct incoming *) peer; struct incoming *incoming = container_of(peer, struct incoming, peer);
struct addrinfo *addrs; struct addrinfo *addrs;
int err = resolve_result(peer, &addrs); int err = resolve_result(peer, &addrs);
@@ -142,7 +142,7 @@ static void incoming_resolve(struct incoming *incoming) {
} }
static void incoming_resolve_wrapper(struct peer *peer) { static void incoming_resolve_wrapper(struct peer *peer) {
incoming_resolve((struct incoming *) peer); incoming_resolve(container_of(peer, struct incoming, peer));
} }
static bool incoming_add(const char *host_port, struct flow *flow, void *passthrough) { static bool incoming_add(const char *host_port, struct flow *flow, void *passthrough) {

View File

@@ -6,7 +6,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include "buf.h" #include "buf.h"
#include "flow.h" #include "flow.h"
@@ -73,7 +72,7 @@ static void outgoing_connect_next(struct outgoing *outgoing) {
} }
static void outgoing_connect_handler(struct peer *peer) { static void outgoing_connect_handler(struct peer *peer) {
struct outgoing *outgoing = (struct outgoing *) peer; struct outgoing *outgoing = container_of(peer, struct outgoing, peer);
peer_epoll_del(&outgoing->peer); peer_epoll_del(&outgoing->peer);
@@ -84,7 +83,7 @@ static void outgoing_connect_handler(struct peer *peer) {
} }
static void outgoing_disconnect_handler(struct peer *peer) { static void outgoing_disconnect_handler(struct peer *peer) {
struct outgoing *outgoing = (struct outgoing *) peer; struct outgoing *outgoing = container_of(peer, struct outgoing, peer);
LOG(outgoing->id, "Peer disconnected; reconnecting..."); LOG(outgoing->id, "Peer disconnected; reconnecting...");
outgoing_retry(outgoing); outgoing_retry(outgoing);
} }
@@ -121,7 +120,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) {
} }
static void outgoing_resolve_handler(struct peer *peer) { static void outgoing_resolve_handler(struct peer *peer) {
struct outgoing *outgoing = (struct outgoing *) peer; struct outgoing *outgoing = container_of(peer, struct outgoing, peer);
int err = resolve_result(peer, &outgoing->addrs); int err = resolve_result(peer, &outgoing->addrs);
if (err) { if (err) {
LOG(outgoing->id, "Failed to resolve %s/%s: %s", outgoing->node, outgoing->service, gai_strerror(err)); LOG(outgoing->id, "Failed to resolve %s/%s: %s", outgoing->node, outgoing->service, gai_strerror(err));
@@ -139,7 +138,7 @@ static void outgoing_resolve(struct outgoing *outgoing) {
} }
static void outgoing_resolve_wrapper(struct peer *peer) { static void outgoing_resolve_wrapper(struct peer *peer) {
outgoing_resolve((struct outgoing *) peer); outgoing_resolve(container_of(peer, struct outgoing, peer));
} }
static void outgoing_del(struct outgoing *outgoing) { static void outgoing_del(struct outgoing *outgoing) {

View File

@@ -4,7 +4,6 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include "airspy_adsb.h" #include "airspy_adsb.h"
#include "beast.h" #include "beast.h"
@@ -115,7 +114,7 @@ static void receive_del(struct receive *receive) {
} }
static void receive_read(struct peer *peer) { static void receive_read(struct peer *peer) {
struct receive *receive = (struct receive *) peer; struct receive *receive = container_of(peer, struct receive, peer);
if (buf_fill(&receive->buf, receive->peer.fd) <= 0) { if (buf_fill(&receive->buf, receive->peer.fd) <= 0) {
receive_del(receive); receive_del(receive);

View File

@@ -99,7 +99,7 @@ static void send_del(struct send *send) {
} }
static void send_del_wrapper(struct peer *peer) { static void send_del_wrapper(struct peer *peer) {
send_del((struct send *) peer); send_del(container_of(peer, struct send, peer));
} }
static void send_new(int fd, void *passthrough, struct peer *on_close) { static void send_new(int fd, void *passthrough, struct peer *on_close) {

View File

@@ -35,7 +35,7 @@ static void send_receive_del(struct send_receive *send_receive) {
} }
static void send_receive_on_close(struct peer *peer) { static void send_receive_on_close(struct peer *peer) {
struct send_receive *send_receive = (struct send_receive *) peer; struct send_receive *send_receive = container_of(peer, struct send_receive, peer);
if (!--(send_receive->ref_count)) { if (!--(send_receive->ref_count)) {
send_receive_del(send_receive); send_receive_del(send_receive);