SNode.C
Loading...
Searching...
No Matches
SocketContext.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef CORE_SOCKET_SOCKETCONTEXT_H
21#define CORE_SOCKET_SOCKETCONTEXT_H
22
23namespace utils {
24 class Timeval;
25} // namespace utils
26
27#ifndef DOXYGEN_SHOULD_SKIP_THIS
28
29#include <cstddef>
30#include <string>
31
32#endif /* DOXYGEN_SHOULD_SKIP_THIS */
33
34namespace core::socket {
35
36 class SocketContext {
37 protected:
38 SocketContext() = default;
39
40 public:
41 SocketContext(const SocketContext&) = delete;
42 SocketContext(SocketContext&&) = delete;
43
44 SocketContext& operator=(const SocketContext&) = delete;
45 SocketContext& operator=(SocketContext&&) = delete;
46
47 protected:
48 virtual ~SocketContext();
49
50 public:
51 virtual void setTimeout(const utils::Timeval& timeout) = 0;
52
53 void sendToPeer(const std::string& data) const;
54 virtual void sendToPeer(const char* chunk, std::size_t chunkLen) const = 0;
55
56 virtual std::size_t readFromPeer(char* chunk, std::size_t chunklen) const = 0;
57
58 virtual void close() = 0;
59
60 protected:
61 virtual std::size_t onReceivedFromPeer() = 0;
62
63 virtual bool onSignal(int sig) = 0;
64
65 virtual void onWriteError(int errnum) = 0;
66 virtual void onReadError(int errnum) = 0;
67 };
68
69} // namespace core::socket
70
71#endif // CORE_SOCKET_SOCKETCONTEXT_H
int main(int argc, char *argv[])
#define QUOTE_INCLUDE(a)
Definition clients.h:25
#define STR(a)
Definition clients.h:26
EchoSocketClient getClient()
Definition clients.h:54
Definition clients.h:50
Definition Config.h:37