libUTL++
BufferedTCPsocket.h
1 #pragma once
2 
4 
5 #include <libutl/BufferedFDstream.h>
6 #include <libutl/TCPsocket.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
24 
27 {
29 
30 public:
32  {
33  setStream(socket);
34  }
35 
36  BufferedTCPsocket(int fd)
37  {
38  setStream(new TCPsocket(fd));
39  }
40 
41  BufferedTCPsocket(const InetHostAddress& hostAddr, uint16_t port)
42  {
43  setStream(new TCPsocket(hostAddr, port));
44  }
45 
46  void
47  open(const InetHostAddress& hostAddr, uint16_t port)
48  {
49  pget()->open(hostAddr, port);
50  setBufs();
51  }
52 
53 private:
54  void
55  init()
56  {
57  setStream(new TCPsocket());
58  }
59  void
60  deInit()
61  {
62  }
63 
64  const TCPsocket*
65  pget() const
66  {
67  ASSERTD(_stream != nullptr);
68  return utl::cast<TCPsocket>(_stream);
69  }
70  TCPsocket*
71  pget()
72  {
73  ASSERTD(_stream != nullptr);
74  return utl::cast<TCPsocket>(_stream);
75  }
76 };
77 
79 
80 UTL_NS_END;
TCP socket.
Definition: TCPsocket.h:23
void deInit()
De-initialize UTL++.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Buffered TCP socket stream.
unsigned short uint16_t
Unsigned 16-bit integer.
Definition: types.h:101
void init()
Initialize UTL++.
#define ASSERTD
Do an assertion in DEBUG mode only.
Buffered stream with file descriptor.
Internet host address.