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

Add SSLSocket#getbyte #438

Merged
merged 1 commit into from
Apr 17, 2021
Merged

Add SSLSocket#getbyte #438

merged 1 commit into from
Apr 17, 2021

Conversation

tenderlove
Copy link
Member

Normal sockets respond to getbyte, so we should make SSLSocket respond
to getbyte as well. This way we can substitute SSLSockets for regular
sockets.

@ioquatix
Copy link
Member

Can we get some tests too?

@rhenium
Copy link
Member

rhenium commented Apr 16, 2021

That's good to have.

However, IO#getbyte returns nil at EOF. SSLSocket should behave in the same way.

CI is failing because String#unpack1 does not exist in Ruby 2.3. It will be dropped sooner or later anyway, but I guess we can simply work around.

@njh
Copy link

njh commented Apr 16, 2021

Just been taking a look at the ruby openssl source code for the first time.

Does this belong in lib/openssl/buffering.rb?
All the other IO functions are there...

@tenderlove
Copy link
Member Author

SSLSocket should behave in the same way.

I'll add a test for it.

CI is failing because String#unpack1 does not exist in Ruby 2.3. It will be dropped sooner or later anyway, but I guess we can simply work around.

Ah, makes sense. I'll add a work around too.

Normal sockets respond to `getbyte`, so we should make SSLSocket respond
to `getbyte` as well.  This way we can substitute SSLSockets for regular
sockets.
@tenderlove
Copy link
Member Author

I added a test for returning nil on EOF. Also moved the IO function to buffering.rb. Thanks @njh for pointing that out!

Copy link
Member

@ioquatix ioquatix left a comment

Choose a reason for hiding this comment

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

Nice work. Good specs. I wonder if we should have direct unit tests against Buffering.

@rhenium rhenium merged commit 03cb3d5 into master Apr 17, 2021
@rhenium rhenium deleted the getbyte branch April 17, 2021 03:42
@rhenium
Copy link
Member

rhenium commented Apr 17, 2021

Thanks!

tenderlove added a commit to tenderlove/ruby-mqtt that referenced this pull request Sep 29, 2021
This backports the getbyte method which was added in this PR:

  ruby/openssl#438

We only add the method to SSLSocket if the method isn't already defined.
I was able to test this with the following program:

```ruby
require 'rubygems'
require 'mqtt'

client = MQTT::Client.connect(
  host: "test.mosquitto.org",
  port: 8883,
  ssl: true
)

client.get
```

Fixes njh#135
tenderlove added a commit to tenderlove/ruby-mqtt that referenced this pull request Sep 29, 2021
This backports the getbyte method which was added in this PR:

  ruby/openssl#438

We only add the method to SSLSocket if the method isn't already defined.
I was able to test this with the following program:

```ruby
require 'rubygems'
require 'mqtt'

client = MQTT::Client.connect(
  host: "test.mosquitto.org",
  port: 8883,
  ssl: true
)

client.get
```

Fixes njh#135
njh pushed a commit to njh/ruby-mqtt that referenced this pull request Jun 15, 2022
This backports the getbyte method which was added in this PR:

  ruby/openssl#438

We only add the method to SSLSocket if the method isn't already defined.
I was able to test this with the following program:

```ruby
require 'rubygems'
require 'mqtt'

client = MQTT::Client.connect(
  host: "test.mosquitto.org",
  port: 8883,
  ssl: true
)

client.get
```

Fixes #135
lwoggardner added a commit to lwoggardner/openssl that referenced this pull request Jun 30, 2024
Companion to getbyte but raise EOFError
Similar to ruby#438
matzbot pushed a commit to ruby/ruby that referenced this pull request Jul 3, 2024
Companion to getbyte but raise EOFError
Similar to ruby/openssl#438

ruby/openssl@c40f70711a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants