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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return os.EINVAL | 206 return os.EINVAL |
207 } | 207 } |
208 return setNoDelay(c.fd, noDelay) | 208 return setNoDelay(c.fd, noDelay) |
209 } | 209 } |
210 | 210 |
211 // File returns a copy of the underlying os.File, set to blocking mode. | 211 // File returns a copy of the underlying os.File, set to blocking mode. |
212 // It is the caller's responsibility to close f when finished. | 212 // It is the caller's responsibility to close f when finished. |
213 // Closing c does not affect f, and closing f does not affect c. | 213 // Closing c does not affect f, and closing f does not affect c. |
214 func (c *TCPConn) File() (f *os.File, err os.Error) { return c.fd.dup() } | 214 func (c *TCPConn) File() (f *os.File, err os.Error) { return c.fd.dup() } |
215 | 215 |
216 // DialTCP is like Dial but can only connect to TCP networks | 216 // DialTCP connects to the remote address raddr on the network net, |
217 // and returns a TCPConn structure. | 217 // which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is used |
| 218 // as the local address for the connection. |
218 func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err os.Error) { | 219 func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err os.Error) { |
219 if raddr == nil { | 220 if raddr == nil { |
220 return nil, &OpError{"dial", "tcp", nil, errMissingAddress} | 221 return nil, &OpError{"dial", "tcp", nil, errMissingAddress} |
221 } | 222 } |
222 fd, e := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOC
K_STREAM, 0, "dial", sockaddrToTCP) | 223 fd, e := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOC
K_STREAM, 0, "dial", sockaddrToTCP) |
223 if e != nil { | 224 if e != nil { |
224 return nil, e | 225 return nil, e |
225 } | 226 } |
226 return newTCPConn(fd), nil | 227 return newTCPConn(fd), nil |
227 } | 228 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 return l.fd.Close() | 285 return l.fd.Close() |
285 } | 286 } |
286 | 287 |
287 // Addr returns the listener's network address, a *TCPAddr. | 288 // Addr returns the listener's network address, a *TCPAddr. |
288 func (l *TCPListener) Addr() Addr { return l.fd.laddr } | 289 func (l *TCPListener) Addr() Addr { return l.fd.laddr } |
289 | 290 |
290 // File returns a copy of the underlying os.File, set to blocking mode. | 291 // File returns a copy of the underlying os.File, set to blocking mode. |
291 // It is the caller's responsibility to close f when finished. | 292 // It is the caller's responsibility to close f when finished. |
292 // Closing c does not affect f, and closing f does not affect c. | 293 // Closing c does not affect f, and closing f does not affect c. |
293 func (l *TCPListener) File() (f *os.File, err os.Error) { return l.fd.dup() } | 294 func (l *TCPListener) File() (f *os.File, err os.Error) { return l.fd.dup() } |
LEFT | RIGHT |