Skip to content

Socket: adds closeOnDestruction flag to ctor arguments#11041

Closed
denizzzka wants to merge 1 commit into
dlang:masterfrom
denizzzka:socket_dont_destroy
Closed

Socket: adds closeOnDestruction flag to ctor arguments#11041
denizzzka wants to merge 1 commit into
dlang:masterfrom
denizzzka:socket_dont_destroy

Conversation

@denizzzka

@denizzzka denizzzka commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Rationale

There is a case that is not covered by the std.socket.Socket:
When we get a ready-made socket_t from somewhere (from a 3rd-party library, for example), using it idiomatically in the D style, and after it we should just leave the socket "as is", because all other handling of this socket_t is performed by 3rd-party code.

Currently, if we want to do it this way, we have to duplicate the socket:
https://github.com/denizzzka/dpq2/blob/master/src/dpq2/connection.d#L227
and then Socket will close duplicate in desctructor without side-effects.

Solution

closeOnDestruction flag added into ctor arguments, it allows not close underlying system socket in the destructor of Socket

Pre-review checklist

  • I have performed a self-review of my code.
  • If my PR fixes a bug or introduces a new feature, I have added thorough tests.

I think this case doesn't need testing.

  • If my changes are non-trivial and do not concern a reported issue, I have added a changelog entry.

@rikkimax

Copy link
Copy Markdown
Contributor

When I said flag I meant: https://dlang.org/phobos/std_typecons.html#Flag

I'll leave it to others to decide if this is a requirement or not.

@denizzzka denizzzka force-pushed the socket_dont_destroy branch 2 times, most recently from ebee0ae to f72a486 Compare June 18, 2026 11:45
@denizzzka denizzzka force-pushed the socket_dont_destroy branch from f72a486 to c4a3809 Compare June 18, 2026 11:47
@denizzzka denizzzka marked this pull request as ready for review June 18, 2026 11:47
@denizzzka denizzzka requested a review from CyberShadow as a code owner June 18, 2026 11:47
@denizzzka denizzzka closed this Jun 18, 2026
@denizzzka

Copy link
Copy Markdown
Contributor Author

A workaround for this problem was devised: #11040 (comment)

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