FAQ
I have implemented a working HTTP proxy in Go to detect blocked site in China.

In this proxy, I need to detect the following network error:

- DNS error (maybe dial time out, no such host)
- read time out
- connection reset

The problem I encountered now is that I can't detect these errors in the same way on Linux/OS X and Windows.

On unix system, I use type assertion to get the underlying net.OpError or net.DNSError and do some additional checking. For example,

func isErrConnReset(err error) bool {
if ne, ok := err.(*net.OpError); ok {
return ne.Err == syscall.ECONNRESET
}
return false
}



But the same code does not work on Windows (XP, to be more specific). For connection reset, I'm getting error number 64 and 10054. For DNS error and time out on Windows, I resort to search for specific string in the error message as I can't find other ways.

The complete code can be found here:
https://github.com/cyfdecyf/cow/blob/master/proxy_unix.go
https://github.com/cyfdecyf/cow/blob/master/proxy_windows.go

I'm not sure if this problem is caused by different OSes reporting different error messages for the underlying network connection error. As I see ECONNRESET in src/pkg/syscall/zerrors_windows.go, I guess maybe the different behaviors can be abstracted by the standard library but currently it's not?


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Brainman at Feb 21, 2013 at 12:12 am
    For DNS errors, perhaps, you could split net.Dial into net.LookupHost +
    net.Dial(<address>).

    Alex

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 20, '13 at 5:39a
activeFeb 21, '13 at 12:12a
posts2
users2
websitegolang.org

2 users in discussion

Brainman: 1 post Chen Yufei: 1 post

People

Translate

site design / logo © 2022 Grokbase