Comments (7)
In the example shown above there is only one WebSocket instantiated and then used in reader and writer inside the same process. Reader wants to read data using ::SSL_read
in function receiveBytes
and writer wants to send the data using the same instance of websocket (sendBytes
).
Mutex to protect SSL members is locked by reader and therefore the writer can't send.
I doubt that this is a valid use case at all. Reader and writer shall have their own instances of web socket and not share the same one. @aleks-f ?
from poco.
To clarify, my project involves a WebSocket client that is designed to be receptive to messages from the server at any moment. Given this requirement, it's practical to have a dedicated thread constantly monitoring the WebSocket connection for incoming data. Further, the same client must be capable of sending messages at any time, as it interacts with user-generated input. This design rationale underpins the structure of my code example, which I hope is now more understandable.
The scenario I've described is typical for applications that produce and consume real-time data and the straightforward implementation I've provided is effective when using a plain WebSocket. Problems arise when I try to use a Secure WebSocket because reading from the WebSocket prevents any writing.
from poco.
@acarioni , would it be possible for you to have two instances of websockets: one for reading and another completely independent for writing to the server?
from poco.
Do you mean two Websocket connections, one for reading and one for writing, or two Websocket objects sharing the same connection?
In my case, the first alternative is not acceptable but the second one is.
from poco.
Having two Websocket objects would definitely solve locking issue. Is it possible for you to test whether it work properly on one connection in your situation?
from poco.
After implementing the suggested changes, the program still hangs.
The reason is that both ws
and ws2
(see the code below) reference the same SecureSocketImpl instance. Consequently, this shared instance's mutex becomes a contention point, as it is simultaneously accessed by SecureSocketImpl::receiveBytes and SecureSocketImpl::sendBytes.
// same as before ...
WebSocket ws(cs, request, response);
WebSocket ws2(ws);
Reader rdr(ws);
Poco::Thread tr;
tr.start(rdr);
Writer wrt(ws2);
Poco::Thread tw;
tw.start(wrt);
tr.join();
tw.join();
from poco.
@acarioni what you are doing is not thread-safe, you can't safely access the same SSL object from multiple threads:
openssl/openssl#20446 (comment)
You should decouple those threads with notification queues and do the I/O in one thread only.
from poco.
Related Issues (20)
- GitHub runner: Linux thread sanitizer tests fail with "unexpected memory mapping"
- ODBC Unicode wrappers do not check for null length pointers
- On Poco::Buffer<char> deallocation, free(): invalid next size (normal) HOT 2
- FAILED: bin/libPocoActiveRecord.dll lib/libPocoActiveRecord.dll.a HOT 1
- Upgrade bundled SQLite to 3.45.2
- HTTP cookie specification update HOT 2
- why ini file don't support write, is it difficult? HOT 1
- Checksum mismatch for release 1.13.3 HOT 6
- RecordSet issue since 1.10.0
- SocketStream messages doesn't send, and send after close socket.
- SQLChannel stops logging on LoggingSubsystem shutdown HOT 1
- Build Error in gcc 8 with POCO 1.13.0 Release. HOT 3
- decodeWord adds spaces at folding borders, when there are special characters encoded
- Serializable Isolation level for SQLite Databases
- Socket::available Causes Connection Reset by Peer on Windows UDP Sockets HOT 3
- SetSourceIP Error
- Postgres CMakeList.txt HOT 1
- Using passive mode, it seems that it has not been converted to data connection
- The load balancing issue in Poco::ActiveThreadPool
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from poco.