nlib
TcpInputStream.h
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_TCPINPUTSTREAM_H_
17 #define INCLUDE_NN_NLIB_TCPINPUTSTREAM_H_
18 
19 #include "nn/nlib/Platform.h"
20 #ifdef NLIB_SOCKET_ENABLED
21 
22 #include "nn/nlib/Config.h"
23 #include "nn/nlib/InputStream.h"
24 
25 NLIB_NAMESPACE_BEGIN
26 
27 struct TcpInputStreamSettings {
28  void* buf;
29  size_t buffer_size;
30  TcpInputStreamSettings() : buf(nullptr), buffer_size(8192) {}
31 };
32 
33 class NLIB_VIS_PUBLIC TcpInputStream NLIB_FINAL : public InputStream {
34  public:
35  TcpInputStream() NLIB_NOEXCEPT : socket_(NLIB_SOCKET_INVALID), buf_(nullptr), buf_size_(0),
36  buffer_holder_(nullptr) {}
37  virtual ~TcpInputStream() NLIB_NOEXCEPT NLIB_OVERRIDE;
38  errno_t Init(nlib_sock sockfd) NLIB_NOEXCEPT {
39  TcpInputStreamSettings settings;
40  return this->Init(sockfd, settings);
41  }
42  errno_t Init(nlib_sock sockfd,
43  const TcpInputStreamSettings& settings) NLIB_NOEXCEPT;
44 
45  private:
46  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
47  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
48  virtual void* GetWorkBuffer_(size_t* nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
49 
50  private:
51  nlib_sock socket_;
52  uint8_t* buf_;
53  size_t buf_size_;
54  uint8_t* buffer_holder_;
55  NLIB_DISALLOW_COPY_AND_ASSIGN(TcpInputStream);
56 };
57 
58 NLIB_NAMESPACE_END
59 
60 #endif
61 
62 #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:244
#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:179
Defines the base class for input streams.
Basic APIs are declared with a C linkage.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
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:245
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37