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
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:244
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
Defines the base class for output streams.
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37