Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: io client shared in socketdata #327

Merged
merged 32 commits into from
Jun 5, 2024
Merged

Conversation

Totodore
Copy link
Owner

@Totodore Totodore commented Jun 4, 2024

Motivation

Currently there is no way to access the SocketIo handle from a socket context / handler. The only solution is to store it as a static shared OnceLock in the application code. Having a way to access the SocketIo handle from any context enable two things:

fn handler(io: SocketIo)

Solution

The chosen solution is to store the SocketIo handle in the engine.io socket data. This allow for any socket to have it set at any time.
One other way was to simply propagate the client reference to the handler when events were trigerred. However the main issue with this solution is that when events where trigger from the user side like calling disconnect() on a socket, the use would have to provide the io ref himself.

Todo

  • Improve documentation
  • Update examples.

socketioxide/src/extract/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/extract/socket.rs Fixed Show fixed Hide fixed
socketioxide/src/extract/socket.rs Fixed Show fixed Hide fixed
@Totodore Totodore force-pushed the feat-io-client-in-socketdata branch from c243451 to 9852110 Compare June 4, 2024 14:29
Copy link

github-actions bot commented Jun 4, 2024

🐰Bencher

ReportWed, June 5, 2024 at 13:39:04 UTC
ProjectSocketioxide
Branchfeat-io-client-in-socketdata
Testbedubuntu-latest

⚠️ WARNING: The following Measure does not have a Threshold. Without a Threshold, no Alerts will ever be generated!

  • Latency (latency)

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds CLI flag.

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns)
engineio_packet/decode/Decode packet binary b64➖ (view plot)87.86
engineio_packet/decode/Decode packet message➖ (view plot)38.96
engineio_packet/decode/Decode packet noop➖ (view plot)35.07
engineio_packet/decode/Decode packet ping/pong➖ (view plot)30.85
engineio_packet/decode/Decode packet ping/pong upgrade➖ (view plot)34.99
engineio_packet/encode/Encode packet binary b64➖ (view plot)56.13
engineio_packet/encode/Encode packet message➖ (view plot)30.53
engineio_packet/encode/Encode packet noop➖ (view plot)29.49
engineio_packet/encode/Encode packet open➖ (view plot)288.46
engineio_packet/encode/Encode packet ping/pong➖ (view plot)29.27
engineio_packet/encode/Encode packet ping/pong upgrade➖ (view plot)29.32
extensions/concurrent_get➖ (view plot)6.82
extensions/concurrent_get_inserts➖ (view plot)14.93
extensions/concurrent_inserts➖ (view plot)21.08
socketio_packet/decode/Decode packet ack on /➖ (view plot)268.48
socketio_packet/decode/Decode packet ack on /custom_nsp➖ (view plot)294.92
socketio_packet/decode/Decode packet binary ack (b64) on /➖ (view plot)493.72
socketio_packet/decode/Decode packet binary ack (b64) on /custom_nsp➖ (view plot)525.64
socketio_packet/decode/Decode packet binary event (b64) on /➖ (view plot)575.67
socketio_packet/decode/Decode packet binary event (b64) on /custom_nsp➖ (view plot)599.00
socketio_packet/decode/Decode packet connect on /➖ (view plot)62.51
socketio_packet/decode/Decode packet connect on /custom_nsp➖ (view plot)79.39
socketio_packet/decode/Decode packet event on /➖ (view plot)341.65
socketio_packet/decode/Decode packet event on /custom_nsp➖ (view plot)366.05
socketio_packet/decode/Decode packet event with ack on /➖ (view plot)341.42
socketio_packet/decode/Decode packet event with ack on /custom_nsp➖ (view plot)370.00
socketio_packet/encode/Encode packet ack on /➖ (view plot)116.37
socketio_packet/encode/Encode packet ack on /custom_nsp➖ (view plot)121.30
socketio_packet/encode/Encode packet binary ack (b64) on /➖ (view plot)326.84
socketio_packet/encode/Encode packet binary ack (b64) on /custom_nsp➖ (view plot)331.28
socketio_packet/encode/Encode packet binary event (b64) on /➖ (view plot)403.42
socketio_packet/encode/Encode packet binary event (b64) on /custom_nsp➖ (view plot)428.17
socketio_packet/encode/Encode packet connect on /➖ (view plot)52.09
socketio_packet/encode/Encode packet connect on /custom_nsp➖ (view plot)56.59
socketio_packet/encode/Encode packet event on /➖ (view plot)118.87
socketio_packet/encode/Encode packet event on /custom_nsp➖ (view plot)126.59
socketio_packet/encode/Encode packet event with ack on /➖ (view plot)119.48
socketio_packet/encode/Encode packet event with ack on /custom_nsp➖ (view plot)124.08

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@Totodore Totodore force-pushed the feat-io-client-in-socketdata branch from 44ebe7f to d5eb45e Compare June 4, 2024 14:57
@Totodore Totodore force-pushed the feat-io-client-in-socketdata branch from 854597f to 25ab9d5 Compare June 4, 2024 15:06
@Totodore Totodore added enhancement C-Bug Something isn't working labels Jun 5, 2024
@Totodore Totodore merged commit 170801c into main Jun 5, 2024
19 checks passed
@Totodore Totodore deleted the feat-io-client-in-socketdata branch June 5, 2024 13:44
This was referenced Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant