WPILibC++ 2024.3.2
NetworkStream.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#ifndef WPINET_NETWORKSTREAM_H_
6#define WPINET_NETWORKSTREAM_H_
7
8#include <cstddef>
9#include <string_view>
10
11namespace wpi {
12
14 public:
15 NetworkStream() = default;
16 virtual ~NetworkStream() = default;
17
18 enum Error {
22 kWouldBlock = -3
23 };
24
25 virtual size_t send(const char* buffer, size_t len, Error* err) = 0;
26 virtual size_t receive(char* buffer, size_t len, Error* err,
27 int timeout = 0) = 0;
28 virtual void close() = 0;
29
30 virtual std::string_view getPeerIP() const = 0;
31 virtual int getPeerPort() const = 0;
32 virtual void setNoDelay() = 0;
33
34 // returns false on failure
35 virtual bool setBlocking(bool enabled) = 0;
36 virtual int getNativeHandle() const = 0;
37
38 NetworkStream(const NetworkStream&) = delete;
40};
41
42} // namespace wpi
43
44#endif // WPINET_NETWORKSTREAM_H_
Definition: NetworkStream.h:13
virtual int getNativeHandle() const =0
virtual void close()=0
virtual void setNoDelay()=0
virtual bool setBlocking(bool enabled)=0
virtual std::string_view getPeerIP() const =0
NetworkStream(const NetworkStream &)=delete
NetworkStream & operator=(const NetworkStream &)=delete
NetworkStream()=default
virtual size_t send(const char *buffer, size_t len, Error *err)=0
Error
Definition: NetworkStream.h:18
@ kConnectionTimedOut
Definition: NetworkStream.h:21
@ kWouldBlock
Definition: NetworkStream.h:22
@ kConnectionReset
Definition: NetworkStream.h:20
@ kConnectionClosed
Definition: NetworkStream.h:19
virtual ~NetworkStream()=default
virtual size_t receive(char *buffer, size_t len, Error *err, int timeout=0)=0
virtual int getPeerPort() const =0
basic_string_view< char > string_view
Definition: core.h:501
Definition: ntcore_cpp.h:26