"crypto/rsa"
"io"
"io/ioutil"
- "once"
+ "sync"
"time"
)
// The defaultConfig is used in place of a nil *Config in the TLS server and client.
var varDefaultConfig *Config
+var once sync.Once
+
func defaultConfig() *Config {
once.Do(initDefaultConfig)
return varDefaultConfig
import (
"bufio"
- "once"
"os"
"strings"
"sync"
}
}
+var once sync.Once
+
// TypeByExtension returns the MIME type associated with the file extension ext.
// The extension ext should begin with a leading dot, as in ".html".
// When ext has no associated type, TypeByExtension returns "".
package net
import (
- "once"
"os"
"rand"
+ "sync"
"time"
)
return ok
}
+var onceLoadConfig sync.Once
+
func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err os.Error) {
if !isDomainName(name) {
return name, nil, &DNSError{Error: "invalid domain name", Name: name}
}
- once.Do(loadConfig)
+ onceLoadConfig.Do(loadConfig)
if dnserr != nil || cfg == nil {
err = dnserr
return
// It returns the canonical name for the host and an array of that
// host's addresses.
func LookupHost(name string) (cname string, addrs []string, err os.Error) {
- once.Do(loadConfig)
+ onceLoadConfig.Do(loadConfig)
if dnserr != nil || cfg == nil {
err = dnserr
return
import (
"io"
- "once"
"os"
"sync"
"syscall"
// All the network FDs use a single pollServer.
var pollserver *pollServer
+var onceStartServer sync.Once
func startServer() {
p, err := newPollServer()
}
func newFD(fd, family, proto int, net string, laddr, raddr Addr) (f *netFD, err os.Error) {
- once.Do(startServer)
+ onceStartServer.Do(startServer)
if e := syscall.SetNonblock(fd, true); e != 0 {
return nil, &OpError{"setnonblock", net, laddr, os.Errno(e)}
}
package net
import (
- "once"
"os"
"sync"
"syscall"
"unsafe"
)
+var onceStartServer sync.Once
+
// BUG(brainman): The Windows implementation does not implement SetTimeout.
// IO completion result parameters.
// All the network FDs use a single pollServer.
var pollserver *pollServer
+var onceStartServer sync.Once
func startServer() {
p, err := newPollServer()
if initErr != nil {
return nil, initErr
}
- once.Do(startServer)
+ onceStartServer.Do(startServer)
// Associate our socket with pollserver.iocp.
if _, e := syscall.CreateIoCompletionPort(int32(fd), pollserver.iocp, 0, 0); e != 0 {
return nil, &OpError{"CreateIoCompletionPort", net, laddr, os.Errno(e)}
syscall.ForkLock.RUnlock()
// Associate our new socket with IOCP.
- once.Do(startServer)
+ onceStartServer.Do(startServer)
if _, e = syscall.CreateIoCompletionPort(int32(s), pollserver.iocp, 0, 0); e != 0 {
return nil, &OpError{"CreateIoCompletionPort", fd.net, fd.laddr, os.Errno(e)}
}
package net
import (
- "once"
"os"
+ "sync"
"syscall"
)
+var onceReadProtocols sync.Once
+
func sockaddrToIP(sa syscall.Sockaddr) Addr {
switch sa := sa.(type) {
case *syscall.SockaddrInet4:
}
func netProtoSplit(netProto string) (net string, proto int, err os.Error) {
- once.Do(readProtocols)
+ onceReadProtocols.Do(readProtocols)
i := last(netProto, ':')
if i+1 >= len(netProto) { // no colon
return "", 0, os.ErrorString("no IP protocol specified")
package net
import (
- "once"
"os"
+ "sync"
)
var services map[string]map[string]int
var servicesError os.Error
+var onceReadServices sync.Once
func readServices() {
services = make(map[string]map[string]int)
// LookupPort looks up the port for the given network and service.
func LookupPort(network, service string) (port int, err os.Error) {
- once.Do(readServices)
+ onceReadServices.Do(readServices)
switch network {
case "tcp4", "tcp6":
package os
import (
- "once"
+ "sync"
)
// ENOENV is the Error indicating that an environment variable does not exist.
var ENOENV = NewError("no such environment variable")
var env map[string]string
+var once sync.Once
func copyenv() {
"http"
"log"
"net"
- "once"
"os"
"strings"
+ "sync"
"testing"
)
var serverAddr string
var httpServerAddr string
+var once sync.Once
const second = 1e9
package time
import (
- "once"
+ "sync"
)
// A Ticker holds a synchronous channel that delivers `ticks' of a clock
}
}
+var onceStartTickerLoop sync.Once
+
// NewTicker returns a new Ticker containing a channel that will
// send the time, in nanoseconds, every ns nanoseconds. It adjusts the
// intervals to make up for pauses in delivery of the ticks.
}
c := make(chan int64, 1) // See comment on send in tickerLoop
t := &Ticker{c, c, ns, false, Nanoseconds() + ns, nil}
- once.Do(startTickerLoop)
+ onceStartTickerLoop.Do(startTickerLoop)
// must be run in background so global Tickers can be created
go func() { newTicker <- t }()
return t
}
var zones []zonetime
+var onceSetupZone sync.Once
func setupZone() {
// consult $TZ to find the time zone to use.
// Look up the correct time zone (daylight savings or not) for the given unix time, in the current location.
func lookupTimezone(sec int64) (zone string, offset int) {
- once.Do(setupZone)
+ onceSetupZone.Do(setupZone)
if len(zones) == 0 {
return "UTC", 0
}
import (
"io/ioutil"
- "once"
"os"
+ "sync"
)
const (
}
var zones []zonetime
+var onceSetupZone sync.Once
func setupZone() {
// consult $TZ to find the time zone to use.
// Look up the correct time zone (daylight savings or not) for the given unix time, in the current location.
func lookupTimezone(sec int64) (zone string, offset int) {
- once.Do(setupZone)
+ onceSetupZone.Do(setupZone)
if len(zones) == 0 {
return "UTC", 0
}
// For a system in Sydney, "EST" and "EDT", though they have
// different meanings than they do in New York.
func lookupByName(name string) (off int, found bool) {
- once.Do(setupZone)
+ onceSetupZone.Do(setupZone)
for _, z := range zones {
if name == z.zone.name {
return z.zone.utcoff, true
import (
"syscall"
- "os"
"once"
+ "os"
)
// BUG(brainman): The Windows implementation assumes that
var tz zoneinfo
var initError os.Error
+var onceSetupZone sync.Once
func setupZone() {
var i syscall.Timezoneinformation
// Look up the correct time zone (daylight savings or not) for the given unix time, in the current location.
func lookupTimezone(sec int64) (zone string, offset int) {
- once.Do(setupZone)
+ onceSetupZone.Do(setupZone)
if initError != nil {
return "", 0
}
// time zone with the given abbreviation. It only considers
// time zones that apply to the current system.
func lookupByName(name string) (off int, found bool) {
- once.Do(setupZone)
+ onceSetupZone.Do(setupZone)
if initError != nil {
return 0, false
}
"io"
"log"
"net"
- "once"
+ "sync"
"testing"
)
var serverAddr string
+var once sync.Once
func echoServer(ws *Conn) { io.Copy(ws, ws) }