Skip to content

Make IO::Socket::SSL do the IO::Socket role #21

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

Merged
merged 1 commit into from
Oct 10, 2020
Merged

Make IO::Socket::SSL do the IO::Socket role #21

merged 1 commit into from
Oct 10, 2020

Conversation

jjatria
Copy link
Contributor

@jjatria jjatria commented Oct 10, 2020

This makes it possible to assign an IO::Socket::SSL to a variable
with an IO::Socket constraint. Without this, doing so would result
in a hard to understand segmentation fault.

In order for this work, the put method is also naively implemented.

This fixes #20 and likely #3.

@@ -11,7 +11,6 @@ sub v6-split($uri) {
$host ?? ($host, $port) !! $uri;
}

has Str $.encoding = 'utf8';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed because otherwise applying the role would die with Attribute '$!encoding' already exists in the class 'IO::Socket::SSL', but a role also wishes to compose it. However, it should be safe to remove, since IO::Socket provides the same default: https://github.com/rakudo/rakudo/blob/master/src/core.c/IO/Socket.pm6#L3

@@ -126,6 +125,10 @@ method print(Str $s) {
$!ssl.write($s);
}

method put(Str $s) {
$!ssl.write($s ~ "\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use $.nl-out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted. I changed it to $!nl-out, or do you think it's preferable to use the accessor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally try to avoid calling private accessors that come from outside the class (composed in from roles). It is fine (to me) for IO::Socket to call $!nl-out because it is declared in that class and thus the implementation details can be hidden. Using $.nl-out outside of IO::Socket is ok because it ensures it will use the public interface (maybe in the future there is no $!nl-out, only method nl-out { ... })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Amended

This makes it possible to assign an IO::Socket::SSL to a variable
with an IO::Socket constraint. Without this, doing so would result
in a hard to understand segmentation fault.

In order for this work, the `put` method is also naively implemented.
@ugexe ugexe merged commit 847c28e into raku-community-modules:master Oct 10, 2020
@jjatria jjatria deleted the socket-role branch October 10, 2020 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot assign to a variable with an IO::Socket constraint
2 participants