nlib
TcpOutputStream.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_TCPOUTPUTSTREAM_H_
17 #define INCLUDE_NN_NLIB_TCPOUTPUTSTREAM_H_
18 
19 #include "nn/nlib/Platform.h"
20 #ifdef NLIB_SOCKET_ENABLED
21 
22 #include "nn/nlib/Config.h"
23 #include "nn/nlib/OutputStream.h"
24 
25 NLIB_NAMESPACE_BEGIN
26 
27 struct TcpOutputStreamSettings {
28  void* buf;
29  size_t buffer_size;
30  TcpOutputStreamSettings() : buf(nullptr), buffer_size(8192) {}
31 };
32 
33 class NLIB_VIS_PUBLIC TcpOutputStream NLIB_FINAL : public OutputStream {
34  public:
35  TcpOutputStream() NLIB_NOEXCEPT : socket_(NLIB_SOCKET_INVALID), buf_(nullptr), buf_size_(0),
36  buffer_holder_(nullptr) {}
37  virtual ~TcpOutputStream() NLIB_NOEXCEPT NLIB_OVERRIDE;
38  errno_t Init(nlib_sock sockfd) NLIB_NOEXCEPT {
39  TcpOutputStreamSettings settings;
40  return this->Init(sockfd, settings);
41  }
42  errno_t Init(nlib_sock sockfd, const TcpOutputStreamSettings& settings) NLIB_NOEXCEPT;
43 
44  private:
45  virtual bool PushBuffer_(const void* p, size_t nbytes,
46  bool do_flush) NLIB_NOEXCEPT NLIB_OVERRIDE;
47  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
48 
49  private:
50  nlib_sock socket_;
51  uint8_t* buf_;
52  size_t buf_size_;
53  uint8_t* buffer_holder_;
54 };
55 
56 NLIB_NAMESPACE_END
57 
58 #endif
59 #endif // INCLUDE_NN_NLIB_TCPOUTPUTSTREAM_H_
#define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:244
基本的なAPIがCリンケージで宣言されています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
開発環境別の設定が書かれるファイルです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
出力ストリームの基底クラスを定義しています。
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37