5 #if UTL_HOST_OS == UTL_OS_LINUX 9 #include <libutl/Array.h> 10 #include <libutl/FDstream.h> 11 #include <libutl/Hashtable.h> 12 #include <libutl/Queue.h> 13 #include <libutl/Semaphore.h> 14 #include <libutl/ServerSocket.h> 15 #include <libutl/Thread.h> 23 class NetServerClient;
24 class QueuedConnection;
51 NetServer(
size_t maxClients,
size_t maxPaused = 1,
size_t clientsPerThread = 1)
53 init(maxClients, maxPaused, clientsPerThread);
56 virtual void* run(
void* arg =
nullptr);
68 void handlePipeEvent();
71 void handleServerSocketEvent(
int fd);
74 void clientDisconnectAll();
106 virtual bool exiting()
const;
109 void init(
size_t maxClients =
size_t_max,
size_t maxPaused = 1,
size_t clientsPerThread = 1);
130 using client_ptr_t = std::atomic<NetServerClient*>;
133 Array _serverSockets;
135 size_t _clientsPerThread;
141 client_ptr_t* _clients;
142 char pad0[UTL_CACHE_LINE_SIZE -
sizeof(size_t)];
143 std::atomic_size_t _clientsIndex;
144 char pad1[UTL_CACHE_LINE_SIZE -
sizeof(size_t)];
150 size_t _clientsCount;
176 virtual const Object& getKey()
const;
180 virtual void* run(
void* arg =
nullptr);
182 virtual void pause();
192 void setSocket(
Stream* socket);
201 Stream& unbufferedSocket()
const;
222 setVerified(
bool verified)
224 _verified = verified;
240 setIndex(
size_t index)
246 setNumClients(
size_t numClients)
248 _numClients = numClients;
254 return (_numClients > 0) && (_socket ==
nullptr);
260 return (_numClients == 0);
289 #endif // UTL_HOST_OS == UTL_OS_LINUX void deInit()
De-initialize UTL++.
Counter for resources shared between threads.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
const size_t size_t_max
Maximum size_t value.
SortedCollection that stores objects in an array.
Client connection to NetServer.
Local host server socket.
NetServer(size_t maxClients, size_t maxPaused=1, size_t clientsPerThread=1)
Constructor.
#define UTL_CLASS_DECL_ABC(DC, BC)
Declaration of standard UTL++ functionality for an abstract base class (ABC).
#define ABORT()
Immediately terminates the program.
#define UTL_CLASS_NO_SERIALIZE
Declare that a class cannot do serialize().
#define UTL_CLASS_NO_COPY
Declare that a class cannot do copy().
Stream with file descriptor.
Abstract base for multi-threaded network server.
Root of UTL++ class hierarchy.
void init()
Initialize UTL++.
#define ASSERTD
Do an assertion in DEBUG mode only.