diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-10-23 19:04:37 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-10-23 19:04:37 +0000 |
commit | de27caacfb3da386f499e0f1c65a3246675824bc (patch) | |
tree | 664e8146cf480634282350e5f7f68403941ddfea /libgo/go/net | |
parent | 7b45b87f01235d15b5d9403fa59693a97e49611a (diff) | |
download | gcc-de27caacfb3da386f499e0f1c65a3246675824bc.zip gcc-de27caacfb3da386f499e0f1c65a3246675824bc.tar.gz gcc-de27caacfb3da386f499e0f1c65a3246675824bc.tar.bz2 |
Implement new syscall package.
Calls to library functions now use entersyscall and
exitsyscall as appropriate. This is a first step toward
multiplexing goroutines onto threads.
From-SVN: r180345
Diffstat (limited to 'libgo/go/net')
-rw-r--r-- | libgo/go/net/cgo_unix.go | 15 | ||||
-rw-r--r-- | libgo/go/net/fd_select.go | 18 |
2 files changed, 22 insertions, 11 deletions
diff --git a/libgo/go/net/cgo_unix.go b/libgo/go/net/cgo_unix.go index b809018..d088eab 100644 --- a/libgo/go/net/cgo_unix.go +++ b/libgo/go/net/cgo_unix.go @@ -24,6 +24,17 @@ func libc_getaddrinfo(node *byte, service *byte, hints *syscall.Addrinfo, res ** func libc_freeaddrinfo(res *syscall.Addrinfo) __asm__ ("freeaddrinfo") func libc_gai_strerror(errcode int) *byte __asm__ ("gai_strerror") +// bytePtrToString takes a NUL-terminated array of bytes and convert +// it to a Go string. +func bytePtrToString(p *byte) string { + a := (*[10000]byte)(unsafe.Pointer(p)) + i := 0 + for a[i] != 0 { + i++ + } + return string(a[:i]) +} + func cgoLookupHost(name string) (addrs []string, err os.Error, completed bool) { ip, err, completed := cgoLookupIP(name) for _, p := range ip { @@ -99,13 +110,13 @@ func cgoLookupIPCNAME(name string) (addrs []IP, cname string, err os.Error, comp } else if gerrno == syscall.EAI_SYSTEM { str = syscall.Errstr(syscall.GetErrno()) } else { - str = syscall.BytePtrToString(libc_gai_strerror(gerrno)) + str = bytePtrToString(libc_gai_strerror(gerrno)) } return nil, "", &DNSError{Error: str, Name: name}, true } defer libc_freeaddrinfo(res) if res != nil { - cname = syscall.BytePtrToString((*byte)(unsafe.Pointer(res.Ai_canonname))) + cname = bytePtrToString((*byte)(unsafe.Pointer(res.Ai_canonname))) if cname == "" { cname = name } diff --git a/libgo/go/net/fd_select.go b/libgo/go/net/fd_select.go index e9c68ab..21fd801 100644 --- a/libgo/go/net/fd_select.go +++ b/libgo/go/net/fd_select.go @@ -12,20 +12,20 @@ import ( ) type pollster struct { - readFds, writeFds, repeatFds *syscall.FdSet_t + readFds, writeFds, repeatFds *syscall.FdSet maxFd int - readyReadFds, readyWriteFds *syscall.FdSet_t + readyReadFds, readyWriteFds *syscall.FdSet nReady int lastFd int } func newpollster() (p *pollster, err os.Error) { p = new(pollster) - p.readFds = new(syscall.FdSet_t) - p.writeFds = new(syscall.FdSet_t) - p.repeatFds = new(syscall.FdSet_t) - p.readyReadFds = new(syscall.FdSet_t) - p.readyWriteFds = new(syscall.FdSet_t) + p.readFds = new(syscall.FdSet) + p.writeFds = new(syscall.FdSet) + p.repeatFds = new(syscall.FdSet) + p.readyReadFds = new(syscall.FdSet) + p.readyWriteFds = new(syscall.FdSet) p.maxFd = -1 p.nReady = 0 p.lastFd = 0 @@ -86,9 +86,9 @@ func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err os.E } var n, e int - var tmpReadFds, tmpWriteFds syscall.FdSet_t + var tmpReadFds, tmpWriteFds syscall.FdSet for { - // Temporary syscall.FdSet_ts into which the values are copied + // Temporary syscall.FdSet's into which the values are copied // because select mutates the values. tmpReadFds = *p.readFds tmpWriteFds = *p.writeFds |