mirror of
https://github.com/go-micro/go-micro.git
synced 2025-01-05 10:20:53 +02:00
39 lines
761 B
Go
39 lines
761 B
Go
package utp
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/asim/go-micro/v3/transport"
|
|
)
|
|
|
|
func (u *utpClient) Local() string {
|
|
return u.conn.LocalAddr().String()
|
|
}
|
|
|
|
func (u *utpClient) Remote() string {
|
|
return u.conn.RemoteAddr().String()
|
|
}
|
|
|
|
func (u *utpClient) Send(m *transport.Message) error {
|
|
// set timeout if its greater than 0
|
|
if u.timeout > time.Duration(0) {
|
|
u.conn.SetDeadline(time.Now().Add(u.timeout))
|
|
}
|
|
if err := u.enc.Encode(m); err != nil {
|
|
return err
|
|
}
|
|
return u.encBuf.Flush()
|
|
}
|
|
|
|
func (u *utpClient) Recv(m *transport.Message) error {
|
|
// set timeout if its greater than 0
|
|
if u.timeout > time.Duration(0) {
|
|
u.conn.SetDeadline(time.Now().Add(u.timeout))
|
|
}
|
|
return u.dec.Decode(&m)
|
|
}
|
|
|
|
func (u *utpClient) Close() error {
|
|
return u.conn.Close()
|
|
}
|