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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 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
// +build darwin freebsd linux netbsd openbsd windows
6
 
7
// Sockets
8
 
9
package net
10
 
11
import (
12
        "io"
13
        "syscall"
14
)
15
 
16
var listenerBacklog = maxListenerBacklog()
17
 
18
// Generic socket creation.
19
func socket(net string, f, t, p int, la, ra syscall.Sockaddr, toAddr func(syscall.Sockaddr) Addr) (fd *netFD, err error) {
20
        // See ../syscall/exec.go for description of ForkLock.
21
        syscall.ForkLock.RLock()
22
        s, err := syscall.Socket(f, t, p)
23
        if err != nil {
24
                syscall.ForkLock.RUnlock()
25
                return nil, err
26
        }
27
        syscall.CloseOnExec(s)
28
        syscall.ForkLock.RUnlock()
29
 
30
        err = setDefaultSockopts(s, f, t)
31
        if err != nil {
32
                closesocket(s)
33
                return nil, err
34
        }
35
 
36
        if la != nil {
37
                la, err = listenerSockaddr(s, f, la, toAddr)
38
                if err != nil {
39
                        closesocket(s)
40
                        return nil, err
41
                }
42
                err = syscall.Bind(s, la)
43
                if err != nil {
44
                        closesocket(s)
45
                        return nil, err
46
                }
47
        }
48
 
49
        if fd, err = newFD(s, f, t, net); err != nil {
50
                closesocket(s)
51
                return nil, err
52
        }
53
 
54
        if ra != nil {
55
                if err = fd.connect(ra); err != nil {
56
                        closesocket(s)
57
                        fd.Close()
58
                        return nil, err
59
                }
60
                fd.isConnected = true
61
        }
62
 
63
        sa, _ := syscall.Getsockname(s)
64
        laddr := toAddr(sa)
65
        sa, _ = syscall.Getpeername(s)
66
        raddr := toAddr(sa)
67
 
68
        fd.setAddr(laddr, raddr)
69
        return fd, nil
70
}
71
 
72
type writerOnly struct {
73
        io.Writer
74
}
75
 
76
// Fallback implementation of io.ReaderFrom's ReadFrom, when sendfile isn't
77
// applicable.
78
func genericReadFrom(w io.Writer, r io.Reader) (n int64, err error) {
79
        // Use wrapper to hide existing r.ReadFrom from io.Copy.
80
        return io.Copy(writerOnly{w}, r)
81
}

powered by: WebSVN 2.1.0

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