github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/third_party/gofrontend/libgo/go/net/fd_poll_nacl.go (about) 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 net 6 7 import ( 8 "syscall" 9 "time" 10 ) 11 12 type pollDesc struct { 13 fd *netFD 14 closing bool 15 } 16 17 func (pd *pollDesc) Init(fd *netFD) error { pd.fd = fd; return nil } 18 19 func (pd *pollDesc) Close() {} 20 21 func (pd *pollDesc) Lock() {} 22 23 func (pd *pollDesc) Unlock() {} 24 25 func (pd *pollDesc) Wakeup() {} 26 27 func (pd *pollDesc) Evict() bool { 28 pd.closing = true 29 if pd.fd != nil { 30 syscall.StopIO(pd.fd.sysfd) 31 } 32 return false 33 } 34 35 func (pd *pollDesc) Prepare(mode int) error { 36 if pd.closing { 37 return errClosing 38 } 39 return nil 40 } 41 42 func (pd *pollDesc) PrepareRead() error { return pd.Prepare('r') } 43 44 func (pd *pollDesc) PrepareWrite() error { return pd.Prepare('w') } 45 46 func (pd *pollDesc) Wait(mode int) error { 47 if pd.closing { 48 return errClosing 49 } 50 return errTimeout 51 } 52 53 func (pd *pollDesc) WaitRead() error { return pd.Wait('r') } 54 55 func (pd *pollDesc) WaitWrite() error { return pd.Wait('w') } 56 57 func (pd *pollDesc) WaitCanceled(mode int) {} 58 59 func (pd *pollDesc) WaitCanceledRead() {} 60 61 func (pd *pollDesc) WaitCanceledWrite() {} 62 63 func (fd *netFD) setDeadline(t time.Time) error { 64 return setDeadlineImpl(fd, t, 'r'+'w') 65 } 66 67 func (fd *netFD) setReadDeadline(t time.Time) error { 68 return setDeadlineImpl(fd, t, 'r') 69 } 70 71 func (fd *netFD) setWriteDeadline(t time.Time) error { 72 return setDeadlineImpl(fd, t, 'w') 73 } 74 75 func setDeadlineImpl(fd *netFD, t time.Time, mode int) error { 76 d := t.UnixNano() 77 if t.IsZero() { 78 d = 0 79 } 80 if err := fd.incref(); err != nil { 81 return err 82 } 83 switch mode { 84 case 'r': 85 syscall.SetReadDeadline(fd.sysfd, d) 86 case 'w': 87 syscall.SetWriteDeadline(fd.sysfd, d) 88 case 'r' + 'w': 89 syscall.SetReadDeadline(fd.sysfd, d) 90 syscall.SetWriteDeadline(fd.sysfd, d) 91 } 92 fd.decref() 93 return nil 94 }