// Return a new session with the connection
// client has a writer and reader buffer
485761
func (s *Server) newClient(rwc net.Conn) (c *client, err error) {
	c = &client{
		srv: s,
		rwc: rwc,
		br:  bufio.NewReader(rwc),
		bw:  bufio.NewWriter(rwc),
	}
	return c, nil
}
674155
func (db *dbusImpl) SessionBus() (Connection, error) {
	if db.sessionBus == nil {
		bus, err := godbus.SessionBus()
		if err != nil {
			return nil, err
		}
		db.sessionBus = &connImpl{bus}
	}

	return db.sessionBus, nil
}
1071040
func New(pool *redis.Pool, reconnectPolicy conn.ReconnectPolicy) *Client {
	return &Client{
		eventEmitter: newEventEmitter(),
		state:        blueprint.Machine(),
		stateLock:    new(sync.Mutex),
		pool:         pool,
		subscribed:   map[string][]*Listener{},
		policy:       reconnectPolicy,
		tasks:        make(chan task, 128),
	}
}
1188894
func (m *Manager) Client(name string) rest.Client {
	return m.services[name]
}
589372
func NewClient(conn io.ReadWriteCloser) *rpc.Client {
	return rpc.NewClientWithCodec(NewClientCodec(conn))
}
422065
func NewSessionClient(s *ssh.Session) (*SessionClient, error) {
	writer, err := s.StdinPipe()
	if err != nil {
		return nil, err
	}

	reader, err := s.StdoutPipe()
	if err != nil {
		return nil, err
	}

	var wg sync.WaitGroup

	return &SessionClient{
		writer: writer,
		reader: reader,
		wg:     &wg,
		errors: make(chan error),
	}, nil
}
260896
func NewClient() *Client {
	detector := newDetector()
	session := session.NewClient(nil)

	return &Client{
		detector: detector,
		session:  session,
	}
}
895541
func NewClient(clientConfig ClientConfig) *Client {
	client := &Client{
		ClientConfig: clientConfig,
	}

	// If reader is nil use default rand.Reader
	if clientConfig.Reader == nil {
		client.Reader = rand.Reader
	}

	// If hash is nil use default sha256
	if clientConfig.Hash == nil {
		client.Hash = sha256.New()
	}

	return client
}
1017484
func Write(client Client, writer Writer, msg message.Msg) (message.Msg, error) {
	return sessionFunc(client, writer.Write(msg))
}
961490
func Client(c *http.Client) func(*Attacker) {
	return func(a *Attacker) { a.client = *c }
}
1194915
func Client(conn net.Conn, config *Config) *Conn {
	return &Conn{conn: conn, config: config, isClient: true}
}
1104911
func (db Db) Session() *DbSession {
	return &DbSession{db: db, Session: db.mainSession.Copy()}
}
214554
func NewClient(conn io.ReadWriteCloser) *Client {
	encBuf := bufio.NewWriter(conn)
	client := &gobClientCodec{conn, gob.NewDecoder(conn), gob.NewEncoder(encBuf), encBuf}
	return NewClientWithCodec(client)
}
519612
func (t *TestTLSServer) NewClientFromWebSession(sess services.WebSession) (*Client, error) {
	tlsConfig, err := t.Identity.TLSConfig(t.AuthServer.CipherSuites)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	tlsCert, err := tls.X509KeyPair(sess.GetTLSCert(), sess.GetPriv())
	if err != nil {
		return nil, trace.Wrap(err, "failed to parse TLS cert and key")
	}
	tlsConfig.Certificates = []tls.Certificate{tlsCert}
	addrs := []utils.NetAddr{utils.FromAddr(t.Listener.Addr())}
	return NewTLSClient(ClientConfig{Addrs: addrs, TLS: tlsConfig})
}
465775
func (c *Conn) getClient() (*StreamClient, error) {
	// Check for cached client
	c.clientLock.Lock()
	front := c.clients.Front()
	if front != nil {
		c.clients.Remove(front)
	}
	c.clientLock.Unlock()
	if front != nil {
		return front.Value.(*StreamClient), nil
	}

	// Open a new session
	stream, err := c.session.Open()
	if err != nil {
		return nil, err
	}

	// Create the RPC client
	codec := msgpackrpc.NewClientCodec(stream)

	// Return a new stream client
	sc := &StreamClient{
		stream: stream,
		codec:  codec,
	}
	return sc, nil
}
373678
func (s *S3Storage) Client() (*s3.S3, error) {
	auth, err := s.Auth()

	if err != nil {
		return nil, err
	}

	return s3.New(auth, s.Region), nil
}
114388
func NewClient(w io.Writer, r io.Reader) *Client {
	return &Client{
		r: NewReader(r),
		w: NewWriter(w),
	}
}