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(NULL), 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_(NULL), buf_size_(0),
36  buffer_holder_(NULL) {}
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
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:228
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:163
入力ストリームの基底クラスを定義しています。
基本的なAPIがCリンケージで宣言されています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
開発環境別の設定が書かれるファイルです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:229
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37