Commit 791b2a49 authored by Albert Strasheim's avatar Albert Strasheim Committed by Russ Cox

net: Return error from CloseRead and CloseWrite.

R=bradfitz, rsc, iant
CC=golang-dev
https://golang.org/cl/5167043
parent 51057bda
...@@ -358,20 +358,23 @@ func (fd *netFD) Close() os.Error { ...@@ -358,20 +358,23 @@ func (fd *netFD) Close() os.Error {
return nil return nil
} }
func (fd *netFD) CloseRead() os.Error { func (fd *netFD) shutdown(how int) os.Error {
if fd == nil || fd.sysfile == nil { if fd == nil || fd.sysfile == nil {
return os.EINVAL 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 return nil
} }
func (fd *netFD) CloseRead() os.Error {
return fd.shutdown(syscall.SHUT_RD)
}
func (fd *netFD) CloseWrite() os.Error { func (fd *netFD) CloseWrite() os.Error {
if fd == nil || fd.sysfile == nil { return fd.shutdown(syscall.SHUT_WR)
return os.EINVAL
}
syscall.Shutdown(fd.sysfd, syscall.SHUT_WR)
return nil
} }
func (fd *netFD) Read(p []byte) (n int, err os.Error) { func (fd *netFD) Read(p []byte) (n int, err os.Error) {
......
...@@ -312,20 +312,23 @@ func (fd *netFD) Close() os.Error { ...@@ -312,20 +312,23 @@ func (fd *netFD) Close() os.Error {
return nil return nil
} }
func (fd *netFD) CloseRead() os.Error { func (fd *netFD) shutdown(how int) os.Error {
if fd == nil || fd.sysfd == syscall.InvalidHandle { if fd == nil || fd.sysfd == syscall.InvalidHandle {
return os.EINVAL 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 return nil
} }
func (fd *netFD) CloseRead() os.Error {
return fd.shutdown(syscall.SHUT_RD)
}
func (fd *netFD) CloseWrite() os.Error { func (fd *netFD) CloseWrite() os.Error {
if fd == nil || fd.sysfd == syscall.InvalidHandle { return fd.shutdown(syscall.SHUT_WR)
return os.EINVAL
}
syscall.Shutdown(fd.sysfd, syscall.SHUT_WR)
return nil
} }
// Read from network. // Read from network.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment