Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef _SESSION_TPL_H_
#define _SESSION_TPL_H_

#include "WorldPacket.h"

namespace Divide {
//----------------------------------------------------------------------

//This is game specific but core functionality
extern void UpdateEntities(WorldPacket& p);

class subscriber {
   public:
    virtual ~subscriber() {}
    virtual void sendPacket(const WorldPacket& p) = 0;
};

typedef std::shared_ptr<subscriber> subscriber_ptr;

//----------------------------------------------------------------------

class channel {
   public:
    void join(subscriber_ptr sub) { subscribers_.insert(sub); }

    void leave(subscriber_ptr sub) { subscribers_.erase(sub); }

    void sendPacket(const WorldPacket& p) {
        std::for_each(std::begin(subscribers_), std::end(subscribers_),
                      boost::bind(&subscriber::sendPacket, _1, boost::ref(p)));
    }

   private:
    std::set<subscriber_ptr> subscribers_;
};

/// This is a single session handled by the server. It is mapped to a single
/// client
class tcp_session_tpl : public subscriber,
                        public std::enable_shared_from_this<tcp_session_tpl> {
   public:
    tcp_session_tpl(boost::asio::io_service& io_service, channel& ch);

    inline boost::asio::ip::tcp::socket& getSocket() { return _socket; }

    // Called by the server object to initiate the four actors.
    virtual void start();

    // Push a new packet in the output queue
    virtual void sendPacket(const WorldPacket& p);

    // Push a new file in the output queue
    virtual void sendFile(const stringImpl& fileName);

   private:
    virtual void stop();
    virtual bool stopped() const;

    // Read Packet;
    virtual void start_read();
    virtual void handle_read_body(const boost::system::error_code& ec,
                                  size_t bytes_transfered);
    virtual void handle_read_packet(const boost::system::error_code& ec,
                                    size_t bytes_transfered);

    // Write Packet
    virtual void start_write();
    virtual void handle_write(const boost::system::error_code& ec);

    // Write File
    virtual void handle_write_file(const boost::system::error_code& ec);

    // Update Timers
    virtual void await_output();
    virtual void check_deadline(boost::asio::deadline_timer* deadline);

   protected:
    // Define this functions to implement various packet handling (a switch
    // statement for example)
    // switch(p.getOpcode()) { case SMSG_XXXXX: bla bla bla break; case
    // MSG_HEARTBEAT: break;}
    virtual void handlePacket(WorldPacket& p);

    virtual void HandleHeartBeatOpCode(WorldPacket& p);
    virtual void HandleDisconnectOpCode(WorldPacket& p);
    virtual void HandlePingOpCode(WorldPacket& p);
    virtual void HandleEntityUpdateOpCode(WorldPacket& p);

   private:
    size_t _header;
    channel& _channel;
    boost::asio::ip::tcp::socket _socket;
    boost::asio::streambuf _inputBuffer;
    boost::asio::deadline_timer _inputDeadline;
    std::deque<WorldPacket> _outputQueue;
    std::deque<stringImpl> _outputFileQueue;
    boost::asio::deadline_timer _nonEmptyOutputQueue;
    boost::asio::deadline_timer _outputDeadline;
    boost::asio::io_context::strand _strand;
    time_t _startTime;
};

typedef std::shared_ptr<tcp_session_tpl> tcp_session_ptr;

//----------------------------------------------------------------------

class udp_broadcaster : public subscriber {
   public:
    udp_broadcaster(boost::asio::io_service& io_service,
                    const boost::asio::ip::udp::endpoint& broadcast_endpoint);

    inline boost::asio::ip::udp::socket& getSocket() { return socket_; }
    void sendPacket(const WorldPacket& p);

   private:
    boost::asio::ip::udp::socket socket_;
};

};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Networking/Headers/tcp_session_tpl.h

Diff revisions: vs.
Revision Author Commited Message
1012 Diff Diff IonutCava picture IonutCava Mon 15 Jan, 2018 17:21:32 +0000

[Ionut]
- Update boost to v1.66
- Performance optimizations

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

838 Diff Diff IonutCava picture IonutCava Mon 30 Jan, 2017 17:28:35 +0000

[IonutCava]
- Added a NetworkingComponent to SGNs
- Started cleaning up Client / Server architecture

499 Diff Diff IonutCava picture IonutCava Thu 20 Aug, 2015 21:22:10 +0000

[IonutCava]
- UBO/SSBO proper alignment fixed (finally)
- ShaderBuffer class cleanup

457 IonutCava picture IonutCava Mon 01 Jun, 2015 21:45:52 +0000

[Ionut]
- Windows build fix for previous commit