src/Network/UDP.hh
author terom
Wed, 17 Dec 2008 00:40:22 +0000
changeset 381 9b35bc329d23
parent 286 2a8f20a53ff2
child 400 d64bf28c4340
permissions -rw-r--r--
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     1
#ifndef NETWORK_UDP_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     2
#define NETWORK_UDP_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     3
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     4
#include "Socket.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     5
#include "Address.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     6
#include "Packet.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     7
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
     8
/**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
     9
 * A UDP socket that can send and receive NetworkPackets
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    10
 */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    11
class NetworkUDP {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    12
    private:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    13
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    14
         * The socket itself
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    15
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    16
        NetworkSocket socket;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    17
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    18
        CL_SlotContainer slots;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    19
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    20
    public:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    21
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    22
         * Allocate an UDP socket on an ephemeral port (random port chosen by OS)
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    23
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    24
        NetworkUDP (void);
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    25
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    26
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    27
         * Allocate an UDP socket on a specific local port/interface
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    28
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    29
         * @param bind_addr the local address to bind to
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    30
         */
381
9b35bc329d23 separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents: 286
diff changeset
    31
        NetworkUDP (const NetworkEndpoint &bind_addr);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    32
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    33
    private:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    34
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    35
         * Socket is ready for recv, read as many packets as available, calling sig_packet on each
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    36
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    37
        void on_recv (void);
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    38
        
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    39
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    40
         * The signal called by on_recv
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    41
         */
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    42
        CL_Signal_v2<NetworkPacketInput&, const NetworkAddress&> _sig_packet;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    43
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    44
    public:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    45
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    46
         * Send the given packet on this UDP socket to the given destination address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    47
         */
202
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    48
        bool sendto (const NetworkPacketBuffer &packet, const NetworkAddress &dst);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    49
        
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    50
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    51
         * Triggered whenever a packet has been received, giving the NetworkPacketInput and the source address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    52
         */
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    53
        CL_Signal_v2<NetworkPacketInput&, const NetworkAddress&>& sig_packet (void) { return _sig_packet; }
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    54
};
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    55
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    56
#endif /* NETWORK_UDP_HH */