mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
improve read syscall reliability by inreasing buffer size and handling old kernel errors
This commit is contained in:
@@ -17,7 +17,8 @@ const maximumWatchersFile = "/proc/sys/fs/inotify/max_user_watches"
|
|||||||
// set to -1 if the number cannot be determined
|
// set to -1 if the number cannot be determined
|
||||||
var MaxWatchers int = -1
|
var MaxWatchers int = -1
|
||||||
|
|
||||||
const EventSize int = unix.SizeofInotifyEvent
|
// sizeof(struct inotify_event) + NAME_MAX + 1
|
||||||
|
const EventSize int = unix.SizeofInotifyEvent + 255 + 1
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
mw, err := getMaxWatchers()
|
mw, err := getMaxWatchers()
|
||||||
@@ -71,7 +72,7 @@ func (i *Inotify) Watch(dir string) error {
|
|||||||
|
|
||||||
func (i *Inotify) Read(buf []byte) (int, error) {
|
func (i *Inotify) Read(buf []byte) (int, error) {
|
||||||
n, errno := unix.Read(i.FD, buf)
|
n, errno := unix.Read(i.FD, buf)
|
||||||
if n < 0 {
|
if n < 1 {
|
||||||
return n, fmt.Errorf("reading from inotify fd %d: errno: %d", i.FD, errno)
|
return n, fmt.Errorf("reading from inotify fd %d: errno: %d", i.FD, errno)
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user