我想為客戶端連接設置一個截止日期,他必須在前 10 秒內做一些事情,否則就會斷開連接,如果他做了某事,我想取消截止日期。// meConn = *TCPConnc.meConn.SetDeadline(time.Now().Add(10 * time.Second))但是文檔沒有說明禁用截止日期的任何內容。另外,在滿足特定條件時繼續(xù)更改截止日期是否安全?
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的文檔中
因此,當客戶端發(fā)送您期望的內容時,您需要傳入零。
并且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 關注
- 165 瀏覽
添加回答
舉報
0/150
提交
取消