-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bb7b1a
commit ed2ffd3
Showing
6 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Class that is used when the TCP connection ends up in a closed state | ||
* | ||
* @author Emiel Bruijntjes <[email protected]> | ||
* @copyright 2015 Copernica BV | ||
* @copyright 2015 - 2016 Copernica BV | ||
*/ | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Implementation file for the TCP connection | ||
* | ||
* @author Emiel Bruijntjes <[email protected]> | ||
* @copyright 2015 Copernica BV | ||
* @copyright 2015 - 2016 Copernica BV | ||
*/ | ||
|
||
/** | ||
|
@@ -56,6 +56,31 @@ void TcpConnection::process(int fd, int flags) | |
_state.reset(result); | ||
} | ||
|
||
/** | ||
* Flush the tcp connection | ||
*/ | ||
void TcpConnection::flush() | ||
{ | ||
// monitor the object for destruction | ||
Monitor monitor(this); | ||
|
||
// keep looping | ||
while (true) | ||
{ | ||
// flush the object | ||
auto *newstate = _state->flush(); | ||
|
||
// done if object no longer exists | ||
if (!monitor.valid()) return; | ||
|
||
// also done if the object is still in the same state | ||
if (newstate == _state.get()) return; | ||
|
||
// replace the new state | ||
_state.reset(newstate); | ||
} | ||
} | ||
|
||
/** | ||
* Method that is called when the heartbeat frequency is negotiated. | ||
* @param connection The connection that suggested a heartbeat interval | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* server, and to make the initial connection | ||
* | ||
* @author Emiel Bruijntjes <[email protected]> | ||
* @copyright 2015 Copernica BV | ||
* @copyright 2015 - 2016 Copernica BV | ||
*/ | ||
|
||
/** | ||
|
@@ -173,9 +173,9 @@ class TcpResolver : public TcpState | |
|
||
/** | ||
* Wait for the resolver to be ready | ||
* @param fd The filedescriptor that is active | ||
* @param flags Flags to indicate that fd is readable and/or writable | ||
* @return New implementation object | ||
* @param fd The filedescriptor that is active | ||
* @param flags Flags to indicate that fd is readable and/or writable | ||
* @return New implementation object | ||
*/ | ||
virtual TcpState *process(int fd, int flags) override | ||
{ | ||
|
@@ -191,6 +191,25 @@ class TcpResolver : public TcpState | |
// create dummy implementation | ||
return new TcpClosed(_connection, _handler); | ||
} | ||
|
||
/** | ||
* Flush state / wait for the connection to complete | ||
* @return New implementation object | ||
*/ | ||
virtual TcpState *flush() override | ||
{ | ||
// just wait for the other thread to be ready | ||
_thread.join(); | ||
|
||
// do we have a valid socket? | ||
if (_socket >= 0) return new TcpConnected(_connection, _socket, std::move(_buffer), _handler); | ||
|
||
// report error | ||
_handler->onError(_connection, _error.data()); | ||
|
||
// create dummy implementation | ||
return new TcpClosed(_connection, _handler); | ||
} | ||
|
||
/** | ||
* Send data over the connection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Base class / interface of the various states of the TCP connection | ||
* | ||
* @author Emiel Bruijntjes <[email protected]> | ||
* @copyright 2015 Copernica BV | ||
* @copyright 2015 - 2016 Copernica BV | ||
*/ | ||
|
||
/** | ||
|
@@ -90,6 +90,12 @@ class TcpState | |
return _handler->onNegotiate(_connection, heartbeat); | ||
} | ||
|
||
/** | ||
* Flush the connection | ||
* @return TcpState new implementation object | ||
*/ | ||
virtual TcpState *flush() { return this; } | ||
|
||
/** | ||
* Report to the handler that the object is in an error state | ||
* @param error | ||
|