1 Star 0 Fork 0

SasukeBo/go-micro

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
socket.go 842 Bytes
一键复制 编辑 原始数据 按行查看 历史
汪波 提交于 2023-02-23 10:27 +08:00 . fix: 替换包名
package utp
import (
"errors"
"time"
"gitee.com/sasukebo/go-micro/v4/transport"
)
func (u *utpSocket) Local() string {
return u.conn.LocalAddr().String()
}
func (u *utpSocket) Remote() string {
return u.conn.RemoteAddr().String()
}
func (u *utpSocket) Recv(m *transport.Message) error {
if m == nil {
return errors.New("message passed in is nil")
}
// 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 *utpSocket) 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 *utpSocket) Close() error {
return u.conn.Close()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sasukebo/go-micro.git
git@gitee.com:sasukebo/go-micro.git
sasukebo
go-micro
go-micro
6e18eb58b836

搜索帮助