WPILibC++  2019.1.1-beta-2-30-g0d0492b
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
TCPStream.h
1 /*
2  TCPStream.h
3 
4  TCPStream class interface. TCPStream provides methods to trasnfer
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 WPIUTIL_WPI_TCPSTREAM_H_
25 #define WPIUTIL_WPI_TCPSTREAM_H_
26 
27 #include <cstddef>
28 #include <string>
29 
30 #include "wpi/NetworkStream.h"
31 
32 struct sockaddr_in;
33 
34 namespace wpi {
35 
36 class TCPStream : public NetworkStream {
37  int m_sd;
38  std::string m_peerIP;
39  int m_peerPort;
40  bool m_blocking;
41 
42  public:
43  friend class TCPAcceptor;
44  friend class TCPConnector;
45 
46  ~TCPStream();
47 
48  size_t send(const char* buffer, size_t len, Error* err) override;
49  size_t receive(char* buffer, size_t len, Error* err,
50  int timeout = 0) override;
51  void close() override;
52 
53  StringRef getPeerIP() const override;
54  int getPeerPort() const override;
55  void setNoDelay() override;
56  bool setBlocking(bool enabled) override;
57  int getNativeHandle() const override;
58 
59  TCPStream(const TCPStream& stream) = delete;
60  TCPStream& operator=(const TCPStream&) = delete;
61 
62  private:
63  bool WaitForReadEvent(int timeout);
64 
65  TCPStream(int sd, sockaddr_in* address);
66  TCPStream() = delete;
67 };
68 
69 } // namespace wpi
70 
71 #endif // WPIUTIL_WPI_TCPSTREAM_H_
Definition: NetworkStream.h:17
Definition: TCPConnector.h:37
Definition: TCPAcceptor.h:38
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Definition: TCPStream.h:36