-
Notifications
You must be signed in to change notification settings - Fork 1
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
68982f3
commit 572ff6d
Showing
8 changed files
with
113 additions
and
34 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 |
---|---|---|
|
@@ -43,7 +43,7 @@ class RoveCommEthernetTcp : public RoveCommServer | |
******************************************************************************/ | ||
RoveCommEthernetTcp(RoveCommPort unPort) : RoveCommServer(unPort){}; | ||
|
||
void Init() override; | ||
bool Init() override; | ||
void Shutdown() override; | ||
|
||
int Write(const RoveCommPacket& packet) override; | ||
|
@@ -62,6 +62,17 @@ class RoveCommEthernetTcp : public RoveCommServer | |
******************************************************************************/ | ||
bool Connect(const RoveCommAddress& address); | ||
|
||
/****************************************************************************** | ||
* @brief Close a TCP connection with another device (acting as client) | ||
* | ||
* @param address - The address to disconnect from. If no prior connection exists, | ||
* this function will do nothing. | ||
* | ||
* @author OcelotEmpire ([email protected]) | ||
* @date 2024-01-20 | ||
******************************************************************************/ | ||
void Disconnect(const RoveCommAddress& address); | ||
|
||
/****************************************************************************** | ||
* @brief Check for other devices trying to connect to this device (acting as server) | ||
* This will be private in a future iteration ;) | ||
|
@@ -76,6 +87,8 @@ class RoveCommEthernetTcp : public RoveCommServer | |
void _unregister_socket(const RoveCommAddress& sAddress); | ||
|
||
private: | ||
void OnRoveCommUpdate() override { AcceptIncomingConnections(); } | ||
|
||
// Socket for accepting connections from other devices | ||
RoveCommSocket m_nListeningSocket; | ||
// All open connections (outgoing and incoming) | ||
|
@@ -96,4 +109,4 @@ class RoveCommEthernetTcp : public RoveCommServer | |
fd_set m_sAcceptSet; | ||
}; | ||
|
||
#endif // ROVECOMM_ETHERNET_TCP_H | ||
#endif // ROVECOMM_ETHERNET_TCP_H |
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
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
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 |
---|---|---|
|
@@ -43,10 +43,12 @@ class RoveCommServer | |
/****************************************************************************** | ||
* @brief Initialize listening socket and start thread | ||
* | ||
* @return bool - Whether the server initialized successfully | ||
* | ||
* @author OcelotEmpire ([email protected]) | ||
* @date 2023-11-29 | ||
******************************************************************************/ | ||
virtual void Init() = 0; | ||
virtual bool Init() = 0; | ||
/****************************************************************************** | ||
* @brief Close all open sockets and shut down thread | ||
* | ||
|
@@ -103,6 +105,17 @@ class RoveCommServer | |
|
||
inline RoveCommPort GetPort() const { return m_unPort; } | ||
|
||
friend class RoveCommServerManager; | ||
|
||
protected: | ||
/****************************************************************************** | ||
* @brief Optional method that RoveCommServerManager calls before each Read() | ||
* | ||
* @author OcelotEmpire ([email protected]) | ||
* @date 2024-01-20 | ||
******************************************************************************/ | ||
virtual void OnRoveCommUpdate() {} | ||
|
||
protected: | ||
const RoveCommPort m_unPort; | ||
}; | ||
|
@@ -133,8 +146,8 @@ class RoveCommServerManager | |
RoveCommServerManager() {} | ||
|
||
public: | ||
void Init(); | ||
void OpenServerOnPort(RoveCommPort port, RoveCommProtocol protocol = UDP); | ||
bool Init(); | ||
bool OpenServerOnPort(RoveCommPort port, RoveCommProtocol protocol = UDP); | ||
void Shutdown(); | ||
int Write(RoveCommPacket& packet, RoveCommProtocol protocol = UDP); | ||
int SendTo(RoveCommPacket& packet, RoveCommAddress address, RoveCommProtocol protocol = UDP); | ||
|
@@ -192,7 +205,7 @@ class RoveCommServerManager | |
std::map<RoveCommDataId, RoveCommCallback> m_mCallbacks; | ||
std::deque<RoveCommPacket> m_dqPacketQueue; | ||
|
||
bool m_bStopThread; | ||
bool m_bStopThread = false; | ||
std::thread m_thNetworkThread; | ||
std::mutex m_muQueueMutex; | ||
}; | ||
|