1
0
mirror of https://github.com/golang/go synced 2024-11-25 03:47:57 -07:00

net: Return error from CloseRead and CloseWrite.

R=bradfitz, rsc, iant
CC=golang-dev
https://golang.org/cl/5167043
This commit is contained in:
Albert Strasheim 2011-10-12 13:45:25 -04:00 committed by Russ Cox
parent 51057bda3f
commit 791b2a498e
2 changed files with 20 additions and 14 deletions

View File

@ -358,20 +358,23 @@ func (fd *netFD) Close() os.Error {
return nil
}
func (fd *netFD) CloseRead() os.Error {
func (fd *netFD) shutdown(how int) os.Error {
if fd == nil || fd.sysfile == nil {
return os.EINVAL
}
syscall.Shutdown(fd.sysfd, syscall.SHUT_RD)
errno := syscall.Shutdown(fd.sysfd, how)
if errno != 0 {
return &OpError{"shutdown", fd.net, fd.laddr, os.Errno(errno)}
}
return nil
}
func (fd *netFD) CloseRead() os.Error {
return fd.shutdown(syscall.SHUT_RD)
}
func (fd *netFD) CloseWrite() os.Error {
if fd == nil || fd.sysfile == nil {
return os.EINVAL
}
syscall.Shutdown(fd.sysfd, syscall.SHUT_WR)
return nil
return fd.shutdown(syscall.SHUT_WR)
}
func (fd *netFD) Read(p []byte) (n int, err os.Error) {

View File

@ -312,20 +312,23 @@ func (fd *netFD) Close() os.Error {
return nil
}
func (fd *netFD) CloseRead() os.Error {
func (fd *netFD) shutdown(how int) os.Error {
if fd == nil || fd.sysfd == syscall.InvalidHandle {
return os.EINVAL
}
syscall.Shutdown(fd.sysfd, syscall.SHUT_RD)
errno := syscall.Shutdown(fd.sysfd, how)
if errno != 0 {
return &OpError{"shutdown", fd.net, fd.laddr, os.Errno(errno)}
}
return nil
}
func (fd *netFD) CloseRead() os.Error {
return fd.shutdown(syscall.SHUT_RD)
}
func (fd *netFD) CloseWrite() os.Error {
if fd == nil || fd.sysfd == syscall.InvalidHandle {
return os.EINVAL
}
syscall.Shutdown(fd.sysfd, syscall.SHUT_WR)
return nil
return fd.shutdown(syscall.SHUT_WR)
}
// Read from network.