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

fifo: add new fifo package for named pipes #4665

Merged
merged 6 commits into from
Sep 17, 2018
Merged

fifo: add new fifo package for named pipes #4665

merged 6 commits into from
Sep 17, 2018

Conversation

nickethier
Copy link
Member

No description provided.

Copy link
Member

@schmichael schmichael left a comment

Choose a reason for hiding this comment

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

Need tests!

We haven't made any changes to r-clientv2 yet. This could go into master and we could rebase.

winio "github.com/Microsoft/go-winio"
)

const PipeBufferSize = int(^uint16(0))
Copy link
Member

Choose a reason for hiding this comment

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

Comment

return Open(path)
}

func Open(path string) (io.ReadWriteCloser, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Hm, should we make an OpenReader and OpenWriter API to avoid misuse? New could return a Reader as it should be the reader's responsibility to create the fifo as needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I like this. The writer should also always be the one to close it I think so New and OpenReader will just return an io.Reader and OpenWriter can return a io.WriteCloser.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I don't think we will ever need an OpenReader. Plus it doesn't work on windows since creating the pipe returns a listener.

Copy link
Member

Choose a reason for hiding this comment

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

The logger will read and write into the log file. And we'll need a writer for the driver-side.

The read side will close when the write side closes, so I don't think the reader will need to be a Close method but it wouldn't hurt. Might be useful for tests or future use cases.

The Windows and Unix APIs should match to avoid accidental build errors on the Windows side.

"syscall"
)

func New(path string) (io.ReadWriteCloser, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Comment


const PipeBufferSize = int(^uint16(0))

type FIFO struct {
Copy link
Member

Choose a reason for hiding this comment

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

Let's not export it so the Window's version doesn't export a different API from the non-Window's version.

}

func (f *FIFO) Close() error {
if f.conn != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Conn.Close is threadsafe and File.Close not being threadsafe was considered a bug: golang/go#7970

Perhaps we should lock around the conn check? The only way to unblock a blocked Read() or Write() is to Close it.

}

// OpenWriter opens a fifo that already exists and returns a writer for it
func OpenWriter(path string) (io.WriteCloser, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just open and return a readwritecloser?

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha this is what I initially had but @schmichael thought having seperate funcs for Reader/Writer would be beneficial.

I settled on only having a writer here since New returns a reader. For our use, the data will be unidirectional so New would be the only place we want a reader.

This can totally be a ReaderWriterCloser, it just didn't make sense to me to ever need to read from the pipe (other than for the caller of New).

Copy link
Contributor

Choose a reason for hiding this comment

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

Won't bike shed on this since it will do what we need but I would have both open/new return readwriteclosers

@nickethier
Copy link
Member Author

Added an additional test and ran them against windows

}

// OpenWriter opens a fifo that already exists and returns a writer for it
func OpenWriter(path string) (io.WriteCloser, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't bike shed on this since it will do what we need but I would have both open/new return readwriteclosers

@nickethier nickethier merged this pull request into r-clientv2 Sep 17, 2018
@nickethier nickethier deleted the f-fifo branch September 17, 2018 17:23
dadgar pushed a commit that referenced this pull request Sep 17, 2018
* fifo: add new fifo package for named pipes
dadgar pushed a commit that referenced this pull request Sep 18, 2018
* fifo: add new fifo package for named pipes
schmichael pushed a commit that referenced this pull request Oct 16, 2018
* fifo: add new fifo package for named pipes
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants