Commit 5ee02eef authored by Russ Cox's avatar Russ Cox

net: TCPConn.SetNoDelay, back by popular demand

R=r
CC=golang-dev
https://golang.org/cl/1880047
parent 4188504f
......@@ -129,6 +129,12 @@ func setKeepAlive(fd *netFD, keepalive bool) os.Error {
return setsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, boolint(keepalive))
}
func setNoDelay(fd *netFD, noDelay bool) os.Error {
fd.incref()
defer fd.decref()
return setsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_NODELAY, boolint(noDelay))
}
func setLinger(fd *netFD, sec int) os.Error {
var l syscall.Linger
if sec >= 0 {
......
......@@ -73,7 +73,7 @@ type TCPConn struct {
func newTCPConn(fd *netFD) *TCPConn {
c := &TCPConn{fd}
setsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_NODELAY, 1)
c.SetNoDelay(true)
return c
}
......@@ -192,6 +192,17 @@ func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error {
return setKeepAlive(c.fd, keepalive)
}
// SetNoDelay controls whether the operating system should delay
// packet transmission in hopes of sending fewer packets
// (Nagle's algorithm). The default is true (no delay), meaning
// that data is sent as soon as possible after a Write.
func (c *TCPConn) SetNoDelay(noDelay bool) os.Error {
if !c.ok() {
return os.EINVAL
}
return setNoDelay(c.fd, noDelay)
}
// DialTCP is like Dial but can only connect to TCP networks
// and returns a TCPConn structure.
func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err os.Error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment