src/Network/UDP.hh
author Tero Marttila <terom@fixme.fi>
Fri, 16 Jan 2009 22:03:49 +0200
changeset 400 d64bf28c4340
parent 381 9b35bc329d23
permissions -rw-r--r--
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
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
400
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
     4
/**
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
     5
 * @file
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
     6
 *
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
     7
 * UDP implementation
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
     8
 */
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
     9
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    10
#include "Socket.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    11
#include "Address.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    12
#include "Packet.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    13
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    14
/**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    15
 * A UDP socket that can send and receive NetworkPackets
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    16
 */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    17
class NetworkUDP {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    18
    private:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    19
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    20
         * The socket itself
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    21
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    22
        NetworkSocket socket;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    23
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    24
        CL_SlotContainer slots;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    25
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    26
    public:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    27
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    28
         * Allocate an UDP socket on an ephemeral port (random port chosen by OS)
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    29
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    30
        NetworkUDP (void);
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    31
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    32
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    33
         * Allocate an UDP socket on a specific local port/interface
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    34
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    35
         * @param bind_addr the local address to bind to
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    36
         */
381
9b35bc329d23 separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents: 286
diff changeset
    37
        NetworkUDP (const NetworkEndpoint &bind_addr);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    38
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    39
    private:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    40
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    41
         * 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
    42
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    43
        void on_recv (void);
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    44
        
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    45
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    46
         * The signal called by on_recv
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    47
         */
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    48
        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
    49
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    50
    public:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    51
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    52
         * Send the given packet on this UDP socket to the given destination address
400
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
    53
         *
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
    54
         * @return true if the packet was passed on to the socket API, false if the socket was busy and the packet was
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 381
diff changeset
    55
         * dropped (no chance of it arriving).
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    56
         */
202
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    57
        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
    58
        
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    59
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    60
         * Triggered whenever a packet has been received, giving the NetworkPacketInput and the source address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    61
         */
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    62
        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
    63
};
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    64
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    65
#endif /* NETWORK_UDP_HH */