Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with joining/ending thread #333

Open
szycha03 opened this issue Jun 26, 2024 · 0 comments
Open

problem with joining/ending thread #333

szycha03 opened this issue Jun 26, 2024 · 0 comments

Comments

@szycha03
Copy link

Hi,

I have problem with joining threads.
I tried milions of ideas and solution for example: atomic operation for is_runnning bool in threaded server, checking joinable and many many more. The issue is that after i want finish work threads dont join but they work in loop (i dont know why).

I modified a little tcplinuxserver.cpp to work more like a client (i need p2p connection, so my app need to be client and server at same time) Does anyone has any ideas what i am doing wrong?

here is modified HandleConnection method that work in loop:

void LinuxTcpSocketServer::HandleConnection()
{
StreamReader reader(DEFAULT_BUFFER_SIZE);
string request, response;
reader_port = this->Connect();
std::cout << "LinuxTcpSocketServer::HandleConnection::port:: " << reader_port << std::endl;
reader.Read(request, reader_port, DEFAULT_DELIMITER_CHAR);
std::cout << "LinuxTcpSocketServer::HandleConnection::request" << request << std::endl;
this->ProcessRequest(request, response);

response.append(1, DEFAULT_DELIMITER_CHAR);
StreamWriter writer;
if (!writer.Write(response, reader_port))
{
throw JsonRpcException(Errors::ERROR_SERVER_CONNECTOR, "Could not write request");
}
std::cout << "LinuxTcpSocketServer::HandleConnection::response" << response << std::endl;
//CleanClose(reader_port); // ? powinno zamykac?
close(reader_port);
return;
}

here are logs:

logs.txt

Sorry i am kind a new to threads and dont fully understand how it works.
Thanks for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant