Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

[IO] add handle copy function #120

Closed
wants to merge 1 commit into from
Closed

Conversation

azjezz
Copy link
Contributor

@azjezz azjezz commented Apr 2, 2020

closes #44

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 2, 2020
@azjezz azjezz marked this pull request as ready for review April 2, 2020 22:33
Copy link
Contributor

@lexidor lexidor left a comment

Choose a reason for hiding this comment

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

I reviewed this to get the ball rolling on this function, since it is a very useful low level operation

*/
async function copy(
<<__AcceptDisposable>> ReadHandle $source,
<<__AcceptDisposable>> WriteHandle $target,
Copy link
Contributor

Choose a reason for hiding this comment

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

Personal preference, but isn't $source $destination a more natural pair?

}

if (!$source->isEndOfFile()) {
await copy($source, $target, $chunk_size, $timeout_seconds);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you implemented this via recursive call because of the DontAwaitInALoopLinter?
I guess we could violate this here, since this has the exact same performance characteristics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess you implemented this via recursive call because of the DontAwaitInALoopLinter?

yes

I guess we could violate this here, since this has the exact same performance characteristics.

why violate the linter rule if we can avoid it? 😛

Copy link
Contributor

Choose a reason for hiding this comment

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

Suppress the linter.

why violate the linter rule if we can avoid it?

Because violating the linter rule doesn't consume stack frames, leading to fatals on large files ;)

src/io/copy.php Show resolved Hide resolved
src/io/copy.php Show resolved Hide resolved
* If `$chunk_size` is `null`, there is no limit on the chunk size - this function will
* copy the content of $source all at once.
*/
async function copy(
Copy link
Contributor

Choose a reason for hiding this comment

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

To match the naming conventions, copyAsync() or is this handled by the gen rewriter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure about this. other functions in File\ don't use the _async suffix.

Copy link
Contributor

Choose a reason for hiding this comment

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

it should be copy_async

Other functions in File\ do not return Awaitables, so do not have the suffix (if that's not the case, it's a bug that needs fixing)

tests/io/CopyTest.php Show resolved Hide resolved
@jjergus jjergus requested a review from fredemmott April 17, 2020 00:11
@fredemmott
Copy link
Contributor

This is going to need some reworking with the changes to read api and Upcoming Corresponding changes to write api

Additionally, there’ll be the scope for some optimization , e.g if real file to socket, use sendfile()

Copy link
Contributor

@fredemmott fredemmott left a comment

Choose a reason for hiding this comment

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

Also, sorry, I will not be merging this - or anything similar - until the APIs are stable after moving over to OS\FileDescriptor; this is not about the quality of the code, just timing. It definitely should be here in some form, but it is not a good time for API expansion at present.

HSL IO is still truly experimental, and unsuitable for use in any more other than standalone CLI - all error reporting is broken in HTTP and CLI server modes (which is fixed by the move to OS\FileDescriptor)

We're also restricting internal callers at Facebook, for both of the same reasons

@fredemmott
Copy link
Contributor

The previous blockers are gone - closing at it would now need to be against the main HHVM repo.

@fredemmott fredemmott closed this Jul 9, 2021
@azjezz azjezz deleted the copy-stream branch July 10, 2021 01:30
@azjezz
Copy link
Contributor Author

azjezz commented Jul 10, 2021

will open a PR against hhvm :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[IO] add stream/handle copy function
4 participants