Hi . I'm so newbie in Tokio, in particular, and in Rust, in general .
I would like to control the number of readers inside a TCP server developed with Tokio to avoid having problems with attacks . I want to have a poll with a predefined number of threads . Those threads will represent readers .
On the other hand, I want to have just one writer that access concurrently to a resource inside the server .
I have seen tokio::sync::RwLock, that let me have multiple readers and one writer . What I'm scared is having problems to receive an attack of having more readers than machine can handle .
This TCP server will represent a multiple reader/one writer paradigm sharing a dictionary to control key / value elements .
Is there any way using RwLock to control this ? is it better to investigate through channels ?
This type of lock allows a number of readers or at most one writer at any point in time.
The write portion of this lock typically allows modification of the underlying data
(exclusive access) and the read portion of this lock typically allows for read-only
access (shared access).
In comparison, a [ Mutex ]
(tokio::sync::Mutex - Rust) does not distinguish between
readers or writers that acquire the lock, therefore blocking any tasks waiting for the
lock to become available. An RwLock will allow any number of readers to acquire
the lock as long as a writer is not holding the lock.
What I'm trying to control is that number of readers . Semaphore might be a solution . I'll give a try . Thanks Alice .