{"action":"opened","issue":{"url":"https://api.github.com/repos/log4cplus/log4cplus/issues/152","repository_url":"https://api.github.com/repos/log4cplus/log4cplus","labels_url":"https://api.github.com/repos/log4cplus/log4cplus/issues/152/labels{/name}","comments_url":"https://api.github.com/repos/log4cplus/log4cplus/issues/152/comments","events_url":"https://api.github.com/repos/log4cplus/log4cplus/issues/152/events","html_url":"https://github.com/log4cplus/log4cplus/issues/152","id":139048994,"number":152,"title":"Building a multi-threaded server using QThreads - blocking read does not return","user":{"login":"kaufManu","id":5639197,"avatar_url":"https://avatars.githubusercontent.com/u/5639197?v=3","gravatar_id":"","url":"https://api.github.com/users/kaufManu","html_url":"https://github.com/kaufManu","followers_url":"https://api.github.com/users/kaufManu/followers","following_url":"https://api.github.com/users/kaufManu/following{/other_user}","gists_url":"https://api.github.com/users/kaufManu/gists{/gist_id}","starred_url":"https://api.github.com/users/kaufManu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaufManu/subscriptions","organizations_url":"https://api.github.com/users/kaufManu/orgs","repos_url":"https://api.github.com/users/kaufManu/repos","events_url":"https://api.github.com/users/kaufManu/events{/privacy}","received_events_url":"https://api.github.com/users/kaufManu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-07T18:05:56Z","updated_at":"2016-03-07T18:05:56Z","closed_at":null,"body":"Hello,\r\n\r\nI want to build a multi-threaded application which uses `log4cplus::helpers::Socket`s and a `log4cplus::helpers::ServerSocket` respectively. Because I need to display the log statements in an existing GUI, which was built with Qt, I'm using `QThreads ` to manage the acceptor thread on the server and to dispatch threads that read from the client. I am encountering an issue that the blocking call to `log4cplus::helpers::Socket::read` does not return immediately when I call the `close` function on the respective socket - it only returns and breaks when the next log statement has arrived. It is very well possible that this problem is introduced by the way I handle my `QThreads`, so I'm going to post in more detail in the following what I'm doing exactly. If you have any suggestions / recommondations for a better implementation of this use case, they are very welcome! I am using version 1.1.3 rc 4.\r\n\r\nGenerally I have the following setup: A dispatcher thread (which is a `QThread` as mentioned before) continuously listens for incoming connections. It's run method looks like this:\r\n\r\n```\r\nmStopRequested = false;\r\n\r\n// create the server socket\r\n// mServerSocket is wrapped in a smart pointer\r\nmServerSocket.reset(new log4cplus::helpers::ServerSocket(PORT));\r\n\r\nif (!mServerSocket->isOpen()\r\n  {\r\n   std::cout << \"ERROR: Could not open server socket\" << std::endl;\r\n   return;\r\n}\r\n\r\nwhile (!mStopRequested)\r\n{\r\n  // wait for incoming connection\r\n  log4cplus::helpers::Socket _socket = mServerSocket->accept();\r\n\r\n  if (!mStopRequested)\r\n  {\r\n    dispatch(_socket);\r\n  }\r\n}\r\n```\r\nThe `dispatch` function creates a new worker thread (which is again a `QThread`). I only expect very few client connections, so I chose not to use a thread pool. The client socket returned from `accept` is passed to this worker in the constructor. The run method of a worker looks like the following (`mSocket` is the client socket passed via the constructor):\r\n\r\n ```\r\n std::cout << \"start worker\" << std::endl;\r\n  mStopRequested = false;\r\n\r\n  while (!mStopRequested)\r\n  {\r\n    if (!mSocket.isOpen())\r\n    {\r\n      std::cout << \"ERROR: socket not open - abort\") << std::endl;\r\n      mStopRequested = true;\r\n      continue;\r\n    }\r\n\r\n    // read size of the message\r\n    log4cplus::helpers::SocketBuffer _msgSizeBuffer(sizeof(unsigned int));\r\n\r\n    if (!mSocket.read(_msgSizeBuffer)) // here is the problem\r\n    {\r\n      if (errno == 10054)\r\n      {\r\n        std::cout << \"Connection reset on client side - abort\" << std::endl;\r\n      }\r\n      else\r\n      {\r\n        std::cout<< \"ERROR: error reading size of message from buffer - abort\" << std::endl;\r\n      }\r\n      mStopRequested = true;\r\n      continue;\r\n    }\r\n\r\n    unsigned int _msgSize = _msgSizeBuffer.readInt();\r\n\r\n    // read the message\r\n    log4cplus::helpers::SocketBuffer _buffer(_msgSize);\r\n    if (!mSocket.read(_buffer))\r\n    {\r\n      std::cout << \"ERROR: error reading message from buffer - abort\" << std::endl;\r\n      mStopRequested = true;\r\n      break;\r\n    }\r\n\r\n    log4cplus::spi::InternalLoggingEvent _event = log4cplus::helpers::readFromBuffer(_buffer);\r\n\r\n    // do something with the message\r\n    // ...\r\n  }\r\n```\r\nThe problem is that `mSocket.read(_msgSizeBuffer)` does not break immediately when I call `mSocket.close()` from the outside. It only breaks when another message arrives. Is this expected behaviour? Or am I messing things up because I access the socket from multiple threads? Would you recommend to use `log4cplus::thread::AbstractThread` rather than `QThreads`? I realize that this question might be very localized. So feel free to just point me towards some examples that I might not have found yet or highlight some design issues that I'm not aware of. In any case, thanks a lot for your help!\r\n"}}