WPILibC++ 2024.3.2
TCPStream.h
Go to the documentation of this file.
1/*
2 TCPStream.h
3
4 TCPStream class interface. TCPStream provides methods to transfer
5 data between peers over a TCP/IP connection.
6
7 ------------------------------------------
8
9 Copyright (c) 2013 [Vic Hargrave - http://vichargrave.com]
10
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14
15 http://www.apache.org/licenses/LICENSE-2.0
16
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22*/
23
24#ifndef WPINET_TCPSTREAM_H_
25#define WPINET_TCPSTREAM_H_
26
27#include <cstddef>
28#include <string>
29#include <string_view>
30
32
33struct sockaddr_in;
34
35namespace wpi {
36
37class TCPStream : public NetworkStream {
38 int m_sd;
39 std::string m_peerIP;
40 int m_peerPort;
41 bool m_blocking;
42
43 public:
44 friend class TCPAcceptor;
45 friend class TCPConnector;
46
47 ~TCPStream() override;
48
49 size_t send(const char* buffer, size_t len, Error* err) override;
50 size_t receive(char* buffer, size_t len, Error* err,
51 int timeout = 0) override;
52 void close() final;
53
54 std::string_view getPeerIP() const override;
55 int getPeerPort() const override;
56 void setNoDelay() override;
57 bool setBlocking(bool enabled) override;
58 int getNativeHandle() const override;
59
60 TCPStream(const TCPStream& stream) = delete;
61 TCPStream& operator=(const TCPStream&) = delete;
62
63 private:
64 bool WaitForReadEvent(int timeout);
65
66 TCPStream(int sd, sockaddr_in* address);
67 TCPStream() = delete;
68};
69
70} // namespace wpi
71
72#endif // WPINET_TCPSTREAM_H_
Definition: NetworkStream.h:13
Error
Definition: NetworkStream.h:18
Definition: TCPAcceptor.h:39
Definition: TCPConnector.h:37
Definition: TCPStream.h:37
bool setBlocking(bool enabled) override
size_t send(const char *buffer, size_t len, Error *err) override
int getNativeHandle() const override
void setNoDelay() override
int getPeerPort() const override
size_t receive(char *buffer, size_t len, Error *err, int timeout=0) override
void close() final
std::string_view getPeerIP() const override
~TCPStream() override
Definition: array.h:89
Definition: ntcore_cpp.h:26