diff --git a/Socket.cpp b/Socket.cpp index 05cf652..36c1fc4 100644 --- a/Socket.cpp +++ b/Socket.cpp @@ -17,7 +17,6 @@ namespace core { shutDown = true; onUnregister(); ePoll.unregisterSocket(this); -// coreutils::Log(coreutils::LOG_DEBUG_4) << "BMAXFree on socket " << descriptor; free(buffer); if(descriptor == -1) return; @@ -63,7 +62,7 @@ namespace core { void Socket::onUnregistered() {} bool Socket::eventReceived(struct epoll_event event, long long eventId) { -// coreutils::Log(coreutils::LOG_DEBUG_3) << "eventReceived " << eventId << ": " << descriptor << ":" << event.events; + lock.lock(); inHandler = true; if(event.events & EPOLLRDHUP) { readHangup = true; @@ -80,6 +79,7 @@ namespace core { shutdown(); } inHandler = false; + lock.unlock(); return !shutDown; } @@ -138,9 +138,10 @@ namespace core { outlock.lock(); fifo.emplace(data); outlock.unlock(); -// coreutils::Log(coreutils::LOG_DEBUG_4) << "inHandler " << descriptor << " " << inHandler << ":" << shutDown << ":[" << data << "]"; - if(!inHandler && sender != this) + if(sender != this) + lock.lock(); ePoll.resetSocket(this); + lock.unlock(); return 1; } diff --git a/Socket.h b/Socket.h index 05734c7..682ff5f 100644 --- a/Socket.h +++ b/Socket.h @@ -167,6 +167,7 @@ namespace core { std::string text; int descriptor = -1; std::mutex outlock; + std::mutex lock; bool readHangup = false; volatile bool inHandler = false; diff --git a/html/Socket_8h_source.html b/html/Socket_8h_source.html index 3435fa3..d97372c 100644 --- a/html/Socket_8h_source.html +++ b/html/Socket_8h_source.html @@ -147,48 +147,49 @@ $(function() {
167  std::string text;
168  int descriptor = -1;
169  std::mutex outlock;
-
170  bool readHangup = false;
-
171  volatile bool inHandler = false;
-
172 
-
173  //-------------------------------------------------------------------------------------
-
174  // the writeSocket is called when epoll has received a write request for a socket.
-
175  // Writing data to this socket is queued in the streambuf and permission is requested
-
176  // to write to the socket. This routine handles the writing of the streambuf data
-
177  // buffer to the socket.
-
178  //-------------------------------------------------------------------------------------
-
179 
-
180  void writeSocket();
-
181 
-
182  // int_type underflow();
-
183 // int_type uflow();
-
184 // int_type pbackfail(int_type ch);
-
185 // streamsize showmanyc();
-
186 
-
187  char *buffer; // This is a pointer to the managed buffer space.
-
188  int length; // This is the length of the buffer.
-
189 
-
190  std::queue<std::string> fifo;
-
191 
-
192  };
-
193 
-
194 }
-
195 
-
196 #endif
-
197 
+
170  std::mutex lock;
+
171  bool readHangup = false;
+
172  volatile bool inHandler = false;
+
173 
+
174  //-------------------------------------------------------------------------------------
+
175  // the writeSocket is called when epoll has received a write request for a socket.
+
176  // Writing data to this socket is queued in the streambuf and permission is requested
+
177  // to write to the socket. This routine handles the writing of the streambuf data
+
178  // buffer to the socket.
+
179  //-------------------------------------------------------------------------------------
+
180 
+
181  void writeSocket();
+
182 
+
183  // int_type underflow();
+
184 // int_type uflow();
+
185 // int_type pbackfail(int_type ch);
+
186 // streamsize showmanyc();
+
187 
+
188  char *buffer; // This is a pointer to the managed buffer space.
+
189  int length; // This is the length of the buffer.
+
190 
+
191  std::queue<std::string> fifo;
+
192 
+
193  };
+
194 
+
195 }
+
196 
+
197 #endif
+
198 
core::EPoll
Definition: EPoll.h:31
core::Socket
Definition: Socket.h:34
-
core::Socket::getDescriptor
int getDescriptor()
Get the descriptor for the socket.
Definition: Socket.cpp:44
-
core::Socket::eventReceived
bool eventReceived(struct epoll_event event, long long eventId)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:65
-
core::Socket::onRegistered
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:59
+
core::Socket::getDescriptor
int getDescriptor()
Get the descriptor for the socket.
Definition: Socket.cpp:43
+
core::Socket::eventReceived
bool eventReceived(struct epoll_event event, long long eventId)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:64
+
core::Socket::onRegistered
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:58
core::Socket::receiveData
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:94
core::Socket::Socket
Socket(EPoll &ePoll, std::string text="")
Definition: Socket.cpp:11
core::Socket::write
int write(std::string data, Socket *sender)
Definition: Socket.cpp:137
-
core::Socket::onRegister
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:57
+
core::Socket::onRegister
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:56
core::Socket::~Socket
virtual ~Socket()
Definition: Socket.cpp:16
-
core::Socket::setDescriptor
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:29
+
core::Socket::setDescriptor
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:28
core::Socket::onDataReceived
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:86
-
core::Socket::onUnregistered
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:63
-
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:155
+
core::Socket::onUnregistered
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:62
+
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:156