src/Network/Target.hh
author Tero Marttila <terom@fixme.fi>
Mon, 26 Jan 2009 23:03:47 +0200
changeset 431 c6d7272a164b
child 432 82b0f4e55a13
permissions -rw-r--r--
rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
#ifndef NETWORK_TARGET_HH
#define NETWORK_TARGET_HH

/**
 * @file
 *
 * Abstract NetworkTarget definition
 */

#include "Channel.hh"
#include "Packet.hh"

/**
 * Abstract interface for sending NetworkPackets to some NetworkSession-related destination, either a single
 * NetworkNode or a NetworkGroup of nodes.
 */
class NetworkTarget {
    friend class NetworkGroup;

    protected:
        /**
         * Send the given packet directly
         */
        virtual void send_pkt (const NetworkPacketBuffer &pkt, bool reliable = true) = 0;

    public:        
        /**
         * Send a raw packet prepared using write_packet_header. This does not need to copy the packet data around.
         *
         * XXX: this interface needs fixing to be less procedural
         *
         * @param pkt the NetworkPacket prepared using write_packet_header
         * @param reliable whether to use TCP or UDP
         *
         * @see write_packet_header
         */
        void send_raw (const NetworkPacketBuffer &pkt, bool reliable = true);

        /**
         * Send the given packet on the given channel to this destination.
         *
         * Note that this constructs a new *NetworkPacket* containing our header and the given packet, so there
         * given packet must be small enough to fit.
         *
         * @param channel_id the NetworkChannelID to use
         * @param pkt the NetworkPacket to send on the given channel
         * @param reliable Whether to use TCP or UDP
         */
        void send (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable = true);
};

#endif /* NETWORK_TARGET_HH */