...
Run Format

Source file src/internal/poll/fd_poll_nacl.go

Documentation: internal/poll

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package poll
     6  
     7  import (
     8  	"syscall"
     9  	"time"
    10  )
    11  
    12  type pollDesc struct {
    13  	fd      *FD
    14  	closing bool
    15  }
    16  
    17  func (pd *pollDesc) init(fd *FD) error { pd.fd = fd; return nil }
    18  
    19  func (pd *pollDesc) close() {}
    20  
    21  func (pd *pollDesc) evict() {
    22  	pd.closing = true
    23  	if pd.fd != nil {
    24  		syscall.StopIO(pd.fd.Sysfd)
    25  	}
    26  }
    27  
    28  func (pd *pollDesc) prepare(mode int, isFile bool) error {
    29  	if pd.closing {
    30  		return errClosing(isFile)
    31  	}
    32  	return nil
    33  }
    34  
    35  func (pd *pollDesc) prepareRead(isFile bool) error { return pd.prepare('r', isFile) }
    36  
    37  func (pd *pollDesc) prepareWrite(isFile bool) error { return pd.prepare('w', isFile) }
    38  
    39  func (pd *pollDesc) wait(mode int, isFile bool) error {
    40  	if pd.closing {
    41  		return errClosing(isFile)
    42  	}
    43  	return ErrTimeout
    44  }
    45  
    46  func (pd *pollDesc) waitRead(isFile bool) error { return pd.wait('r', isFile) }
    47  
    48  func (pd *pollDesc) waitWrite(isFile bool) error { return pd.wait('w', isFile) }
    49  
    50  func (pd *pollDesc) waitCanceled(mode int) {}
    51  
    52  func (pd *pollDesc) pollable() bool { return true }
    53  
    54  // SetDeadline sets the read and write deadlines associated with fd.
    55  func (fd *FD) SetDeadline(t time.Time) error {
    56  	return setDeadlineImpl(fd, t, 'r'+'w')
    57  }
    58  
    59  // SetReadDeadline sets the read deadline associated with fd.
    60  func (fd *FD) SetReadDeadline(t time.Time) error {
    61  	return setDeadlineImpl(fd, t, 'r')
    62  }
    63  
    64  // SetWriteDeadline sets the write deadline associated with fd.
    65  func (fd *FD) SetWriteDeadline(t time.Time) error {
    66  	return setDeadlineImpl(fd, t, 'w')
    67  }
    68  
    69  func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
    70  	d := t.UnixNano()
    71  	if t.IsZero() {
    72  		d = 0
    73  	}
    74  	if err := fd.incref(); err != nil {
    75  		return err
    76  	}
    77  	switch mode {
    78  	case 'r':
    79  		syscall.SetReadDeadline(fd.Sysfd, d)
    80  	case 'w':
    81  		syscall.SetWriteDeadline(fd.Sysfd, d)
    82  	case 'r' + 'w':
    83  		syscall.SetReadDeadline(fd.Sysfd, d)
    84  		syscall.SetWriteDeadline(fd.Sysfd, d)
    85  	}
    86  	fd.decref()
    87  	return nil
    88  }
    89  
    90  // PollDescriptor returns the descriptor being used by the poller,
    91  // or ^uintptr(0) if there isn't one. This is only used for testing.
    92  func PollDescriptor() uintptr {
    93  	return ^uintptr(0)
    94  }
    95  

View as plain text