Replies: 1 comment
-
This issue is stale because it has been open for 365 days with no activity. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
I'm using WebSocket in worker thread to receive response from server. So in main loop of worker thread I call
receiveFrame()
. Everything is fine until I want to close app. I send signal to process where I start my close procedure. Joining threads etc. So far so good. I only have problem with WebSockets because they are blocking worker thread and waiting forreceiveFrame()
for server response or TimeoutException. I figure out that I can call_webSocket->shutdown()
from other thread and that looks good but I'm not sure is it safe to do from other thread. There is no documentation about this and from reading code I'm still not sure.Q_1: Can someone confirm is it safe and if not what is the correct way? I already tried sending signal directly to thread but that won't unblock
poll()
orrecv()
. (Maybe it is waiting in SSL part and signal do not cancel this, not sure).When using
Poco::Net::WebSocket
with long receive time.So worker is calling in loop: (loop is
while(my_atomic_bool_is_working)
)Few more questions if someone can answer.
Q_2: Previously I was using something like this:
Such approach was working great with signals because
poll
from documentation will be canceled by signal. But after some time of working such WebSocket I get always delayed last response. Not sure why so thats why I resign from this solution. It looks like I received that response but I was missing "extra run" to process such frame.Q_3: Why there is no receiveFrame method that won't throw exception? Isn't it bad that normal flow is handled with exception? I would like to call
receiveFrame
and get empty/null frame if no response from server. E.g. I would like to check multiple websockets with max wait time of 100ms but now I would get a lot of TimeoutExceptionsQ_4: Is there way to process multiple websockets in signle thread? Now I have separate thread for every websocket. It would be more convenient to check in loop multiple webosockets is there any data and then sleep/maybe call
select
on multiple sockets. (Not an expert) I tried to achieve something like this to achieve but every solution failed.Thank you.
It would be very nice if such responses could be in Poco could be easy to figure out either from documentation or Poco example codes. I couldn't find responses after 2 years of using Poco in my project.
Tags:
thread, WebSocket, WebSocket::shutdown, threadsafe, cancel receiveFrame, abort receiveFrame, TimeoutException, receive timout
Beta Was this translation helpful? Give feedback.
All reactions