* Calling ::close() when txbuf empties and readyState is CLOSING

* Removing unnecessary const.
* Fixing up spacing to be consistent with rest of code.
This commit is contained in:
David Baird
2013-05-14 10:51:37 -06:00
parent bc1368b849
commit 86ec5a65b1
2 changed files with 7 additions and 9 deletions
+4 -6
View File
@@ -59,8 +59,7 @@ struct _DummyWebSocket : public WebSocket
void send(std::string message) { }
void close() { }
void _dispatch(Callback & callable) { }
const readyStateValues getReadyState() {}
readyStateValues getReadyState() { return CLOSED; }
};
@@ -115,7 +114,7 @@ struct _RealWebSocket : public WebSocket
_RealWebSocket(int sockfd) : sockfd(sockfd), readyState(OPEN) {
}
const readyStateValues getReadyState() {
readyStateValues getReadyState() {
return readyState;
}
@@ -149,6 +148,7 @@ struct _RealWebSocket : public WebSocket
if (ret > 0) { txbuf.erase(txbuf.begin(), txbuf.begin() + ret); }
else { break; }
}
if (!txbuf.size() && readyState == CLOSING) { ::close(); }
}
// Callable must have signature: void(const std::string & message).
@@ -214,9 +214,7 @@ struct _RealWebSocket : public WebSocket
}
else if (ws.opcode == wsheader_type::PING) { }
else if (ws.opcode == wsheader_type::PONG) { }
else if (ws.opcode == wsheader_type::CLOSE) {
if(readyState != CLOSING) { close(); }
}
else if (ws.opcode == wsheader_type::CLOSE) { close(); }
else { fprintf(stderr, "ERROR: Got unexpected WebSocket message.\n"); close(); }
rxbuf.erase(rxbuf.begin(), rxbuf.begin() + ws.header_size+ws.N);
+1 -1
View File
@@ -25,7 +25,7 @@ struct WebSocket {
virtual void poll() = 0;
virtual void send(std::string message) = 0;
virtual void close() = 0;
virtual const readyStateValues getReadyState() = 0;
virtual readyStateValues getReadyState() = 0;
template<class Callable>
void dispatch(Callable callable) { // N.B. this is compatible with both C++11 lambdas, functors and C function pointers
struct _Callback : public Callback {