OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [newpollserver_rtems.go] - Blame information for rev 761

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2010 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package net
6
 
7
import (
8
        "os"
9
        "syscall"
10
)
11
 
12
func selfConnectedTCPSocket() (pr, pw *os.File, err error) {
13
        // See ../syscall/exec.go for description of ForkLock.
14
        syscall.ForkLock.RLock()
15
        sockfd, e := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, 0)
16
        if e != 0 {
17
                syscall.ForkLock.RUnlock()
18
                return nil, nil, os.Errno(e)
19
        }
20
        syscall.CloseOnExec(sockfd)
21
        syscall.ForkLock.RUnlock()
22
 
23
        // Allow reuse of recently-used addresses.
24
        syscall.SetsockoptInt(sockfd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
25
 
26
        var laTCP *TCPAddr
27
        var la syscall.Sockaddr
28
        if laTCP, err = ResolveTCPAddr("127.0.0.1:0"); err != nil {
29
        Error:
30
                return nil, nil, err
31
        }
32
        if la, err = laTCP.sockaddr(syscall.AF_INET); err != nil {
33
                goto Error
34
        }
35
        e = syscall.Bind(sockfd, la)
36
        if e != 0 {
37
        Errno:
38
                syscall.Close(sockfd)
39
                return nil, nil, os.Errno(e)
40
        }
41
 
42
        laddr, _ := syscall.Getsockname(sockfd)
43
        e = syscall.Connect(sockfd, laddr)
44
        if e != 0 {
45
                goto Errno
46
        }
47
 
48
        fd := os.NewFile(sockfd, "wakeupSocket")
49
        return fd, fd, nil
50
}
51
 
52
func newPollServer() (s *pollServer, err error) {
53
        s = new(pollServer)
54
        s.cr = make(chan *netFD, 1)
55
        s.cw = make(chan *netFD, 1)
56
        // s.pr and s.pw are indistinguishable.
57
        if s.pr, s.pw, err = selfConnectedTCPSocket(); err != nil {
58
                return nil, err
59
        }
60
        var e int
61
        if e = syscall.SetNonblock(s.pr.Fd(), true); e != 0 {
62
        Errno:
63
                err = &os.PathError{"setnonblock", s.pr.Name(), os.Errno(e)}
64
        Error:
65
                s.pr.Close()
66
                return nil, err
67
        }
68
        if s.poll, err = newpollster(); err != nil {
69
                goto Error
70
        }
71
        if _, err = s.poll.AddFD(s.pr.Fd(), 'r', true); err != nil {
72
                s.poll.Close()
73
                goto Error
74
        }
75
        s.pending = make(map[int]*netFD)
76
        go s.Run()
77
        return s, nil
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.