Skip to content

Commit

Permalink
use sequential client id
Browse files Browse the repository at this point in the history
  • Loading branch information
github-af committed Sep 7, 2024
1 parent 7121187 commit f95aed2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! is of type `Heartbeat`, `Abort` or `End`. Then the `data_length` will be set to 0 by the
//! message constructor and the data chunk will be fully padded with zeros.

use std::{fmt, io};
use std::{fmt, io, sync};

pub enum Error {
Io(io::Error),
Expand Down Expand Up @@ -95,8 +95,10 @@ const ID_END: u8 = 0x04;

pub(crate) type ClientId = u32;

static CLIENT_ID_COUNTER: sync::atomic::AtomicU32 = sync::atomic::AtomicU32::new(0);

pub(crate) fn new_client_id() -> ClientId {
rand::random::<ClientId>()
CLIENT_ID_COUNTER.fetch_add(1, sync::atomic::Ordering::Relaxed)
}

pub struct Message(Vec<u8>);
Expand Down

0 comments on commit f95aed2

Please sign in to comment.