Server crash after client calls QtTcpSocket::disconnectFromHost();
-
Hello!
I have a server running in linux and a client running in windows.
When the client close the application or lost connection everything works fine, but when the application runs the code:void Network::disconnect() { ... socket->disconnectFromHost(); ... }
The server will crash here::
void SendJSON(json j) { vector <uint8_t> bson = json::to_bson(j); auto s = bson.size(); vector <uint8_t> final; final.push_back(s >> 0); final.push_back(s >> 8); final.push_back(s >> 16); final.push_back(s >> 24); for (int i = 0; i < s; i++) { final.push_back(bson[i]); } if (write(client, &final.front(), final.size()) <= 0) <- at this line the application will crash { connected = false; printf("connection failed\n"); close(client); piThreadCreate(CheckForConnections); } }
Is the problem that I'm using QtTcpSocket for the client and not for the server and if so, how can I disconnect in a safe way without crashing the server or closing the application?
-
Hi and welcome to devnet,
What are you using of the server ?
Please provide the stack trace of your crash.
-
I'm new to linux and I dont know how can I get the stack trace?
The server is running on a RaspberryPI.
The RaspberryPI is controlling my boiler and gathering some information like temperature, etc.
And the server is sending that information to the client so I can watch my boiler on my pc even when I'm not home. -
Use gdb to run your application.
-
This is the stack trace:
Thread 5 "test" received signal SIGPIPE, Broken pipe. [Switching to Thread 0xb4fff450 (LWP 7463)] __GI___libc_write (nbytes=52, buf=0xb50008a0, fd=5) at ../sysdeps/unix/sysv/linux/write.c:26 26 ../sysdeps/unix/sysv/linux/write.c: No such file or directory.
-
Are you using a QTcpServer ?
-
If not, are you handling that signal ? See here for some suggestions related to that.
-
Sorry, I currently don't know although I am also intrigued.