From cb98cbc593309d4781dfb873b018a5d4e12ad118 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 1 Nov 2012 15:11:40 +0100 Subject: Dynamically create and destroy sockets without fixed binds --- src/fastd.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/fastd.h') diff --git a/src/fastd.h b/src/fastd.h index e4f7924..ecc3eee 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -73,7 +73,7 @@ struct _fastd_protocol { void (*peer_configure)(fastd_context *ctx, fastd_peer_config *peer_conf); void (*handshake_init)(fastd_context *ctx, const fastd_socket *sock, const fastd_peer_address *address, const fastd_peer_config *peer_conf); - void (*handshake_handle)(fastd_context *ctx, const fastd_socket *sock, const fastd_peer_address *address, const fastd_peer_config *peer_conf, const fastd_handshake *handshake, const fastd_method *method); + void (*handshake_handle)(fastd_context *ctx, fastd_socket *sock, const fastd_peer_address *address, const fastd_peer_config *peer_conf, const fastd_handshake *handshake, const fastd_method *method); void (*handle_recv)(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer); void (*send)(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer); @@ -189,7 +189,6 @@ struct _fastd_config { fastd_string_stack *peer_dirs; fastd_peer_config *peers; - unsigned n_peers; unsigned n_floating; unsigned n_v4; unsigned n_v6; @@ -228,6 +227,7 @@ struct _fastd_context { struct timespec now; + unsigned n_peers; fastd_peer *peers; fastd_queue task_queue; @@ -268,6 +268,8 @@ void fastd_send(fastd_context *ctx, const fastd_socket *sock, const fastd_peer_a void fastd_send_handshake(fastd_context *ctx, const fastd_socket *sock, const fastd_peer_address *address, fastd_buffer buffer); void fastd_handle_receive(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer); +fastd_socket* fastd_socket_open(fastd_context *ctx, int af); + void fastd_resolve_peer(fastd_context *ctx, fastd_peer *peer); int fastd_vsnprintf(const fastd_context *ctx, char *buffer, size_t size, const char *format, va_list ap); @@ -394,6 +396,15 @@ static inline void fastd_string_stack_free(fastd_string_stack *str) { } } +static inline void fastd_socket_close(fastd_context *ctx, fastd_socket *sock) { + if (sock->fd >= 0) { + if(close(sock->fd)) + pr_error_errno(ctx, "closing socket: close"); + + sock->fd = -2; + } +} + static inline bool timespec_after(const struct timespec *tp1, const struct timespec *tp2) { return (tp1->tv_sec > tp2->tv_sec || (tp1->tv_sec == tp2->tv_sec && tp1->tv_nsec > tp2->tv_nsec)); -- cgit v1.2.3