SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRUD_Link.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt for details)
6  */
7 
8 #pragma once
9 #include "CRUDP_Protocol.h"
10 #include "EventProcessor.h"
12 #include "PacketCodec.h"
13 
14 #include <ace/ACE.h>
15 #include <ace/Synch.h>
16 #include <ace/SOCK_Dgram.h>
17 #include <ace/Reactor_Notification_Strategy.h>
18 #include <ace/Thread_Mutex.h>
19 #include <ace/Guard_T.h>
20 
21 #include <cassert>
22 
23 class SEGSEvent;
24 class PacketEvent;
25 class CRUD_EventFactory;
26 
27 
28 class CRUDLink : public LinkBase
29 {
30 protected:
31 using super = LinkBase;
32  ACE_Reactor_Notification_Strategy m_notifier; // our queue will use this to inform the reactor of it's new elements
33  ACE_HANDLE get_handle (void) const override {return peer_.get_handle();}
34  ACE_Time_Value m_last_recv_activity; // last link activity time
35  ACE_Time_Value m_last_send_activity; // last send activity on the link
36 public:
37 
38 using stream_type = ACE_SOCK_Dgram;
39 using addr_type = ACE_INET_Addr;
40 
41 public:
42  CRUDLink();
43  ~CRUDLink() override;
44 
45  int open(void * = nullptr) override;
46  int handle_output( ACE_HANDLE = ACE_INVALID_HANDLE ) override;
47  void received_block(BitStream &bytes);
48  void dispatch(SEGSEvent *) override
49  {
50  assert(!"Should not be called");
51  }
53  stream_type & peer() { return peer_; }
55 
56  ACE_Time_Value client_last_seen_packets() const
57  {
58  return ACE_OS::gettimeofday()-m_last_recv_activity;
59  }
60  ACE_Time_Value last_sent_packets() const
61  {
62  return ACE_OS::gettimeofday()-m_last_send_activity;
63  }
65 protected:
66  int handle_close(ACE_HANDLE h, ACE_Reactor_Mask c) override;
67  void event_for_packet(PacketEvent *pak_ev);
68  void packets_for_event(SEGSEvent *c_ev);
69  void connection_update();
73 virtual CRUD_EventFactory &factory() = 0;
74 
80 
81 };
void connection_update()
Connection updates are done only when new data is available on the link.
Definition: CRUD_Link.cpp:95
Definition: SEGSEvent.h:32
CRUDLink()
Definition: CRUD_Link.cpp:29
size_t UnackedPacketCount() const
Definition: CRUDP_Protocol.h:76
Definition: BitStream.h:30
Definition: CRUD_Events.h:30
int handle_output(ACE_HANDLE=ACE_INVALID_HANDLE) override
Definition: CRUD_Link.cpp:119
Definition: ILink.h:14
Definition: CRUDP_Protocol.h:38
void connection_sent_packet()
Connection updates are done only when new data is sent on the link.
Definition: CRUD_Link.cpp:101
Definition: EventProcessor.h:13
~CRUDLink() override
Definition: CRUD_Link.cpp:36
void packets_for_event(SEGSEvent *c_ev)
CRUDLink::packets_for_event - convert event to 1-n packets and push them to our net_layer() ...
Definition: CRUD_Link.cpp:68
void received_block(BitStream &bytes)
CRUDLink::received_block - convert incoming bytes to PacketEvent&#39;s.
Definition: CRUD_Link.cpp:161
int open(void *=nullptr) override
Definition: CRUD_Link.cpp:108
void event_for_packet(PacketEvent *pak_ev)
CRUDLink::event_for_packet - convert incoming packet into higher level events and push them to our ta...
Definition: CRUD_Link.cpp:45
int handle_close(ACE_HANDLE h, ACE_Reactor_Mask c) override
Definition: CRUD_Link.cpp:179
Definition: CRUD_Events.h:131