Skip to content

Commit 0a09c72

Browse files
committed
internal/poll: add RawControl, RawRead and RawWrite methods to FD
This change adds RawControl, RawRead and RawWrite methods to type FD to make the runtime-integrated network poller work together with a user-defined function. The methods are used via the net package from external packages and type FD is considered as an implementation of syscall.Conn and syscall.RawConn interfaces. Updates #19435. Change-Id: I4ad04b10ffddb2b54fa8d70587440960d73c0a2d Reviewed-on: https://go-review.googlesource.com/37038 Run-TryBot: Mikio Hara <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent de5c573 commit 0a09c72

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

src/internal/poll/fd_plan9.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package poll
66

77
import (
8+
"errors"
89
"io"
910
"sync/atomic"
1011
"time"
@@ -197,3 +198,19 @@ func isInterrupted(err error) bool {
197198
func PollDescriptor() uintptr {
198199
return ^uintptr(0)
199200
}
201+
202+
// RawControl invokes the user-defined function f for a non-IO
203+
// operation.
204+
func (fd *FD) RawControl(f func(uintptr)) error {
205+
return errors.New("not implemented")
206+
}
207+
208+
// RawRead invokes the user-defined function f for a read operation.
209+
func (fd *FD) RawRead(f func(uintptr) bool) error {
210+
return errors.New("not implemented")
211+
}
212+
213+
// RawWrite invokes the user-defined function f for a write operation.
214+
func (fd *FD) RawWrite(f func(uintptr) bool) error {
215+
return errors.New("not implemented")
216+
}

src/internal/poll/fd_unix.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,52 @@ func (fd *FD) Fstat(s *syscall.Stat_t) error {
399399
func (fd *FD) WaitWrite() error {
400400
return fd.pd.waitWrite(fd.isFile)
401401
}
402+
403+
// RawControl invokes the user-defined function f for a non-IO
404+
// operation.
405+
func (fd *FD) RawControl(f func(uintptr)) error {
406+
if err := fd.incref(); err != nil {
407+
return err
408+
}
409+
defer fd.decref()
410+
f(uintptr(fd.Sysfd))
411+
return nil
412+
}
413+
414+
// RawRead invokes the user-defined function f for a read operation.
415+
func (fd *FD) RawRead(f func(uintptr) bool) error {
416+
if err := fd.readLock(); err != nil {
417+
return err
418+
}
419+
defer fd.readUnlock()
420+
if err := fd.pd.prepareRead(fd.isFile); err != nil {
421+
return err
422+
}
423+
for {
424+
if f(uintptr(fd.Sysfd)) {
425+
return nil
426+
}
427+
if err := fd.pd.waitRead(fd.isFile); err != nil {
428+
return err
429+
}
430+
}
431+
}
432+
433+
// RawWrite invokes the user-defined function f for a write operation.
434+
func (fd *FD) RawWrite(f func(uintptr) bool) error {
435+
if err := fd.writeLock(); err != nil {
436+
return err
437+
}
438+
defer fd.writeUnlock()
439+
if err := fd.pd.prepareWrite(fd.isFile); err != nil {
440+
return err
441+
}
442+
for {
443+
if f(uintptr(fd.Sysfd)) {
444+
return nil
445+
}
446+
if err := fd.pd.waitWrite(fd.isFile); err != nil {
447+
return err
448+
}
449+
}
450+
}

src/internal/poll/fd_windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,19 @@ func (fd *FD) GetFileInformationByHandle(data *syscall.ByHandleFileInformation)
833833
defer fd.decref()
834834
return syscall.GetFileInformationByHandle(fd.Sysfd, data)
835835
}
836+
837+
// RawControl invokes the user-defined function f for a non-IO
838+
// operation.
839+
func (fd *FD) RawControl(f func(uintptr)) error {
840+
return errors.New("not implemented")
841+
}
842+
843+
// RawRead invokes the user-defined function f for a read operation.
844+
func (fd *FD) RawRead(f func(uintptr) bool) error {
845+
return errors.New("not implemented")
846+
}
847+
848+
// RawWrite invokes the user-defined function f for a write operation.
849+
func (fd *FD) RawWrite(f func(uintptr) bool) error {
850+
return errors.New("not implemented")
851+
}

0 commit comments

Comments
 (0)