-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate Thread of Receiving and Parsing (#2)
- Loading branch information
1 parent
b17dd74
commit c286ace
Showing
6 changed files
with
43 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
#ifndef _PKT_PARSE_H_ | ||
#define _PKT_PARSE_H_ | ||
|
||
class Pkt_Parse {}; | ||
#include "pkt_def.h" | ||
#include "pkt_receive.h" | ||
#include <iostream> | ||
#include <queue> | ||
|
||
// TODO: Implement options for parsing. | ||
|
||
class Pkt_Parse { | ||
public: | ||
Pkt_Parse(Pkt_Receive& pkt_receive, std::mutex& mtx_pkt_receive); | ||
|
||
bool parse(); | ||
|
||
private: | ||
Pkt_Receive& pkt_receive; | ||
std::mutex& mtx_pkt_receive; | ||
}; | ||
|
||
#endif |
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 |
---|---|---|
@@ -1 +1,20 @@ | ||
#include "pkt_parse.h" | ||
|
||
Pkt_Parse::Pkt_Parse(Pkt_Receive& pkt_receive, std::mutex& mtx_pkt_receive) | ||
: pkt_receive(pkt_receive), mtx_pkt_receive(mtx_pkt_receive) {} | ||
|
||
bool Pkt_Parse::parse() { | ||
while (true) { | ||
std::unique_lock<std::mutex> lock(mtx_pkt_receive); | ||
auto&& queue = pkt_receive.getPayloadQueue(); | ||
if (auto queue_size = queue.size(); queue_size > 0) { | ||
std::cout << "Number of Payloads: " << queue_size << std::endl; | ||
auto payload = queue.front(); | ||
queue.pop(); | ||
std::cout << "Payload Size: " << payload.size() << std::endl; | ||
} else if (!pkt_receive.isRunning()) { | ||
std::cout << "Finished parsing and receiving has stopped." << std::endl; | ||
return true; | ||
} | ||
} | ||
} |
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