summaryrefslogtreecommitdiff
path: root/src/multiplex.h
blob: 946e570c9b547d83aadb3dd582780544dcd90f47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once

#include <al/array.h>

#include "socket/socket.h"

#include "loop.h"
#include "packet_stream.h"

struct nn_multiplex_direct {
    struct nn_packet_stream *closing_bridge;
    bool (*connection_callback)(void *, u8 id, struct nn_packet_stream *stream);
    void *userdata;
};

struct nn_multiplex_socket;
struct nn_multiplex_connection {
    struct nn_socket sock;
    ev_io event;
    struct nn_multiplex_socket *multi;
};

struct nn_multiplex_socket {
    struct nn_socket sock;
    struct nn_event_loop *loop;
    ev_io event;
    bool (*connection_callback)(void *, u8 id, struct nn_packet_stream *stream);
    void *userdata;
};

bool nn_multiplex_socket_init(struct nn_multiplex_socket *multi, u8 type,
    bool (*connection_callback)(void *, u8, struct nn_packet_stream *), void *userdata);
bool nn_multiplex_socket_listen(struct nn_multiplex_socket *multi, struct nn_event_loop *loop, str *addr, u16 port);
void nn_multiplex_socket_close(struct nn_multiplex_socket *multi);

void nn_multiplex_direct_init(bool (*connection_callback)(void *, u8, struct nn_packet_stream *), void *userdata);
void nn_multiplex_direct_connect(struct nn_packet_stream *client, u8 id);
void nn_multiplex_direct_reconnect(struct nn_packet_stream *client);
struct nn_packet_stream *nn_multiplex_direct_get_bridge(void);
void nn_multiplex_direct_close(void);