我想为客户端连接设置一个截止日期,他必须在前 10 秒内做一些事情,否则就会断开连接,如果他做了某事,我想取消截止日期。// meConn = *TCPConnc.meConn.SetDeadline(time.Now().Add(10 * time.Second))但是文档没有说明禁用截止日期的任何内容。另外,在满足特定条件时继续更改截止日期是否安全?
2 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
它指出:
// SetReadDeadline sets the deadline for future Read calls.
// A zero value for t means Read will not time out.
SetReadDeadline(t time.Time) error
在SetReadDeadLine的文档中
因此,当客户端发送您期望的内容时,您需要传入零。
并且SetDeadLine表示它正在设置读取器和写入器,因此请确保您还打算设置写入器。
// SetDeadline sets the read and write deadlines associated
// with the connection. It is equivalent to calling both
// SetReadDeadline and SetWriteDeadline.
泛舟湖上清波郎朗
TA贡献1818条经验 获得超3个赞
要重置截止日期,您可以SetDeadline在文档保留时使用“零”值调用。这个“零”值可以设置为:
conn.SetDeadline(time.Time{})- 2 回答
- 0 关注
- 200 浏览
添加回答
举报
0/150
提交
取消
