OLD | NEW |
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 /* | 5 /* |
6 Package net provides a portable interface for network I/O, including | 6 Package net provides a portable interface for network I/O, including |
7 TCP/IP, UDP, domain name resolution, and Unix domain sockets. | 7 TCP/IP, UDP, domain name resolution, and Unix domain sockets. |
8 | 8 |
9 Although the package provides access to low-level networking | 9 Although the package provides access to low-level networking |
10 primitives, most clients will need only the basic interface provided | 10 primitives, most clients will need only the basic interface provided |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 d.Unlock() | 426 d.Unlock() |
427 } | 427 } |
428 | 428 |
429 func (d *deadline) setTime(t time.Time) { | 429 func (d *deadline) setTime(t time.Time) { |
430 if t.IsZero() { | 430 if t.IsZero() { |
431 d.set(0) | 431 d.set(0) |
432 } else { | 432 } else { |
433 d.set(t.UnixNano()) | 433 d.set(t.UnixNano()) |
434 } | 434 } |
435 } | 435 } |
| 436 |
| 437 // Limit the number of concurrent cgo-using goroutines, because |
| 438 // each will block an entire operating system thread. The usual culprit |
| 439 // is resolving many DNS names in separate goroutines but the DNS |
| 440 // server is not responding. Then the many lookups each use a different |
| 441 // thread, and the system or the program runs out of threads. |
| 442 |
| 443 var threadLimit = make(chan struct{}, 500) |
| 444 |
| 445 func acquireThread() { |
| 446 threadLimit <- struct{}{} |
| 447 } |
| 448 |
| 449 func releaseThread() { |
| 450 <-threadLimit |
| 451 } |
OLD | NEW |