Skip to content

Commit

Permalink
Merge pull request ARMmbed#21 from syoder/flush-socket-after-bind
Browse files Browse the repository at this point in the history
After binding to the HCI socket, flush any data
  • Loading branch information
hasty authored Dec 23, 2016
2 parents 4aaf0fe + 1a8b112 commit 65396cf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions linux/hci/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ func open(fd, id int) (*Socket, error) {
if err := unix.Bind(fd, &sa); err != nil {
return nil, errors.Wrap(err, "can't bind socket to hci user channel")
}

// poll for 20ms to see if any data becomes available, then clear it
pfds := []unix.PollFd{unix.PollFd{Fd: int32(fd), Events: unix.POLLIN}}
unix.Poll(pfds, 20)
if pfds[0].Revents&unix.POLLIN > 0 {
b := make([]byte, 100)
unix.Read(fd, b)
}

return &Socket{fd: fd}, nil
}

Expand Down

0 comments on commit 65396cf

Please sign in to comment.