-
Notifications
You must be signed in to change notification settings - Fork 126
Switch to syscall.Open on Darwin #36
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
jc-m
wants to merge
1
commit into
jacobsa:master
Choose a base branch
from
jc-m:issue-35
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,22 @@ type termios struct { | |
| c_ispeed speed_t | ||
| c_ospeed speed_t | ||
| } | ||
| type Port struct{ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be exported (i.e. capitalized). |
||
| fd int | ||
| } | ||
|
|
||
| func (p Port) Close() error { | ||
| return syscall.Close(p.fd) | ||
| } | ||
|
|
||
| func (p Port) Read(b []byte) (n int, err error) { | ||
| return syscall.Read(p.fd, b) | ||
| } | ||
|
|
||
| func (p Port) Write(b []byte) (n int, err error) { | ||
| return syscall.Write(p.fd,b) | ||
| } | ||
|
|
||
|
|
||
| // setTermios updates the termios struct associated with a serial port file | ||
| // descriptor. This sets appropriate options for how the OS interacts with the | ||
|
|
@@ -199,8 +215,8 @@ func convertOptions(options OpenOptions) (*termios, error) { | |
| func openInternal(options OpenOptions) (io.ReadWriteCloser, error) { | ||
| // Open the serial port in non-blocking mode, since otherwise the OS will | ||
| // wait for the CARRIER line to be asserted. | ||
| file, err := | ||
| os.OpenFile( | ||
| fd, err := | ||
| syscall.Open( | ||
| options.PortName, | ||
| syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NONBLOCK, | ||
| 0600) | ||
|
|
@@ -213,7 +229,7 @@ func openInternal(options OpenOptions) (io.ReadWriteCloser, error) { | |
| r1, _, errno := | ||
| syscall.Syscall( | ||
| syscall.SYS_FCNTL, | ||
| uintptr(file.Fd()), | ||
| uintptr(fd), | ||
| uintptr(syscall.F_SETFL), | ||
| uintptr(0)) | ||
|
|
||
|
|
@@ -231,7 +247,7 @@ func openInternal(options OpenOptions) (io.ReadWriteCloser, error) { | |
| return nil, err | ||
| } | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to ensure that the FD isn't leaked if you return early below. |
||
| err = setTermios(file.Fd(), terminalOptions) | ||
| err = setTermios(uintptr(fd), terminalOptions) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -240,7 +256,7 @@ func openInternal(options OpenOptions) (io.ReadWriteCloser, error) { | |
| // Set baud rate with the IOSSIOSPEED ioctl, to support non-standard speeds. | ||
| r2, _, errno2 := syscall.Syscall( | ||
| syscall.SYS_IOCTL, | ||
| uintptr(file.Fd()), | ||
| uintptr(fd), | ||
| uintptr(kIOSSIOSPEED), | ||
| uintptr(unsafe.Pointer(&options.BaudRate))) | ||
|
|
||
|
|
@@ -253,6 +269,9 @@ func openInternal(options OpenOptions) (io.ReadWriteCloser, error) { | |
| } | ||
| } | ||
|
|
||
| file := Port{ | ||
| fd: fd, | ||
| } | ||
| // We're done. | ||
| return file, nil | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line before this