Removed asyncHandler and creating new threads now once buffer-vector is complete
parent
f1e8069afd
commit
a0ae919614
@ -1,17 +0,0 @@
|
||||
#ifndef EFFCCB40_3639_4BD4_9649_302F05987909
|
||||
#define EFFCCB40_3639_4BD4_9649_302F05987909
|
||||
|
||||
#include <future>
|
||||
#include <string.h>
|
||||
#include "bufHandler.hpp"
|
||||
|
||||
void asyncHandler(char *buf){
|
||||
// Create a copy of buf for our thread
|
||||
char bufCopy[265];
|
||||
strcpy(bufCopy, buf);
|
||||
|
||||
// \/ Surpress unused warning
|
||||
(void)std::async(std::launch::async, bufHandler, bufCopy);
|
||||
}
|
||||
|
||||
#endif /* EFFCCB40_3639_4BD4_9649_302F05987909 */
|
@ -1,22 +1,24 @@
|
||||
#ifndef C251BA62_6D80_4033_86B6_61F184E6F250
|
||||
#define C251BA62_6D80_4033_86B6_61F184E6F250
|
||||
|
||||
#include <future>
|
||||
#include <string>
|
||||
#include "textPacketHandler.hpp"
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
std::vector<std::string> buffer;
|
||||
void bufHandler(char *buf){
|
||||
void bufHandler(const char *buf){
|
||||
// When first char of buf has text (no tab), we got a new packet
|
||||
if(buf[0] != '\t'){
|
||||
// Submit the just-read text-packet
|
||||
if(buffer.size() != 0) textPacketHandler(buffer);
|
||||
buffer = std::vector<std::string>();
|
||||
// Submit the just-read text-packet in a new thread
|
||||
if(buffer.size() != 0) {
|
||||
(void)std::async(std::launch::async, textPacketHandler, buffer);
|
||||
}
|
||||
|
||||
// Append part-packet
|
||||
buffer.push_back(buf);
|
||||
buffer = {std::string(buf)};
|
||||
}
|
||||
else
|
||||
buffer.push_back(std::string(buf)); // Append part-packet
|
||||
}
|
||||
|
||||
#endif /* C251BA62_6D80_4033_86B6_61F184E6F250 */
|
||||
|
Loading…
Reference in New Issue