LEFT | RIGHT |
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 // TCP sockets | 5 // TCP sockets |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "os"; | 10 "os"; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 // TCPConn is an implementation of the Conn interface | 68 // TCPConn is an implementation of the Conn interface |
69 // for TCP network connections. | 69 // for TCP network connections. |
70 type TCPConn struct { | 70 type TCPConn struct { |
71 fd *netFD; | 71 fd *netFD; |
72 } | 72 } |
73 | 73 |
74 func newTCPConn(fd *netFD) *TCPConn { | 74 func newTCPConn(fd *netFD) *TCPConn { |
75 c := &TCPConn{fd}; | 75 c := &TCPConn{fd}; |
76 fd.getref(); | |
77 defer fd.delref(); | |
78 setsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_NODELAY, 1); | 76 setsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_NODELAY, 1); |
79 return c; | 77 return c; |
80 } | 78 } |
81 | 79 |
82 func (c *TCPConn) ok() bool { return c != nil && c.fd != nil } | 80 func (c *TCPConn) ok() bool { return c != nil && c.fd != nil } |
83 | 81 |
84 // Implementation of the Conn interface - see Conn for documentation. | 82 // Implementation of the Conn interface - see Conn for documentation. |
85 | 83 |
86 // Read reads data from the TCP connection. | 84 // Read reads data from the TCP connection. |
87 // | 85 // |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // Already Accepted connections are not closed. | 271 // Already Accepted connections are not closed. |
274 func (l *TCPListener) Close() os.Error { | 272 func (l *TCPListener) Close() os.Error { |
275 if l == nil || l.fd == nil { | 273 if l == nil || l.fd == nil { |
276 return os.EINVAL | 274 return os.EINVAL |
277 } | 275 } |
278 return l.fd.Close(); | 276 return l.fd.Close(); |
279 } | 277 } |
280 | 278 |
281 // Addr returns the listener's network address, a *TCPAddr. | 279 // Addr returns the listener's network address, a *TCPAddr. |
282 func (l *TCPListener) Addr() Addr { return l.fd.laddr } | 280 func (l *TCPListener) Addr() Addr { return l.fd.laddr } |
LEFT | RIGHT |