Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1606)

Delta Between Two Patch Sets: src/pkg/net/accept_linux.go

Issue 7188044: code review 7188044: net: Use accept4() on Linux. (Closed)
Left Patch Set: diff -r 2da48f86d386 https://code.google.com/p/go Created 11 years, 2 months ago
Right Patch Set: diff -r 2da48f86d386 https://code.google.com/p/go Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/net/accept_bsd.go ('k') | src/pkg/net/fd_unix.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2013 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 "syscall"
9 )
10
11 // Accept4() comes from Linux 2.6.28.
12 // Fallback to Accept() when Accept4() returns ENOSYS.
13 var useAccept4 bool = true
14
15 func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (netfd *netFD, err e rror) {
16 if err := fd.incref(false); err != nil {
17 return nil, err
18 }
19 defer fd.decref()
20
21 accept4 := useAccept4
dfc 2013/01/23 06:29:23 sorry, this hasn't fixed it. You could use an atom
22
23 // See ../syscall/exec_unix.go for description of ForkLock.
24 // It is okay to hold the lock across syscall.Accept
25 // because we have put fd.sysfd into non-blocking mode.
26 var s int
27 var rsa syscall.Sockaddr
28 for {
29 if accept4 {
30 s, rsa, err = syscall.Accept4(fd.sysfd, syscall.SOCK_CLO EXEC|syscall.SOCK_NONBLOCK)
31 if err == syscall.ENOSYS {
32 accept4 = false
33 useAccept4 = false
34 continue
35 }
36 } else {
37 syscall.ForkLock.RLock()
38 s, rsa, err = syscall.Accept(fd.sysfd)
39 if err == nil {
40 syscall.CloseOnExec(s)
41 }
42 syscall.ForkLock.RUnlock()
43 }
44 if err != nil {
45 if err == syscall.EAGAIN {
46 if err = fd.pollServer.WaitRead(fd); err == nil {
47 continue
48 }
49 } else if err == syscall.ECONNABORTED {
50 // This means that a socket on the listen queue was closed
51 // before we Accept()ed it; it's a silly error, so try again.
52 continue
53 }
54 return nil, &OpError{"accept", fd.net, fd.laddr, err}
55 }
56 break
57 }
58
59 if !accept4 {
60 if err = syscall.SetNonblock(s, true); err != nil {
61 closesocket(s)
62 return nil, err
63 }
64 }
65 netfd = newFD(s, fd.family, fd.sotype, fd.net)
66 lsa, _ := syscall.Getsockname(netfd.sysfd)
67 netfd.setAddr(toAddr(lsa), toAddr(rsa))
68 return netfd, nil
69 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b