// conn reads the gandalf config and calls storage.Open to get a database connection.
//
// Most gandalf packages should probably use this function. storage.Open is intended for
// use when supporting more than one database.
488586
func conn() (*storage.Storage, error) {
	url, dbname := DbConfig()
	return storage.Open(url, dbname)
}
72801
func (m *Source) Open(table string) (schema.Conn, error) {
	//u.Infof("Open conn=%q", table)
	m.tblmu.Lock()
	t, ok := m.tables[table]
	m.tblmu.Unlock()
	if !ok {
		return nil, schema.ErrNotFound
	}
	m.mu.Lock()
	//u.Infof("after open lock")
	qc := newQueryConn(t, m)
	m.qryconns[table] = qc
	return qc, nil
}
150459
func Open(driverName, auth string) (*Conn, error) {
	driversMu.RLock()
	driveri, ok := drivers[driverName]
	driversMu.RUnlock()
	if !ok {
		return nil, fmt.Errorf("sms: unknown driver %q (forgotten import?)",
			driverName)
	}
	conn, err := driveri.Open(auth)
	if err != nil {
		return nil, err
	}
	c := &Conn{
		driver: driveri,
		conn:   conn,
	}
	return c, nil
}
937027
func NewConn(mailstore mailstore.Mailstore, netConn io.ReadWriteCloser, transcript io.Writer) (c *Conn) {
	c = new(Conn)
	c.Mailstore = mailstore
	c.Rwc = netConn
	c.Transcript = transcript
	return c
}
1323966
func newDBConn(ops Options) (*ScyllaDB, error) {
	r, err := newScyllaDB(ScyllaDBOpts{
		KeySpaceName: ops.Keyspace,
		NodeIps:      ops.Hosts,
		Username:     ops.Username,
		Password:     ops.Password,
		Debug:        true,
	})
	if err != nil {
		return nil, err
	}
	return r, nil
}
1129312
func (rc *Redis) Connect(config string) error {
	var cf map[string]string
	json.Unmarshal([]byte(config), &cf)
	if _, ok := cf["key"]; !ok {
		cf["key"] = DefaultKey
	}
	if _, ok := cf["conn"]; !ok {
		return errors.New("config has no conn key")
	}
	if _, ok := cf["dbnum"]; !ok {
		cf["dbnum"] = "0"
	}
	rc.key = cf["key"]
	rc.conninfo = cf["conn"]
	rc.dbnum, _ = strconv.Atoi(cf["dbnum"])
	rc.connectInit()

	c := rc.p.Get()
	defer c.Close()

	return c.Err()
}
819944
func Connect(config ConnConfig) (c *Conn, err error) {
	return connect(config, minimalConnInfo)
}
1273577
func (conn *Conn) String() string {
	str := "GoIRC Connection\n"
	str += "----------------\n\n"
	if conn.Connected() {
		str += "Connected to " + conn.cfg.Server + "\n\n"
	} else {
		str += "Not currently connected!\n\n"
	}
	str += conn.Me().String() + "\n"
	if conn.st != nil {
		str += conn.st.String() + "\n"
	}
	return str
}
354814
func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
	var err error

	// New mysqlConn
	mc := &mysqlConn{
		maxAllowedPacket: maxPacketSize,
		maxWriteSize:     maxPacketSize - 1,
	}
	mc.cfg, err = ParseDSN(dsn)
	if err != nil {
		return nil, err
	}
	mc.parseTime = mc.cfg.ParseTime
	mc.strict = mc.cfg.Strict

	// Connect to Server
	if dial, ok := dials[mc.cfg.Net]; ok {
		mc.netConn, err = dial(mc.cfg.Addr)
	} else {
		nd := net.Dialer{Timeout: mc.cfg.Timeout}
		mc.netConn, err = nd.Dial(mc.cfg.Net, mc.cfg.Addr)
	}
	if err != nil {
		return nil, err
	}

	// Enable TCP Keepalives on TCP connections
	if tc, ok := mc.netConn.(*net.TCPConn); ok {
		if err := tc.SetKeepAlive(true); err != nil {
			// Don't send COM_QUIT before handshake.
			mc.netConn.Close()
			mc.netConn = nil
			return nil, err
		}
	}

	mc.buf = newBuffer(mc.netConn)

	// Set I/O timeouts
	mc.buf.timeout = mc.cfg.ReadTimeout
	mc.writeTimeout = mc.cfg.WriteTimeout

	// Reading Handshake Initialization Packet
	cipher, err := mc.readInitPacket()
	if err != nil {
		mc.cleanup()
		return nil, err
	}

	// Send Client Authentication Packet
	if err = mc.writeAuthPacket(cipher); err != nil {
		mc.cleanup()
		return nil, err
	}

	// Handle response to auth packet, switch methods if possible
	if err = handleAuthResult(mc, cipher); err != nil {
		// Authentication failed and MySQL has already closed the connection
		// (https://dev.mysql.com/doc/internals/en/authentication-fails.html).
		// Do not send COM_QUIT, just cleanup and return the error.
		mc.cleanup()
		return nil, err
	}

	if mc.cfg.MaxAllowedPacket > 0 {
		mc.maxAllowedPacket = mc.cfg.MaxAllowedPacket
	} else {
		// Get max allowed packet size
		maxap, err := mc.getSystemVar("max_allowed_packet")
		if err != nil {
			mc.Close()
			return nil, err
		}
		mc.maxAllowedPacket = stringToInt(maxap) - 1
	}
	if mc.maxAllowedPacket < maxPacketSize {
		mc.maxWriteSize = mc.maxAllowedPacket
	}

	// Handle DSN Params
	err = mc.handleParams()
	if err != nil {
		mc.Close()
		return nil, err
	}

	return mc, nil
}
357426
func delConn(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr {
	vars := mux.Vars(r)
	containerId := vars["id"]

	con := d.connections.Get(containerId)

	if con == nil {
		return &HttpErr{http.StatusNotFound, "container not found"}
	}

	ctx := &ConnectionCtx{
		deleteConn,
		con.(*Connection),
		make(chan *Connection),
	}

	d.connectionChan <- ctx
	<-ctx.Result

	return nil
}
1197326
func (c *Conn) serve() {
	var err error
	for err == nil {
		err = c.recv()
	}

	c.closeWithError(err)
}
1038197
func SetUpConn(c *Config) (*bot.Bot, *ircevent.Connection) {
	return SetUp(c), ircConn
}
1356590
func NewConn(rw io.ReadWriter) *Conn {
	return &Conn{
		NewReader(rw),
		NewWriter(rw),
	}
}
1284775
func getConn(d *Daemon, w http.ResponseWriter, r *http.Request) *HttpErr {
	vars := mux.Vars(r)

	containerId := vars["id"]
	con := d.connections.Get(containerId)

	if con == nil {
		return &HttpErr{http.StatusNotFound, containerId}
	}

	data, err := json.Marshal(con.(*Connection))

	if err != nil {
		return &HttpErr{http.StatusInternalServerError, err.Error()}
	}

	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	w.Write(data)

	return nil
}
936114
func (s *Session) Open() (net.Conn, error) {
	conn, err := s.OpenStream()
	if err != nil {
		return nil, err
	}
	return conn, nil
}
58646
func (tx *Tx) Conn() (*TxConn, error) {
	dc, err := tx.grabConn()
	if err != nil {
		return nil, err
	}
	return &TxConn{Conn: dc.ci, Locker: &dc.Mutex}, nil
}
920644
func NewConn() (*Conn, error) {
	sp := strings.SplitN(os.Getenv("GPG_AGENT_INFO"), ":", 3)
	if len(sp) == 0 || len(sp[0]) == 0 {
		return nil, ErrNoAgent
	}
	addr := &net.UnixAddr{Net: "unix", Name: sp[0]}
	uc, err := net.DialUnix("unix", nil, addr)
	if err != nil {
		return nil, err
	}
	br := bufio.NewReader(uc)
	lineb, err := br.ReadSlice('\n')
	if err != nil {
		return nil, err
	}
	line := string(lineb)
	if !strings.HasPrefix(line, "OK") {
		return nil, fmt.Errorf("gpgagent: didn't get OK; got %q", line)
	}
	return &Conn{uc, br}, nil
}