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

Delta Between Two Patch Sets: src/net/tcpsockopt_darwin.go

Issue 136480043: code review 136480043: net: fix SetKeepAlivePeriod method of TCPConn (Closed)
Left Patch Set: diff -r ca2c8c76aed9059b73eac0a8986bf84e6f10f8b5 https://code.google.com/p/go Created 9 years, 6 months ago
Right Patch Set: diff -r 4057ec7e5d7411b67ebd364096cb010b533501e4 https://code.google.com/p/go Created 9 years, 6 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/net/tcpsockopt_dragonfly.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
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package net 5 package net
6 6
7 import ( 7 import (
8 "os" 8 "os"
9 "syscall" 9 "syscall"
10 "time" 10 "time"
11 ) 11 )
12 12
13 const ( 13 const sysTCP_KEEPINTVL = 0x101
14 » sysTCP_KEEPINTVL = 0x101
15 » sysTCP_KEEPCNT = 0x102
16 )
17 14
18 func setKeepAlivePeriod(fd *netFD, d time.Duration) error { 15 func setKeepAlivePeriod(fd *netFD, d time.Duration) error {
19 if err := fd.incref(); err != nil { 16 if err := fd.incref(); err != nil {
20 return err 17 return err
21 } 18 }
22 defer fd.decref() 19 defer fd.decref()
23 » idleInterval := keepAliveInterval{ // [1 second, MaxUint32 milliseconds) 20 » // The kernel expects seconds so round to next highest second.
24 » » time.Second, 21 » d += (time.Second - time.Nanosecond)
25 » » (1<<32 - 2) * time.Millisecond, 22 » secs := int(d.Seconds())
26 » } 23 » switch err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, sysTC P_KEEPINTVL, secs); err {
27 » probeInterval := keepAliveInterval{ // [1 second, MaxUint32 milliseconds ) 24 » case nil, syscall.ENOPROTOOPT: // OS X 10.7 and earlier don't support th is option
28 » » time.Second, 25 » default:
29 » » (1<<32 - 2) * time.Millisecond,
30 » }
31 » idle, probe := keepAliveSubinterval(d, &idleInterval, &probeInterval)
32 » if err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.T CP_KEEPALIVE, int(idle.Seconds())); err != nil {
33 return os.NewSyscallError("setsockopt", err) 26 return os.NewSyscallError("setsockopt", err)
34 } 27 }
35 » if err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, sysTCP_KE EPCNT, int(probe/time.Second)); err != nil { 28 » return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_KEEPALIVE, secs))
36 » » return os.NewSyscallError("setsockopt", err)
37 » }
38 » return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, sysTCP_KEEPINTVL, 1))
39 } 29 }
LEFTRIGHT

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