libUTL++
TCPsocket.h
1 #pragma once
2 
4 
5 #include <libutl/InetHostAddress.h>
6 #include <libutl/FDstream.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
21 
23 class TCPsocket : public FDstream
24 {
26 
27 public:
32  TCPsocket(int fd);
33 
39  TCPsocket(const InetHostAddress& hostAddr, uint16_t port);
40 
41  virtual void checkOK();
42 
48  void open(const InetHostAddress& hostAddr, uint16_t port);
49 
50 #if UTL_HOST_OS == UTL_OS_MINGW
51  virtual void close();
52 
53  virtual size_t read(byte_t* array, size_t maxBytes, size_t minBytes = size_t_max);
54 
55  virtual void write(const byte_t* array, size_t num);
56 #else
57  void setTCPnoDelay(bool noDelay);
58 #endif
59 protected:
60  virtual void setModes();
61 
62 private:
63  void
64  init()
65  {
66  }
67  void
68  deInit()
69  {
70  close();
71  }
72  void errToEx(const utl::Object* object = nullptr);
73 };
74 
76 
77 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
unsigned char byte_t
Unsigned character.
Definition: types.h:31
const size_t size_t_max
Maximum size_t value.
void errToEx(const utl::Object *object=nullptr)
Convert libc&#39;s errno to an exception.
unsigned short uint16_t
Unsigned 16-bit integer.
Definition: types.h:101
Stream with file descriptor.
Definition: FDstream.h:35
Root of UTL++ class hierarchy.
Definition: Object.h:52
void init()
Initialize UTL++.
Internet host address.