diff --git a/ConsoleSession.cpp b/ConsoleSession.cpp index a21affa..06627ee 100644 --- a/ConsoleSession.cpp +++ b/ConsoleSession.cpp @@ -10,6 +10,8 @@ namespace core { void ConsoleSession::protocol(coreutils::ZString &data) { + coreutils::Log(coreutils::LOG_DEBUG_1) << data; + coreutils::ZString blank(""); switch (status) { @@ -33,7 +35,7 @@ namespace core { out << "Password: "; status = WAIT_PASSWORD; break; - + case WAIT_PASSWORD: status = PROMPT; protocol(blank); diff --git a/Socket.cpp b/Socket.cpp index 0168536..02dcf9d 100644 --- a/Socket.cpp +++ b/Socket.cpp @@ -144,14 +144,13 @@ namespace core } } - int Socket::write(std::string data, Socket *sender) { + int Socket::write(std::string data) { outlock.lock(); fifo.emplace(data); outlock.unlock(); - if(sender && (sender != this)) - if(!inHandler) { - ePoll.resetSocket(this); - } + if(!inHandler) { + ePoll.resetSocket(this); + } return 1; } diff --git a/Socket.h b/Socket.h index 9f988df..bf70108 100644 --- a/Socket.h +++ b/Socket.h @@ -86,7 +86,7 @@ namespace core { /// Write data to the socket. /// - int write(std::string data, Socket *sender = NULL); + int write(std::string data); void write(char *buffer, int length); void output(std::stringstream &out); @@ -167,7 +167,6 @@ namespace core { std::string text; int descriptor = -1; std::mutex outlock; -// std::mutex lock; bool readHangup = false; volatile bool inHandler = false; diff --git a/Subscription.cpp b/Subscription.cpp index 1089193..006a37c 100644 --- a/Subscription.cpp +++ b/Subscription.cpp @@ -21,7 +21,7 @@ namespace core out << "cancel:" << id << std::endl; for (auto subscriber : subscribers) { - subscriber->write(out.str(), NULL); + subscriber->write(out.str()); } } @@ -62,7 +62,7 @@ namespace core int Subscription::event(std::stringstream &out) { for (auto subscriber = subscribers.begin(); subscriber < subscribers.end(); ++subscriber) - (*subscriber)->write(out.str(), NULL); + (*subscriber)->write(out.str()); return 1; } diff --git a/TCPSession.cpp b/TCPSession.cpp index f1a3c5b..6b58a08 100644 --- a/TCPSession.cpp +++ b/TCPSession.cpp @@ -58,17 +58,13 @@ namespace core void TCPSession::onConnected() {} - void TCPSession::onDataReceived(coreutils::ZString &data) - { - if (data.getLength() > 0) - { + void TCPSession::onDataReceived(coreutils::ZString &data) { + if (data.getLength() > 0) { lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength()); memcpy(lineBuffer + lineBufferSize, data.getData(), data.getLength()); lineBufferSize += data.getLength(); - while (lineBufferSize > 0) - { - if (blockSize == 0) - { + while (lineBufferSize > 0) { + if (blockSize == 0) { lineLength = strcspn(lineBuffer, "\r\n"); if (lineLength == lineBufferSize) break; @@ -118,7 +114,7 @@ namespace core void TCPSession::send() { if(out.tellp() > 0) - write(out.str(), this); + write(out.str()); out.str(""); } diff --git a/TCPSession2.cpp b/TCPSession2.cpp index bd17da6..af272aa 100644 --- a/TCPSession2.cpp +++ b/TCPSession2.cpp @@ -74,7 +74,7 @@ namespace core { void TCPSession2::send() { if(out.tellp() > 0) - TCPSocket::write(out.str(), this); + TCPSocket::write(out.str()); out.str(""); } diff --git a/compile b/compile index ca6498e..65f0717 100755 --- a/compile +++ b/compile @@ -31,4 +31,5 @@ echo -n "Building library documentation manual..." doxygen docs/latex/doxygen.sty >/dev/null 2>/dev/null echo "OK" -rm *.o \ No newline at end of file +rm *.o +rm *~ diff --git a/html/Socket_8h_source.html b/html/Socket_8h_source.html index 63d37de..5ccd101 100644 --- a/html/Socket_8h_source.html +++ b/html/Socket_8h_source.html @@ -99,8 +99,8 @@ $(function() {
83  bool eventReceived(struct epoll_event event, long long eventId);
84 
88 
-
89  int write(std::string data, Socket *sender = NULL);
-
90  void write(char *buffer, int length);
+
89  int write(std::string data);
+
90  void write(char *buffer, int length);
91 
92  void output(std::stringstream &out);
93 
@@ -147,49 +147,48 @@ $(function() {
167  std::string text;
168  int descriptor = -1;
169  std::mutex outlock;
-
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 
+
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 
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:46
+
core::Socket::write
int write(std::string data)
Definition: Socket.cpp:147
core::Socket::eventReceived
bool eventReceived(struct epoll_event event, long long eventId)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:70
core::Socket::onRegistered
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:64
core::Socket::receiveData
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:102
core::Socket::Socket
Socket(EPoll &ePoll, std::string text="")
Definition: Socket.cpp:12
-
core::Socket::write
int write(std::string data, Socket *sender=NULL)
Definition: Socket.cpp:147
core::Socket::onRegister
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:62
core::Socket::~Socket
virtual ~Socket()
Definition: Socket.cpp:18
core::Socket::setDescriptor
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:30
core::Socket::onDataReceived
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:92
core::Socket::onUnregistered
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:68
-
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:168
+
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:167