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

Delta Between Two Patch Sets: src/pkg/net/accept_bsd.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 | « no previous file | src/pkg/net/accept_linux.go » ('j') | src/pkg/net/accept_linux.go » ('J')
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 // +build darwin freebsd netbsd openbsd
6
7 package net
8
9 import (
10 "syscall"
11 )
12
13 func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (netfd *netFD, err e rror) {
14 if err := fd.incref(false); err != nil {
15 return nil, err
16 }
17 defer fd.decref()
18
19 // See ../syscall/exec_unix.go for description of ForkLock.
20 // It is okay to hold the lock across syscall.Accept
21 // because we have put fd.sysfd into non-blocking mode.
22 var s int
23 var rsa syscall.Sockaddr
24 for {
25 syscall.ForkLock.RLock()
26 s, rsa, err = syscall.Accept(fd.sysfd)
27 if err != nil {
28 syscall.ForkLock.RUnlock()
29 if err == syscall.EAGAIN {
30 if err = fd.pollServer.WaitRead(fd); err == nil {
31 continue
32 }
33 } else if err == syscall.ECONNABORTED {
34 // This means that a socket on the listen queue was closed
35 // before we Accept()ed it; it's a silly error, so try again.
36 continue
37 }
38 return nil, &OpError{"accept", fd.net, fd.laddr, err}
39 }
40 break
41 }
42 syscall.CloseOnExec(s)
43 syscall.ForkLock.RUnlock()
44
45 if err = syscall.SetNonblock(s, true); err != nil {
46 closesocket(s)
47 return nil, err
48 }
49 netfd = newFD(s, fd.family, fd.sotype, fd.net)
50 lsa, _ := syscall.Getsockname(netfd.sysfd)
51 netfd.setAddr(toAddr(lsa), toAddr(rsa))
52 return netfd, nil
53 }
LEFTRIGHT

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