github.com/google/martian/v3@v3.3.3/nosigpipe/nosigpipe_darwin.go (about) 1 //+build darwin,go1.9 2 3 package nosigpipe 4 5 import ( 6 "net" 7 "syscall" 8 9 "github.com/google/martian/v3/log" 10 ) 11 12 // IgnoreSIGPIPE prevents SIGPIPE from being raised on TCP sockets when remote hangs up 13 // See: https://github.com/golang/go/issues/17393 14 func IgnoreSIGPIPE(c net.Conn) { 15 if c == nil { 16 return 17 } 18 s, ok := c.(syscall.Conn) 19 if !ok { 20 return 21 } 22 r, e := s.SyscallConn() 23 if e != nil { 24 log.Errorf("Failed to get SyscallConn: %s", e) 25 return 26 } 27 e = r.Control(func(fd uintptr) { 28 intfd := int(fd) 29 if e := syscall.SetsockoptInt(intfd, syscall.SOL_SOCKET, syscall.SO_NOSIGPIPE, 1); e != nil { 30 log.Errorf("Failed to set SO_NOSIGPIPE: %s", e) 31 } 32 }) 33 if e != nil { 34 log.Errorf("Failed to set SO_NOSIGPIPE: %s", e) 35 } 36 }