Removed asyncHandler and creating new threads now once buffer-vector is complete
This commit is contained in:
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);
|
||||
}
|
||||
buffer = {std::string(buf)};
|
||||
}
|
||||
|
||||
// Append part-packet
|
||||
buffer.push_back(buf);
|
||||
else
|
||||
buffer.push_back(std::string(buf)); // Append part-packet
|
||||
}
|
||||
|
||||
#endif /* C251BA62_6D80_4033_86B6_61F184E6F250 */
|
||||
|
@ -8,8 +8,8 @@
|
||||
/// @param cmd is the command
|
||||
/// @param handler is the handler(char*)-function
|
||||
/// @return Return-code form command
|
||||
int exec(const char* cmd, void (*handler)(char*) = nullptr){
|
||||
const int buf_size = 256;
|
||||
int exec(const char* cmd, void (*handler)(const char*) = nullptr){
|
||||
const int buf_size = 512;
|
||||
char buf[buf_size];
|
||||
|
||||
// Open execution-pipe
|
||||
|
4
main.cpp
4
main.cpp
@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "./helper/exec.hpp"
|
||||
#include "./handler/asyncHandler.hpp"
|
||||
#include "./handler/bufHandler.hpp"
|
||||
|
||||
const std::string tcpdump_baseCmd = "tcpdump -vvv -e -n -X -s0 -i ";
|
||||
|
||||
@ -15,7 +15,7 @@ int main(int argc, char *args[]){
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int exitCode = exec(tcpdump_cmd.c_str(), &asyncHandler);
|
||||
int exitCode = exec(tcpdump_cmd.c_str(), &bufHandler);
|
||||
|
||||
if(exitCode){
|
||||
fprintf(stderr, "\ntcpdump exited with non-zero ExitCode: %d\n Something went wrong! Check tcpdump-output for more information.\n", exitCode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user