Skip to content
Snippets Groups Projects
Commit 921c9409 authored by SEMuser's avatar SEMuser
Browse files

Memory leak fixed, at creating server threads.

By Kiss Adam
parent 0150bc0d
Branches
No related tags found
No related merge requests found
semmodbus semmodbus
semmodbus_server.layout
...@@ -4,15 +4,15 @@ void jelenletjelzo::poll(modbus_t* modbus){ ...@@ -4,15 +4,15 @@ void jelenletjelzo::poll(modbus_t* modbus){
modbus_flush(modbus); //Flush modbus buffers modbus_flush(modbus); //Flush modbus buffers
modbus_set_slave(modbus, 1); //Set slave address to 1 modbus_set_slave(modbus, 1); //Set slave address to 1
uint16_t asd; uint16_t buff;
if (modbus_read_input_registers(modbus, 0x00, 1, &asd) == -1) { //read 1 (third arg) input register, from register index 0(sec arg), to the address of asd if (modbus_read_input_registers(modbus, 0x00, 1, &buff) == -1) { //read 1 (third arg) input register, from register index 0(sec arg), to buff
fprintf(stderr, "Error %d while reading: %s\n", errno, modbus_strerror(errno)); fprintf(stderr, "Error %d while reading: %s\n", errno, modbus_strerror(errno));
return; return;
} }
m.lock(); //lock semaphore m.lock(); //lock semaphore
stat = asd&(1<<7); //set stat stat = buff&(1<<7); //set stat
m.unlock(); //unlock m.unlock(); //unlock
} }
......
...@@ -49,7 +49,7 @@ void serveConnect(Socket s){ ...@@ -49,7 +49,7 @@ void serveConnect(Socket s){
for(auto* i: Devices){ for(auto* i: Devices){
if(i->getName()==req_device){ if(i->getName()==req_device){
found = true; found = true;
std::stringstream ss; ///TODO: clear the code, skip stringstream std::stringstream ss; ///TODO: clean the code, skip stringstream
ss << i->getResp(json_request); ss << i->getResp(json_request);
std::string ans= ss.str(); std::string ans= ss.str();
...@@ -91,8 +91,6 @@ void SocketListener(){ ...@@ -91,8 +91,6 @@ void SocketListener(){
std::cout << "Socket Listener thread started\n\n"; std::cout << "Socket Listener thread started\n\n";
std::set_terminate(socket_thread_terminator); std::set_terminate(socket_thread_terminator);
std::list<std::thread*> Connects;
int portno; int portno;
Socket accpeted; Socket accpeted;
socklen_t clilen; socklen_t clilen;
...@@ -126,6 +124,7 @@ void SocketListener(){ ...@@ -126,6 +124,7 @@ void SocketListener(){
if (accpeted < 0) { if (accpeted < 0) {
perror("ERROR on accept"); perror("ERROR on accept");
} }
Connects.push_back(new std::thread(serveConnect, accpeted)); ///TODO: fix memory leak std::thread serving_thread (serveConnect, accpeted);
serving_thread.detach();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment