Add vectored io api: SSL_writev by alfaloo · Pull Request #27768 · openssl/openssl · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Add vectored io api: SSL_writev #27768

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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Conversation

alfaloo
Copy link

@alfaloo alfaloo commented Jun 5, 2025

Checklist
  • documentation is added or updated
  • tests are added or updated

Evident from the discussions in the linked issue page, I believe that the use case of SSL_writev is compelling enough that we can consider replacing/updating all those internal write calls to work for ssl_writev, then just change ssl_write to be a simplified wrapper to ssl_writev. the performance of the ssl_write use case will not be affected as we are just additionally iterating through the array of iovec structures.

With regards to the problem of iovec not available on all platforms, we can create a compatibility layer that abstracts away the differences.

Fixes #20918

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Jun 5, 2025
@alfaloo alfaloo force-pushed the ssl_writev branch 6 times, most recently from 5b335bf to 5257d5b Compare June 5, 2025 03:53
@paulidale paulidale added branch: master Merge to master branch triaged: feature The issue/pr requests/adds a feature tests: present The PR has suitable tests present approval: review pending This pull request needs review by a committer labels Jun 5, 2025
@mattcaswell
Copy link
Member

Please can you submit a CLA?

https://openssl-library.org/policies/cla/

@alfaloo
Copy link
Author

alfaloo commented Jun 5, 2025

Please can you submit a CLA?

https://openssl-library.org/policies/cla/

Yup emailed it this morning, still pending approval c:

@github-actions github-actions bot added severity: fips change The pull request changes FIPS provider sources severity: ABI change This pull request contains ABI changes labels Jun 5, 2025
@alfaloo alfaloo changed the title Add vectored io api: SSL_writev, SSL_writev_ex, SSL_writev_ex2 Add vectored io api: SSL_writev Jun 6, 2025
@alfaloo
Copy link
Author

alfaloo commented Jun 6, 2025

Thank you everyone for your interest and time in reading through my code! I have implemented changes from most of the comments and I have responded to the rest. I would greatly appreciate it if you could kindly review the PR again for further improvements c:

@kroeckx
Copy link
Member

kroeckx commented Jun 6, 2025

I'm wondering what the behavior of using SSL_MODE_ENABLE_PARTIAL_WRITE should be with this. Should we support this? If we support it, is it then up to the application to figure out which iovecs to remove in the next call, and how to update the data pointers in the iovec?

@kroeckx
Copy link
Member

kroeckx commented Jun 10, 2025

So Linux has a pwritev(), that supports an additional offset. We should consider that for the combination with SSL_MODE_ENABLE_PARTIAL_WRITE.

@alfaloo
Copy link
Author

alfaloo commented Jun 10, 2025

So Linux has a pwritev(), that supports an additional offset. We should consider that for the combination with SSL_MODE_ENABLE_PARTIAL_WRITE.

Sorry wanted to clarify, do you mean SSL_MODE_ENABLE_PARTIAL_WRITE or SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER? I thought SSL_MODE_ENABLE_PARTIAL_WRITE is currently supported for OSSL_IOVECs by storing an offset variable that keeps track of how much we have sent so far? Could I trouble you to expand a little bit on what is the issue we are trying to solve? Thanks in advance

@kroeckx
Copy link
Member

kroeckx commented Jun 10, 2025

In case of SSL_MODE_ENABLE_PARTIAL_WRITE, you don't have to call it with data that was already processed, like in a call to write(). *written will contain how much data has been processed and doesn't need to be passed again when called again. When that flag is not passed, you need to pass exactly the same data.

Since it's in an iovec, you might want to pass the same iovec again, but say how much of the data needs to be skipped. Otherwise, you will need to move data around, or at least update the pointer. But if you're updating the pointer, you might need to have a second copy of the pointer so you can delete it. It's probably easier that we can pass the value of *written back on the next call, or an adjusted version of that if we can remove 1 or more iovecs.

@alfaloo
Copy link
Author

alfaloo commented Jun 13, 2025

@kroeckx I see what you mean now. I was under the impression that removing written data is the responsibility of the caller, I refer to the description of SSL_MODE_ENABLE_PARTIAL_WRITE from SSL_write.pod:

When this flag is set the write functions will also return with success when a partial write has been successfully completed. In this case the write function operation is considered completed. The bytes are sent and a new write call with a new buffer (with the already sent bytes removed) must be started.

However, you make a good point that this can be quite troublesome. Can I clarify that you propose that if the flag is set, we use the value stored inside *written to indicate that the first *written bytes will be skipped during the write procedure?

@alfaloo
Copy link
Author

alfaloo commented Jun 13, 2025

@kroeckx I have updated the SSL_writev such that if the flag is set, we use the value stored inside *written to indicate that the first *written bytes will be skipped during the write procedure. Let me know if this was what you meant. Thank you

@alfaloo alfaloo requested a review from kroeckx June 13, 2025 03:07
@kroeckx
Copy link
Member

kroeckx commented Jun 13, 2025

*written is an output. From your message, I think you want to use it as input too. I would expect a new offset variable that is input only.

@alfaloo
Copy link
Author

alfaloo commented Jun 13, 2025

I was thinking that instead of using two arguments, the *written can first store the offset, but once the method returns, *written will return the new total amount that has been successfully sent. This way, the user can call SSL_writev repeatedly by passing the same *written variable.

Using a separate argument for offset works as well. however, in this case when the SSL_writev returns, should *written contain the amount of bytes newly sent or contain the total number of bytes sent from the beginning of the iovec?

@t-j-h
Copy link
Member

t-j-h commented Jun 16, 2025

I was thinking that instead of using two arguments,

As a general pattern, we have (mostly) moved away from having an in/out parameter for this sort of thing as much as possible so it is clear what is going on in the API calls when looking at the code.

@alfaloo
Copy link
Author

alfaloo commented Jun 16, 2025

@kroeckx @t-j-h Thank you for both of your input. I have updated the SSL_writev to accept an additional argument, offset.

@alfaloo alfaloo requested a review from t8m June 27, 2025 05:52
@alfaloo
Copy link
Author

alfaloo commented Jun 27, 2025

@mattcaswell @kroeckx @t-j-h @t8m Hi everyone, thank you for the feedback that you all have provided. I was hoping to get a status update for this PR. If there are any other requested improvements, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: review pending This pull request needs review by a committer branch: master Merge to master branch severity: ABI change This pull request contains ABI changes severity: fips change The pull request changes FIPS provider sources tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add/design SSL_writev
8 participants

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.