dsgawmla208057 2016-03-10 11:25
浏览 6
已采纳

禁用Golang TCP中的截止日期

I want to set a deadline on client connection, he must do something within the first 10 seconds or else get disconnected, if he does do something, I want to remove the deadline.

// meConn = *TCPConn
c.meConn.SetDeadline(time.Now().Add(10 * time.Second))

But the documentation doesn't say anything about disabling the deadline.

Also, is it safe to keep changing the deadline when a certain condition is met?

  • 写回答

1条回答 默认 最新

  • doulian7252 2016-03-10 11:38
    关注

    It states:

    // SetReadDeadline sets the deadline for future Read calls.
    // A zero value for t means Read will not time out.
    SetReadDeadline(t time.Time) error
    

    In the documentation for SetReadDeadLine

    so you will need to pass in zero when a client sends what you expect.

    and the SetDeadLine says it is setting both the reader and the writer, so make sure you also meant to set the writer.

       // SetDeadline sets the read and write deadlines associated
       // with the connection. It is equivalent to calling both
       // SetReadDeadline and SetWriteDeadline.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部