auto &desc = m_socketDescriptionVector[sock];
desc.setListen(false);
desc.setOpen(true);
- desc.setCynara(false);
desc.interfaceID = 0;
desc.service = NULL;
}
SocketManager::SocketManager() :
+ m_cynaraSocket(-1),
m_maxDesc(0),
m_working(false),
m_counter(0)
return;
}
- if (m_socketDescriptionVector[sock].isCynara()) {
+ if (sock == m_cynaraSocket) {
m_cynara->ProcessSocket();
return;
}
void SocketManager::ReadyForWrite(int sock)
{
- if (m_socketDescriptionVector[sock].isCynara()) {
+ if (sock == m_cynaraSocket) {
m_cynara->ProcessSocket();
return;
}
return;
}
+ assert(sock != m_cynaraSocket);
+
GenericSocketService::CloseEvent event;
event.connectionID.sock = sock;
event.connectionID.counter = desc.counter;
void SocketManager::CynaraSocket(int oldFd, int newFd, bool isRW)
{
if (newFd != oldFd) {
- if (newFd >= 0) {
- auto &desc = CreateDefaultReadSocketDescription(newFd, false);
- desc.service = nullptr;
- desc.setCynara(true);
- }
-
if (oldFd >= 0) {
+ if (oldFd != m_cynaraSocket) {
+ LogError("Invalid old cynara socket " << oldFd);
+ return;
+ }
+
auto &old = m_socketDescriptionVector[oldFd];
+
+ assert(old.isOpen());
+
old.setOpen(false);
- old.setCynara(false);
+ m_cynaraSocket = -1;
FD_CLR(oldFd, &m_writeSet);
FD_CLR(oldFd, &m_readSet);
}
+
+ if (newFd >= 0) {
+ if (m_cynaraSocket != -1) {
+ LogError("Another cynara socket is already opened");
+ return;
+ }
+
+ if (newFd < static_cast<int>(m_socketDescriptionVector.size()) &&
+ m_socketDescriptionVector[newFd].isOpen())
+ {
+ LogError("New cynara socket " << newFd << " is already opened");
+ return;
+ }
+
+ auto &desc = CreateDefaultReadSocketDescription(newFd, false);
+ desc.service = nullptr;
+ m_cynaraSocket = newFd;
+ }
}
if (newFd >= 0) {
+ if (m_cynaraSocket != newFd) {
+ LogError("Invalid new cynara socket " << newFd);
+ return;
+ }
+
FD_SET(newFd, &m_readSet);
if (isRW)
return m_flags & LISTEN;
}
- bool isCynara()
- {
- return m_flags & CYNARA;
- }
-
bool isTimeout()
{
return m_flags & TIMEOUT;
isSet ? m_flags |= LISTEN : m_flags &= ~LISTEN;
}
- void setCynara(bool isSet)
- {
- isSet ? m_flags |= CYNARA : m_flags &= ~CYNARA;
- }
-
void setTimeout(bool isSet)
{
isSet ? m_flags |= TIMEOUT : m_flags &= ~TIMEOUT;
private:
static const char LISTEN = 1 << 0;
static const char OPEN = 1 << 1;
- static const char CYNARA = 1 << 2;
- static const char TIMEOUT = 1 << 3;
+ static const char TIMEOUT = 1 << 2;
int m_flags;
};
// support for generic event Queue
SocketDescriptionVector m_socketDescriptionVector;
+ int m_cynaraSocket;
fd_set m_readSet;
fd_set m_writeSet;
int m_maxDesc;