]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: add RawControl, RawRead and RawWrite methods to FD
authorMikio Hara <mikioh.mikioh@gmail.com>
Mon, 13 Feb 2017 20:55:41 +0000 (05:55 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Fri, 19 May 2017 09:10:16 +0000 (09:10 +0000)
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 <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/internal/poll/fd_plan9.go
src/internal/poll/fd_unix.go
src/internal/poll/fd_windows.go

index 49590ab13c416cbc249da33024fef8accc376e9c..107f4545233394d43dc61348d2c6d5aaeeffc882 100644 (file)
@@ -5,6 +5,7 @@
 package poll
 
 import (
+       "errors"
        "io"
        "sync/atomic"
        "time"
@@ -197,3 +198,19 @@ func isInterrupted(err error) bool {
 func PollDescriptor() uintptr {
        return ^uintptr(0)
 }
+
+// RawControl invokes the user-defined function f for a non-IO
+// operation.
+func (fd *FD) RawControl(f func(uintptr)) error {
+       return errors.New("not implemented")
+}
+
+// RawRead invokes the user-defined function f for a read operation.
+func (fd *FD) RawRead(f func(uintptr) bool) error {
+       return errors.New("not implemented")
+}
+
+// RawWrite invokes the user-defined function f for a write operation.
+func (fd *FD) RawWrite(f func(uintptr) bool) error {
+       return errors.New("not implemented")
+}
index 782ecd5a874d9b2d240ec5a8163b6e211e63f1af..3ca6e157c5e136cf08c23fd5c342d5cf10d66ad2 100644 (file)
@@ -399,3 +399,52 @@ func (fd *FD) Fstat(s *syscall.Stat_t) error {
 func (fd *FD) WaitWrite() error {
        return fd.pd.waitWrite(fd.isFile)
 }
+
+// RawControl invokes the user-defined function f for a non-IO
+// operation.
+func (fd *FD) RawControl(f func(uintptr)) error {
+       if err := fd.incref(); err != nil {
+               return err
+       }
+       defer fd.decref()
+       f(uintptr(fd.Sysfd))
+       return nil
+}
+
+// RawRead invokes the user-defined function f for a read operation.
+func (fd *FD) RawRead(f func(uintptr) bool) error {
+       if err := fd.readLock(); err != nil {
+               return err
+       }
+       defer fd.readUnlock()
+       if err := fd.pd.prepareRead(fd.isFile); err != nil {
+               return err
+       }
+       for {
+               if f(uintptr(fd.Sysfd)) {
+                       return nil
+               }
+               if err := fd.pd.waitRead(fd.isFile); err != nil {
+                       return err
+               }
+       }
+}
+
+// RawWrite invokes the user-defined function f for a write operation.
+func (fd *FD) RawWrite(f func(uintptr) bool) error {
+       if err := fd.writeLock(); err != nil {
+               return err
+       }
+       defer fd.writeUnlock()
+       if err := fd.pd.prepareWrite(fd.isFile); err != nil {
+               return err
+       }
+       for {
+               if f(uintptr(fd.Sysfd)) {
+                       return nil
+               }
+               if err := fd.pd.waitWrite(fd.isFile); err != nil {
+                       return err
+               }
+       }
+}
index a41209c34423fcda2bb6a14e933c547f56ab5c96..5c55c948c233c601bfb2c9275007b933d1e730ad 100644 (file)
@@ -833,3 +833,19 @@ func (fd *FD) GetFileInformationByHandle(data *syscall.ByHandleFileInformation)
        defer fd.decref()
        return syscall.GetFileInformationByHandle(fd.Sysfd, data)
 }
+
+// RawControl invokes the user-defined function f for a non-IO
+// operation.
+func (fd *FD) RawControl(f func(uintptr)) error {
+       return errors.New("not implemented")
+}
+
+// RawRead invokes the user-defined function f for a read operation.
+func (fd *FD) RawRead(f func(uintptr) bool) error {
+       return errors.New("not implemented")
+}
+
+// RawWrite invokes the user-defined function f for a write operation.
+func (fd *FD) RawWrite(f func(uintptr) bool) error {
+       return errors.New("not implemented")
+}