github.com/openziti/transport@v0.1.5/transwarp/connection.go (about) 1 /* 2 Copyright NetFoundry, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 https://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package transwarp 18 19 import ( 20 "crypto/x509" 21 "github.com/openziti/transport" 22 "io" 23 "net" 24 "time" 25 ) 26 27 type Connection struct { 28 detail *transport.ConnectionDetail 29 socket net.Conn 30 } 31 32 func (self *Connection) Detail() *transport.ConnectionDetail { 33 return self.detail 34 } 35 36 func (self *Connection) PeerCertificates() []*x509.Certificate { 37 return nil 38 } 39 40 func (self *Connection) Reader() io.Reader { 41 return self.socket 42 } 43 44 func (self *Connection) Writer() io.Writer { 45 return self.socket 46 } 47 48 func (self *Connection) Conn() net.Conn { 49 return self.socket 50 } 51 52 func (self *Connection) SetReadTimeout(t time.Duration) error { 53 return self.socket.SetReadDeadline(time.Now().Add(t)) 54 } 55 56 func (self *Connection) SetWriteTimeout(t time.Duration) error { 57 return self.socket.SetWriteDeadline(time.Now().Add(t)) 58 } 59 60 // ClearReadTimeout clears the read time for all current and future reads 61 // 62 func (self *Connection) ClearReadTimeout() error { 63 return self.socket.SetReadDeadline(time.Time{}) 64 } 65 66 // ClearWriteTimeout clears the write timeout for all current and future writes 67 // 68 func (self *Connection) ClearWriteTimeout() error { 69 return self.socket.SetWriteDeadline(time.Time{}) 70 } 71 72 func (self *Connection) Close() error { 73 return self.socket.Close() 74 }