Skip to content

Commit 2a9874d

Browse files
bemyakrgbkrk
authored andcommitted
feat: Allow overriding block_on_no_clients queue param
In the current implementation, when a SUB provider is restarted, the library just hangs without detecting connection loss. This happens because on disconnect a client is kicked out of the queue, as since for all the socket queues block_on_no_clients is set to true, it hangs indefinitely. I'm unsure what would be the effect of setting block_on_no_clients to false globally (though it seems reasonable), so in this PR an ability to override this value is introduced via SocketOptions is added.
1 parent 07c65dc commit 2a9874d

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

src/dealer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Drop for DealerSocket {
3131
#[async_trait]
3232
impl Socket for DealerSocket {
3333
fn with_options(options: SocketOptions) -> Self {
34-
let fair_queue = FairQueue::new(true);
34+
let fair_queue = FairQueue::new(options.block_on_no_clients);
3535
Self {
3636
backend: Arc::new(GenericSocketBackend::with_options(
3737
Some(fair_queue.inner()),

src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,30 @@ pub enum SocketEvent {
169169
Disconnected(PeerIdentity),
170170
}
171171

172-
#[derive(Default)]
172+
#[derive(Debug, Clone)]
173173
pub struct SocketOptions {
174174
pub(crate) peer_id: Option<PeerIdentity>,
175+
pub(crate) block_on_no_clients: bool,
176+
}
177+
178+
impl Default for SocketOptions {
179+
fn default() -> Self {
180+
Self {
181+
peer_id: Default::default(),
182+
block_on_no_clients: true,
183+
}
184+
}
175185
}
176186

177187
impl SocketOptions {
178188
pub fn peer_identity(&mut self, peer_id: PeerIdentity) -> &mut Self {
179189
self.peer_id = Some(peer_id);
180190
self
181191
}
192+
pub fn block_on_no_clients(&mut self, block_on_no_clients: bool) -> &mut Self {
193+
self.block_on_no_clients = block_on_no_clients;
194+
self
195+
}
182196
}
183197

184198
#[async_trait]

src/pull.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct PullSocket {
2525
#[async_trait]
2626
impl Socket for PullSocket {
2727
fn with_options(options: SocketOptions) -> Self {
28-
let fair_queue = FairQueue::new(true);
28+
let fair_queue = FairQueue::new(options.block_on_no_clients);
2929
Self {
3030
backend: Arc::new(GenericSocketBackend::with_options(
3131
Some(fair_queue.inner()),

src/rep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Drop for RepSocket {
4343
#[async_trait]
4444
impl Socket for RepSocket {
4545
fn with_options(options: SocketOptions) -> Self {
46-
let fair_queue = FairQueue::new(true);
46+
let fair_queue = FairQueue::new(options.block_on_no_clients);
4747
Self {
4848
backend: Arc::new(RepSocketBackend {
4949
peers: DashMap::new(),

src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Drop for RouterSocket {
3232
#[async_trait]
3333
impl Socket for RouterSocket {
3434
fn with_options(options: SocketOptions) -> Self {
35-
let fair_queue = FairQueue::new(true);
35+
let fair_queue = FairQueue::new(options.block_on_no_clients);
3636
Self {
3737
backend: Arc::new(GenericSocketBackend::with_options(
3838
Some(fair_queue.inner()),

src/sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl SubSocket {
156156
#[async_trait]
157157
impl Socket for SubSocket {
158158
fn with_options(options: SocketOptions) -> Self {
159-
let fair_queue = FairQueue::new(true);
159+
let fair_queue = FairQueue::new(options.block_on_no_clients);
160160
Self {
161161
backend: Arc::new(SubSocketBackend::with_options(
162162
Some(fair_queue.inner()),

0 commit comments

Comments
 (0)