// AddOfferConnection creates a new offer connection record, which records details about a
// relation made from a remote model to an offer in the local model.
482099
func (st *State) AddOfferConnection(args AddOfferConnectionParams) (_ *OfferConnection, err error) {
	defer errors.DeferredAnnotatef(&err, "cannot add offer record for %q", args.OfferUUID)

	if err := validateOfferConnectionParams(args); err != nil {
		return nil, errors.Trace(err)
	}

	model, err := st.Model()
	if err != nil {
		return nil, errors.Trace(err)
	} else if model.Life() != Alive {
		return nil, errors.Errorf("model is no longer alive")
	}

	// Create the application addition operations.
	offerConnectionDoc := offerConnectionDoc{
		SourceModelUUID: args.SourceModelUUID,
		OfferUUID:       args.OfferUUID,
		UserName:        args.Username,
		RelationId:      args.RelationId,
		RelationKey:     args.RelationKey,
		DocID:           fmt.Sprintf("%d", args.RelationId),
	}
	buildTxn := func(attempt int) ([]txn.Op, error) {
		// If we've tried once already and failed, check that
		// model may have been destroyed.
		if attempt > 0 {
			if err := checkModelActive(st); err != nil {
				return nil, errors.Trace(err)
			}
			return nil, errors.AlreadyExistsf("offer connection for relation id %d", args.RelationId)
		}
		ops := []txn.Op{
			model.assertActiveOp(),
			{
				C:      offerConnectionsC,
				Id:     offerConnectionDoc.DocID,
				Assert: txn.DocMissing,
				Insert: &offerConnectionDoc,
			},
		}
		return ops, nil
	}
	if err = st.db().Run(buildTxn); err != nil {
		return nil, errors.Trace(err)
	}
	return &OfferConnection{doc: offerConnectionDoc}, nil
}
905200
func IsConnectionProblem(e error) bool {
	type ad interface {
		IsConnectionProblemError() bool
	}
	_, ok := Unwrap(e).(ad)
	return ok
}
682553
func newConnection() (*Conn, error) {
	c := new(Conn)
	if err := c.initConnection(); err != nil {
		return nil, err
	}

	return c, nil
}
1365656
func (p *IOThrottlerPool) AddConn(conn net.Conn) (net.Conn, error) {

	rwCloser, err := p.AddReadWriter(conn)
	if err != nil {
		return nil, err
	}
	throttledRWC, ok := rwCloser.(*throttledReadWriteCloser)
	if !ok {
		log.Fatalf("Programming error, expecting *throttledReadWriteCloser but got %v", rwCloser)
	}

	return &throttledConn{*throttledRWC, conn}, nil
}
265235
func AllowReconnection(v bool) Option {
	return func(c *client) Option {
		old := c.allowReconnect
		c.allowReconnect = v
		return AllowReconnection(old)
	}
}
1252648
func OnDisconnect(onDisconnect func(remoteAddr string)) func(*wsConnection) {
	return func(wsc *wsConnection) {
		wsc.onDisconnect = onDisconnect
	}
}
406795
func (t *Torrent) addConnection(c *connection) (err error) {
	defer func() {
		if err == nil {
			torrent.Add("added connections", 1)
		}
	}()
	if t.closed.IsSet() {
		return errors.New("torrent closed")
	}
	for c0 := range t.conns {
		if c.PeerID != c0.PeerID {
			continue
		}
		if !t.cl.config.dropDuplicatePeerIds {
			continue
		}
		if left, ok := c.hasPreferredNetworkOver(c0); ok && left {
			c0.Close()
			t.deleteConnection(c0)
		} else {
			return errors.New("existing connection preferred")
		}
	}
	if len(t.conns) >= t.maxEstablishedConns {
		c := t.worstBadConn()
		if c == nil {
			return errors.New("don't want conns")
		}
		c.Close()
		t.deleteConnection(c)
	}
	if len(t.conns) >= t.maxEstablishedConns {
		panic(len(t.conns))
	}
	t.conns[c] = struct{}{}
	return nil
}
17982
func (client *Client) closeConnection(connectionID int) error {
	request := newOpClientRequest(opClientCloseConnection, connectionID)
	client.opRequests <- request
	response := <-request.response
	if val, ok := response.(error); ok {
		return val
	}
	return nil
}
448727
func (s *SocketHub) AddConnection(ws *SocketWorker) {
	var ok bool

	s.so.RLock()
	ok = s.sockets[ws]
	s.so.RUnlock()

	if ok {
		return
	}

	s.so.Lock()
	s.sockets[ws] = true
	s.so.Unlock()

	go s.manageSocket(ws)
}
559873
func (process *TeleportProcess) addConnector(connector *Connector) {
	process.Lock()
	defer process.Unlock()

	process.connectors[connector.ClientIdentity.ID.Role] = connector
}
513549
func (obj *Doc) CreateConnection(ctx context.Context, connection *Connection) (string, error) {
	result := &struct {
		ConnectionId string	`json:"qConnectionId"`
	} {}
	err := obj.rpc(ctx, "CreateConnection", result, connection)
	return result.ConnectionId, err 
}
945228
func OpenConnection(tag, network, address string, db int) *redisConnection {
	redisClient := redis.NewClient(&redis.Options{
		Network: network,
		Addr:    address,
		DB:      db,
	})
	return OpenConnectionWithRedisClient(tag, redisClient)
}
849257
func OnConnect(c websocket.Connection) {
	fmt.Println("socket.OnConnect()")
	c.On("join", func(message string) { OnJoin(message, c) })
	c.On("objectupdate", func(message string) { OnObjectUpdated(message, c) })
	// ok works too c.EmitMessage([]byte("dsadsa"))
	c.OnDisconnect(func() { OnDisconnect(c) })

}
982676
func (pn *peernet) addConn(c *conn) {
	pn.Lock()
	defer pn.Unlock()

	cs, found := pn.connsByPeer[c.RemotePeer()]
	if !found {
		cs = map[*conn]struct{}{}
		pn.connsByPeer[c.RemotePeer()] = cs
	}
	pn.connsByPeer[c.RemotePeer()][c] = struct{}{}

	cs, found = pn.connsByLink[c.link]
	if !found {
		cs = map[*conn]struct{}{}
		pn.connsByLink[c.link] = cs
	}
	pn.connsByLink[c.link][c] = struct{}{}
}
518618
func (n *NotifyRouter) AddConnection(xp rpc.Transporter, ch chan error) ConnectionID {
	if n == nil {
		return 0
	}
	id := n.cm.AddConnection(xp, ch)
	n.setNotificationChannels(id, keybase1.NotificationChannels{})
	return id
}
600192
func NewConnection(addrs []string, opts ConnectionOpts) Connector {
	return &newConnection{
		addrs: addrs,
		opts:  opts,
	}
}
846299
func (s *Simulator) NewConnection() *Connection {
	addr := s.LocalAddr()
	return &Connection{
		Hostname:  addr.IP.String(),
		Port:      addr.Port,
		Interface: "lan",
	}
}