easygo icon indicating copy to clipboard operation
easygo copied to clipboard

Start would reset fd on HandleRead to blocking lead to set deadliner doesn't work

Open cryptom-dev opened this issue 7 years ago • 0 comments

you set non blocking here for handle read:

https://github.com/mailru/easygo/blob/0c8322a753d040315fe938f6d1307cdebbe395c8/netpoll/handle.go#L91-L93

but on poller.Start(), the call to fd() would set underlying file to blocking mode again. https://github.com/mailru/easygo/blob/0c8322a753d040315fe938f6d1307cdebbe395c8/netpoll/netpoll_kqueue.go#L25


// Fd returns the integer Unix file descriptor referencing the open file.
// The file descriptor is valid only until f.Close is called or f is garbage collected.
// On Unix systems this will cause the SetDeadline methods to stop working.
func (f *File) Fd() uintptr {
	if f == nil {
		return ^(uintptr(0))
	}

	// If we put the file descriptor into nonblocking mode,
	// then set it to blocking mode before we return it,
	// because historically we have always returned a descriptor
	// opened in blocking mode. The File will continue to work,
	// but any blocking operation will tie up a thread.
	if f.nonblock {
		f.pfd.SetBlocking()
	}

	return uintptr(f.pfd.Sysfd)
}

This caused set deadliner doesn't work on conn owned by poller

cryptom-dev avatar Mar 26 '19 09:03 cryptom-dev