-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
utils.go functions to not require os.File #86
Comments
In what situation do you have a fd without os.File? I had that situation when dealing with CGO, but it is quite specific and rare. Could you share more detail about your use case? FYI, I have another lib https://github.com/creack/termios which is lower level and more "generic" expecting fds directly |
The key use case is that I am running into is when using the inherit size:
The |
Thank you for the detail, but this seems like a very specific case, and I don't think it would justify a change in the public api / major version bump. As you mentioned, os.NewFile does the trick and I believe switching to FDs directly would confuse users. Note that a "file-like" object which is not backed by an actual tty/pty will fail those calls with "invalid ioctl for device". Closing for now. Let me know if you have more questions. |
An issue that I just ran with using the FD to create the new os.File object is that when the function with the os.File ends the os.File goes out of scope and gets gc'ed, causing the FD to be closed. |
This is indeed a good use case. I don't think it is wide enough to warrant a breaking change in the api, but would an additional helper work for you? |
The The purpose of TCPConn.File is to give you access to the fd for a TCP connection, so you can do ioctl stuff etc. It would be bad if closing the os.File also closed the TCP connection, so the returned os.File uses a dup of the fd. This pty issue seems like an analogous situation, and I think the same workaround might be appropriate. This would mean there's still no need for additional API surface in creack/pty. |
Would you be open to modify the signature of the functions in utils.go:
to either accept a File-like interface:
or to just require the the File descriptor
myFile.Fd()
instead of the os.File concrete struct?If I am not mistaken otherwise it requires the caller to unnecessarily create a os.File object:
The text was updated successfully, but these errors were encountered: