diff options
| author | Ondřej Surý <ondrej@sury.org> | 2012-04-06 15:14:11 +0200 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2012-04-06 15:14:11 +0200 |
| commit | 505c19580e0f43fe5224431459cacb7c21edd93d (patch) | |
| tree | 79e2634c253d60afc0cc0b2f510dc7dcbb48497b /src/pkg/syscall/sockcmsg_unix.go | |
| parent | 1336a7c91e596c423a49d1194ea42d98bca0d958 (diff) | |
| download | golang-505c19580e0f43fe5224431459cacb7c21edd93d.tar.gz | |
Imported Upstream version 1upstream/1
Diffstat (limited to 'src/pkg/syscall/sockcmsg_unix.go')
| -rw-r--r-- | src/pkg/syscall/sockcmsg_unix.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/pkg/syscall/sockcmsg_unix.go b/src/pkg/syscall/sockcmsg_unix.go index b437560e7..d279decb6 100644 --- a/src/pkg/syscall/sockcmsg_unix.go +++ b/src/pkg/syscall/sockcmsg_unix.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build darwin freebsd linux netbsd openbsd + // Socket control messages package syscall @@ -45,17 +47,17 @@ type SocketControlMessage struct { Data []byte } -func ParseSocketControlMessage(buf []byte) ([]SocketControlMessage, int) { +func ParseSocketControlMessage(buf []byte) ([]SocketControlMessage, error) { var ( h *Cmsghdr dbuf []byte - e int + e error cmsgs []SocketControlMessage ) for len(buf) >= CmsgLen(0) { h, dbuf, e = socketControlMessageHeaderAndData(buf) - if e != 0 { + if e != nil { break } m := SocketControlMessage{} @@ -68,12 +70,12 @@ func ParseSocketControlMessage(buf []byte) ([]SocketControlMessage, int) { return cmsgs, e } -func socketControlMessageHeaderAndData(buf []byte) (*Cmsghdr, []byte, int) { +func socketControlMessageHeaderAndData(buf []byte) (*Cmsghdr, []byte, error) { h := (*Cmsghdr)(unsafe.Pointer(&buf[0])) if h.Len < SizeofCmsghdr || int(h.Len) > len(buf) { return nil, nil, EINVAL } - return h, buf[cmsgAlignOf(SizeofCmsghdr):], 0 + return h, buf[cmsgAlignOf(SizeofCmsghdr):], nil } // UnixRights encodes a set of open file descriptors into a socket @@ -97,7 +99,7 @@ func UnixRights(fds ...int) []byte { // ParseUnixRights decodes a socket control message that contains an // integer array of open file descriptors from another process. -func ParseUnixRights(msg *SocketControlMessage) ([]int, int) { +func ParseUnixRights(msg *SocketControlMessage) ([]int, error) { if msg.Header.Level != SOL_SOCKET { return nil, EINVAL } @@ -109,5 +111,5 @@ func ParseUnixRights(msg *SocketControlMessage) ([]int, int) { fds[j] = int(*(*int32)(unsafe.Pointer(&msg.Data[i]))) j++ } - return fds, 0 + return fds, nil } |
