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

Implement Clone for SocketRef #260

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

AkiraMiyakoda
Copy link
Contributor

Motivation

I sometimes find it useful to pass SocketRef across threads.
However, I need to use Arc<SocketRef> to do that despite that SocketRef itself is essentially an Arc.

SocketIo which also wraps Arc already has clone method. So I believe that we can have SocketRef::clone too.

Solution

This PR implements the Clone trait for SocketRef like SocketIo.

@Totodore
Copy link
Owner

Totodore commented Feb 2, 2024

The primary purpose of SocketRef before being an extractor is to remove the clone method from the inner Arc<Socket> the main reason is to protect the user from memory leaks. If the user for instance builds a HashMap<String, Arc<SocketRef>> and doesn't remove the socket from the hashmap when it is closed, the socket is never freed.

However it is possible to keep this behaviour as you said by creating an Arc<SocketRef>. I'm going to do some research on this to be sure that never freeing the socket doesn't create a bad state in the socketio model.

@Totodore Totodore enabled auto-merge (squash) March 14, 2024 06:35
@Totodore Totodore disabled auto-merge March 14, 2024 06:35
@Totodore Totodore enabled auto-merge (squash) March 14, 2024 06:36
@Totodore Totodore merged commit 39d700a into Totodore:main Mar 14, 2024
12 checks passed
@AkiraMiyakoda AkiraMiyakoda deleted the devel-socketref-clone branch March 17, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants