|
|
71057f |
#ifndef SERVER_H
|
|
|
71057f |
#define SERVER_H
|
|
|
71057f |
|
|
|
71057f |
|
|
|
71057f |
#include "connection.h"
|
|
|
71057f |
|
|
|
71057f |
|
|
|
71057f |
class Server: public Root {
|
|
|
71057f |
enum State: int {
|
|
|
71057f |
STATE_NONE,
|
|
|
71057f |
STATE_OPENING,
|
|
|
71057f |
STATE_INITIALIZING,
|
|
|
71057f |
STATE_RESOLVING,
|
|
|
71057f |
STATE_OPEN,
|
|
|
71057f |
STATE_CLOSE_REQ,
|
|
|
71057f |
STATE_CLOSING_CONNECTIONS,
|
|
|
71057f |
STATE_CLOSING,
|
|
|
71057f |
STATE_CLOSED,
|
|
|
71057f |
STATE_FINISHED
|
|
|
71057f |
};
|
|
|
71057f |
|
|
|
71057f |
private:
|
|
|
71057f |
friend class Protocol;
|
|
|
71057f |
|
|
|
71057f |
std::atomic<state> state;</state>
|
|
|
71057f |
std::atomic<state> stateWanted;</state>
|
|
|
71057f |
ReadProtector stateProtector;
|
|
|
71057f |
std::atomic<bool> enqueued;</bool>
|
|
|
71057f |
std::atomic<bool> error;</bool>
|
|
|
71057f |
|
|
|
71057f |
std::atomic<int> closeWaiters;</int>
|
|
|
71057f |
std::atomic<int> finishWaiters;</int>
|
|
|
71057f |
std::condition_variable closeCondition;
|
|
|
71057f |
|
|
|
71057f |
unsigned char address[MAX_ADDR_SIZE];
|
|
|
71057f |
size_t addressSize;
|
|
|
71057f |
|
|
|
71057f |
Protocol *protocol;
|
|
|
71057f |
Server *prev, *next;
|
|
|
71057f |
Server *queueNext;
|
|
|
71057f |
Connection *connFirst, *connLast;
|
|
|
71057f |
int sockId;
|
|
|
71057f |
State stateLocal;
|
|
|
71057f |
|
|
|
71057f |
void wantState(State state, bool error);
|
|
|
71057f |
|
|
|
71057f |
public:
|
|
|
71057f |
typedef QueueMISO<server, &server::queuenext=""> Queue;</server,>
|
|
|
71057f |
friend class QueueMISO<server, &server::queuenext="">;</server,>
|
|
|
71057f |
friend class ChainFuncs<server, &server::queuenext="">;</server,>
|
|
|
71057f |
|
|
|
71057f |
public:
|
|
|
71057f |
Server();
|
|
|
71057f |
~Server();
|
|
|
71057f |
|
|
|
71057f |
bool open(Protocol &protocol, void *address, size_t addressSize);
|
|
|
71057f |
void closeReq();
|
|
|
71057f |
void close(bool error);
|
|
|
71057f |
void closeWait(unsigned long long timeoutUs = 0, bool withReq = true);
|
|
|
71057f |
|
|
|
71057f |
protected:
|
|
|
71057f |
virtual void onOpeningError();
|
|
|
71057f |
virtual void onOpen();
|
|
|
51b3f0 |
virtual Connection* onConnect(const void *address, size_t addressSize);
|
|
|
71057f |
virtual void onDisconnect(Connection *connection, bool error);
|
|
|
71057f |
virtual void onCloseReqested();
|
|
|
71057f |
virtual void onClose(bool error);
|
|
|
71057f |
};
|
|
|
71057f |
|
|
|
71057f |
|
|
|
71057f |
#endif
|