There's only one way(SetReadDeadline to timeout) to stop reading? 在2016年11月17日星期四 UTC+8 23:23:06<amenz...@gmail.com> 写道:
> I was able to solve the problem with the SetReadDeadline function. > I check every n second some flag or channel whether to stop reading or > not. In case you use net sockets and your reader is closed by other > goroutine, the Read function will fail the next for loop iteration with the > "reading from closed connection" error. > > for { > err := r.SetReadDeadline(time.Now().Add(5 * time.Second)) > if err != nil { > return err > } > _, err = r.Read(buf) > if netErr, ok := err.(net.Error); ok && netErr.Timeout() { > // check whether t > > continue > } > // ... > } > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6b6c9413-92f3-4a1f-9993-6e9b988a237an%40googlegroups.com.