nlib
TcpInputStream.h
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_TCPINPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_TCPINPUTSTREAM_H_
5 
6 #include "nn/nlib/Platform.h"
7 #ifdef NLIB_SOCKET_ENABLED
8 
9 #include "nn/nlib/Config.h"
10 #include "nn/nlib/InputStream.h"
11 
12 NLIB_NAMESPACE_BEGIN
13 
14 struct TcpInputStreamSettings {
15  void* buf;
16  size_t buffer_size;
17  TcpInputStreamSettings() : buf(NULL), buffer_size(8192) {}
18 };
19 
20 class NLIB_VIS_PUBLIC TcpInputStream NLIB_FINAL : public InputStream {
21  public:
22  TcpInputStream() NLIB_NOEXCEPT : socket_(NLIB_SOCKET_INVALID), buf_(NULL), buf_size_(0),
23  buffer_holder_(NULL) {}
24  virtual ~TcpInputStream() NLIB_NOEXCEPT NLIB_OVERRIDE;
25  errno_t Init(nlib_sock sockfd) NLIB_NOEXCEPT {
26  TcpInputStreamSettings settings;
27  return this->Init(sockfd, settings);
28  }
29  errno_t Init(nlib_sock sockfd,
30  const TcpInputStreamSettings& settings) NLIB_NOEXCEPT;
31 
32  private:
33  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
34  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
35  virtual void* GetWorkBuffer_(size_t* nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
36 
37  private:
38  nlib_sock socket_;
39  uint8_t* buf_;
40  size_t buf_size_;
41  uint8_t* buffer_holder_;
42  NLIB_DISALLOW_COPY_AND_ASSIGN(TcpInputStream);
43 };
44 
45 NLIB_NAMESPACE_END
46 
47 #endif
48 
49 #endif // INCLUDE_NN_NLIB_TCPINPUTSTREAM_H_
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:210
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:145
Defines the base class for input streams.
C-based declaration of the basic API.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
A file that contains the configuration information for each development environment.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24