Ocean
Loading...
Searching...
No Matches
PackagedTCPServer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef FACEBOOK_NETWORK_PACKAGED_TCP_SERVER_H
9#define FACEBOOK_NETWORK_PACKAGED_TCP_SERVER_H
10
14
15namespace Ocean
16{
17
18namespace Network
19{
20
21/**
22 * This class implements a TCP server with internal package handling.
23 * Each message is prefixed with a PackagedSocket::PackageHeader, so that the receiver can tell messages apart again after TCP has split or merged them.
24 * @see PackagedSocket::PackageHeader for the layout.
25 * @ingroup network
26 */
27class OCEAN_NETWORK_EXPORT PackagedTCPServer :
28 virtual public TCPServer,
29 virtual protected PackagedSocket
30{
31 protected:
32
33 /**
34 * Definition of a container
35 */
37 {
38 public:
39
40 /// The queue holding all memory blocks recently received and not yet process.
42
43 /// The memory block to be filled.
45
46 /// The memory block for the package header.
48 };
49
50 /**
51 * Definition of an unordered map mapping connection ids to ConnectionMemory objects.
52 */
53 using ConnectionMemoryMap = std::unordered_map<ConnectionId, ConnectionMemory>;
54
55 public:
56
57 /**
58 * Creates a new TCP server.
59 */
60 PackagedTCPServer() = default;
61
62 /**
63 * Destructs a TCP server.
64 */
65 ~PackagedTCPServer() override = default;
66
67 protected:
68
69 /**
70 * Internal event function to send data.
71 * @see ConnectionOrientedServer::onSend().
72 */
73 size_t onSend(const ConnectionId connectionId, const void* data, const size_t size) override;
74
75 /**
76 * Internal event function for received data.
77 * @see ConnectionOrientedServer::onReceived().
78 */
79 void onReceived(const ConnectionId connectionId, const void* data, const size_t size) override;
80
81 /**
82 * Internal event function for a connection which is about to be removed from this server.
83 * @see ConnectionOrientedServer::onRemoveConnection().
84 */
85 void onRemoveConnection(const ConnectionId connectionId) override;
86
87 protected:
88
89 /// The map mapping connection ids to ConnectionMemory objects.
91};
92
93}
94
95}
96
97#endif // FACEBOOK_NETWORK_PACKAGED_TCP_SERVER_H
unsigned int ConnectionId
Definition of a connection id.
Definition ConnectionOrientedServer.h:34
This class implements a memory block.
Definition PackagedSocket.h:42
This class is the base class for all packaged sockets.
Definition PackagedSocket.h:35
std::queue< MemoryBlock > MemoryBlockQueue
Definition of a queue holding memory blocks.
Definition PackagedSocket.h:137
Definition of a container.
Definition PackagedTCPServer.h:37
MemoryBlock currentMemory_
The memory block to be filled.
Definition PackagedTCPServer.h:44
MemoryBlockQueue memoryQueue_
The queue holding all memory blocks recently received and not yet process.
Definition PackagedTCPServer.h:41
MemoryBlock currentPackageHeaderMemory_
The memory block for the package header.
Definition PackagedTCPServer.h:47
This class implements a TCP server with internal package handling.
Definition PackagedTCPServer.h:30
ConnectionMemoryMap connectionMemoryMap_
The map mapping connection ids to ConnectionMemory objects.
Definition PackagedTCPServer.h:90
void onRemoveConnection(const ConnectionId connectionId) override
Internal event function for a connection which is about to be removed from this server.
~PackagedTCPServer() override=default
Destructs a TCP server.
void onReceived(const ConnectionId connectionId, const void *data, const size_t size) override
Internal event function for received data.
PackagedTCPServer()=default
Creates a new TCP server.
std::unordered_map< ConnectionId, ConnectionMemory > ConnectionMemoryMap
Definition of an unordered map mapping connection ids to ConnectionMemory objects.
Definition PackagedTCPServer.h:53
size_t onSend(const ConnectionId connectionId, const void *data, const size_t size) override
Internal event function to send data.
This class implements a TCP server.
Definition TCPServer.h:25
The namespace covering the entire Ocean framework.
Definition Accessor.h:15