// Dropped returns the number of known dropped messages for this subscription.
// This will correspond to messages dropped by violations of PendingLimits. If
// the server declares the connection a SlowConsumer, this number may not be
// valid.
484838
func (sub *subscription) Dropped() (int, error) {
	sub.Lock()
	defer sub.Unlock()
	if sub.inboxSub == nil {
		return -1, ErrBadSubscription
	}
	return sub.inboxSub.Dropped()
}
1288608
func (t *Torrent) Drop() {
	t.cl.lock()
	t.cl.dropTorrent(t.infoHash)
	t.cl.unlock()
}
969307
func DropDB(c *Connection) error {
	deets := c.Dialect.Details()
	if deets.Database != "" {
		log(logging.Info, fmt.Sprintf("drop %s (%s)", deets.Database, c.URL()))
		return errors.Wrapf(c.Dialect.DropDB(), "couldn't drop database %s", deets.Database)
	}
	return nil
}
315110
func (s *ChainService) ConnectedCount() int32 {
	replyChan := make(chan int32)

	select {
	case s.query <- getConnCountMsg{reply: replyChan}:
		return <-replyChan
	case <-s.quit:
		return 0
	}

}
305176
func (c *EncodedConn) QueueSubscribe(subject, queue string, cb Handler) (*Subscription, error) {
	return c.subscribe(subject, queue, cb)
}
283424
func (s *RateLimitedSMSService) Send(phonenumber string, message string) (err error) {
	conn := db.NewSession()
	if conn == nil {
		return errors.New("Failed to get DB connection")
	}

	mgr := smshistory.NewManager(conn)

	sendCount, err := mgr.CountSMSHistorySince(phonenumber, time.Now().Add(-s.window))
	if err != nil && !db.IsNotFound(err) {
		log.Error("Failed to count sms history: ", err)
		return err
	}

	// if we've send more or equal than max sms count msges already return an error
	if sendCount >= s.maxSMS {
		log.Info("Rate limiting sms sending to ", phonenumber, ", already sent ", sendCount, " SMS in the last ", s.window)
		return ErrMaxSMS
	}

	// Add log entry
	record := smshistory.New(phonenumber)
	if err = mgr.AddSMSHistory(record); err != nil {
		return err
	}

	// Send the actual sms
	return s.actualService.Send(phonenumber, message)
}
47501
func (c *LRU) Drop(n int) {
	c.mu.Lock()
	c.drop(n)
	c.mu.Unlock()
}
591053
func (t Term) TableDrop(args ...interface{}) Term {
	return constructMethodTerm(t, "TableDrop", p.Term_TABLE_DROP, args, map[string]interface{}{})
}
720918
func (h *handler) handleSubscriptionResult(msg *jsonrpcMessage) {
	var result subscriptionResult
	if err := json.Unmarshal(msg.Params, &result); err != nil {
		h.log.Debug("Dropping invalid subscription message")
		return
	}
	if h.clientSubs[result.ID] != nil {
		h.clientSubs[result.ID].deliver(result.Result)
	}
}
1279774
func (db *DB) DropIndex(name string) error {
	return db.Update(func(tx *Tx) error {
		return tx.DropIndex(name)
	})
}
1165083
func Drop(in interface{}, n int) interface{} {
	value := reflect.ValueOf(in)
	valueType := value.Type()

	kind := value.Kind()

	if kind == reflect.Array || kind == reflect.Slice {
		length := value.Len()

		resultSlice := makeSlice(value, length-n)

		j := 0
		for i := n; i < length; i++ {
			resultSlice.Index(j).Set(value.Index(i))
			j++
		}

		return resultSlice.Interface()

	}

	panic(fmt.Sprintf("Type %s is not supported by Drop", valueType.String()))
}
702143
func (c *Conn) Receive() (reply interface{}, err error) {
	if c.ReceiveWait {
		<-c.ReceiveNow
	}

	if len(c.queue) == 0 && len(c.replies) == 0 {
		if len(c.SubResponses) > 0 {
			reply, err = c.SubResponses[0].Response, c.SubResponses[0].Error
			c.SubResponses = c.SubResponses[1:]
			return
		}
		return nil, fmt.Errorf("no more items")
	}

	if err := c.Flush(); err != nil {
		return nil, err
	}

	reply, err = c.replies[0].reply, c.replies[0].err
	c.replies = c.replies[1:]
	return
}
1143400
func (s *Subscription) Pending() (int, int, error) {
	if s == nil {
		return -1, -1, ErrBadSubscription
	}
	s.mu.Lock()
	defer s.mu.Unlock()
	if s.conn == nil {
		return -1, -1, ErrBadSubscription
	}
	if s.typ == ChanSubscription {
		return -1, -1, ErrTypeSubscription
	}
	return s.pMsgs, s.pBytes, nil
}
1061482
func (sub *Subscription) Pop() (*PublishedValue, error) {
	err := sub.ensureProtocol()
	if err != nil {
		return nil, err
	}
	result, err := sub.resp.receiveResultSet()
	if err != nil {
		return nil, err
	}
	// Analyse the result.
	kind, err := result.StringAt(0)
	if err != nil {
		return nil, err
	}
	switch {
	case strings.Contains(kind, "message"):
		channel, err := result.StringAt(1)
		if err != nil {
			return nil, err
		}
		value, err := result.ValueAt(2)
		if err != nil {
			return nil, err
		}
		return &PublishedValue{
			Kind:    kind,
			Channel: channel,
			Value:   value,
		}, nil
	case strings.Contains(kind, "subscribe"):
		channel, err := result.StringAt(1)
		if err != nil {
			return nil, err
		}
		count, err := result.IntAt(2)
		if err != nil {
			return nil, err
		}
		return &PublishedValue{
			Kind:    kind,
			Channel: channel,
			Count:   count,
		}, nil
	default:
		return nil, errors.New(ErrInvalidResponse, errorMessages, result)
	}
}
144027
func (c *MessageConnection) send() {
	// Start the ticker and defer stopping it and decrementing the
	// wait group counter.
	c.startTicker()
	defer func() {
		c.stopTicker()
		c.log("Goroutine sending to websocket has been closed", LogLevelDebug)
	}()

	for {
		select {
		// Receiving a message from the next handler
		case message, ok := <-c.Sender:
			if !ok {
				c.log("Sender channel has been closed", LogLevelError)
				c.disconnect <- errors.New("Sender channel has been closed")
				return
			}
			// Write the message as a byte array to the socket
			c.log("Writing %s to socket", LogLevelDebug, message)
			if err := c.write(websocket.TextMessage, message); err != nil {
				c.log("Error writing to socket: %s", LogLevelError, err)
				c.disconnect <- err
				return
			}

			c.keepAlive()
		// Ping the client
		case <-c.ticker.C:
			err := c.ping()
			c.log("%s", LogLevelDebug, err)
			if err := c.ping(); err != nil {
				c.log("Error pinging socket: %s", LogLevelError, err)
				c.disconnect <- err
				return
			}

		// Receiving disconnectSend from the closing Connection
		case <-c.disconnectSend:
			return
		}
	}
}
674167
func (m *MemoryBackend) Subscribe(client *Client, subs []packet.Subscription, ack Ack) error {
	// acquire global mutex
	m.globalMutex.Lock()
	defer m.globalMutex.Unlock()

	// save subscription
	for _, sub := range subs {
		client.Session().(*memorySession).subscriptions.Set(sub.Topic, sub)
	}

	// call ack if provided
	if ack != nil {
		ack()
	}

	// get session
	sess := client.Session().(*memorySession)

	// handle all subscriptions
	for _, sub := range subs {
		// get retained messages
		values := m.retainedMessages.Search(sub.Topic)

		// publish messages
		for _, value := range values {
			// add to temporary queue or return error if queue is full
			select {
			case sess.temporary <- value.(*packet.Message):
			default:
				return ErrQueueFull
			}
		}
	}

	return nil
}
414197
func (nc *Conn) QueueSubscribe(subj, queue string, cb MsgHandler) (*Subscription, error) {
	return nc.subscribe(subj, queue, cb, nil, false)
}