summaryrefslogtreecommitdiffstats
path: root/src/fastd.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-11-01 15:11:40 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-11-01 15:11:40 +0100
commitcb98cbc593309d4781dfb873b018a5d4e12ad118 (patch)
treec5c0760dbd36cabec9d421f678b5ebd4d59ed25e /src/fastd.h
parent86df5dbefec807234e9a458da00acbbd2e0e6649 (diff)
downloadfastd-cb98cbc593309d4781dfb873b018a5d4e12ad118.tar
fastd-cb98cbc593309d4781dfb873b018a5d4e12ad118.zip
Dynamically create and destroy sockets without fixed binds
Diffstat (limited to 'src/fastd.h')
-rw-r--r--src/fastd.h15
1 files changed, 13 insertions, 2 deletions
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));