// SendSyncByte sends a message that uses byte encoder using the sync API
548593
func (conn *BytesConnectionStr) SendSyncByte(topic string, key []byte, value []byte) (offset int64, err error) {
	return conn.SendSyncMessage(topic, sarama.ByteEncoder(key), sarama.ByteEncoder(value))
}
896095
func (enc *Encoder) writeBytes(p []byte) {
	enc.buf = append(enc.buf, p...)
}
321744
func (s *Socket) SendBINC(data interface{}) (err error) {
	w, err := s.NextWriter(websocket.BinaryMessage)
	if err != nil {
		return err
	}
	if data != nil {
		codec.NewEncoder(w, &bh).Encode(data)
	}
	return w.Close()
}
778819
func (c *MConnection) Send(chID byte, msgBytes []byte) bool {
	if !c.IsRunning() {
		return false
	}

	c.Logger.Debug("Send", "channel", chID, "conn", c, "msgBytes", fmt.Sprintf("%X", msgBytes))

	// Send message to channel.
	channel, ok := c.channelsIdx[chID]
	if !ok {
		c.Logger.Error(fmt.Sprintf("Cannot send bytes, unknown channel %X", chID))
		return false
	}

	success := channel.sendBytes(msgBytes)
	if success {
		// Wake up sendRoutine if necessary
		select {
		case c.send <- struct{}{}:
		default:
		}
	} else {
		c.Logger.Debug("Send failed", "channel", chID, "conn", c, "msgBytes", fmt.Sprintf("%X", msgBytes))
	}
	return success
}
1309997
func (s *Server) SendSync(m Message) error {
	var eg errgroup.Group
	msg, err := s.serializer.Marshal(m)
	if err != nil {
		return fmt.Errorf("marshaling message: %v", err)
	}
	msg = append([]byte{getMessageType(m)}, msg...)

	for _, node := range s.cluster.Nodes() {
		node := node
		// Don't forward the message to ourselves.
		if s.uri == node.URI {
			continue
		}

		eg.Go(func() error {
			return s.defaultClient.SendMessage(context.Background(), &node.URI, msg)
		})
	}

	return eg.Wait()
}
634458
func (r *rpcServer) sendPaymentSync(ctx context.Context,
	nextPayment *rpcPaymentRequest) (*lnrpc.SendResponse, error) {

	// We don't allow payments to be sent while the daemon itself is still
	// syncing as we may be trying to sent a payment over a "stale"
	// channel.
	if !r.server.Started() {
		return nil, fmt.Errorf("chain backend is still syncing, server " +
			"not active yet")
	}

	// First we'll attempt to map the proto describing the next payment to
	// an intent that we can pass to local sub-systems.
	payIntent, err := extractPaymentIntent(nextPayment)
	if err != nil {
		return nil, err
	}

	// With the payment validated, we'll now attempt to dispatch the
	// payment.
	resp, saveErr := r.dispatchPaymentIntent(&payIntent)
	switch {
	case saveErr != nil:
		return nil, saveErr

	case resp.Err != nil:
		return &lnrpc.SendResponse{
			PaymentError: resp.Err.Error(),
			PaymentHash:  payIntent.rHash[:],
		}, nil
	}

	return &lnrpc.SendResponse{
		PaymentHash:     payIntent.rHash[:],
		PaymentPreimage: resp.Preimage[:],
		PaymentRoute:    r.routerBackend.MarshallRoute(resp.Route),
	}, nil
}
978465
func (self *LesTxRelay) send(txs types.Transactions, count int) {
	sendTo := make(map[*peer]types.Transactions)

	self.peerStartPos++ // rotate the starting position of the peer list
	if self.peerStartPos >= len(self.peerList) {
		self.peerStartPos = 0
	}

	for _, tx := range txs {
		hash := tx.Hash()
		ltr, ok := self.txSent[hash]
		if !ok {
			ltr = &ltrInfo{
				tx:     tx,
				sentTo: make(map[*peer]struct{}),
			}
			self.txSent[hash] = ltr
			self.txPending[hash] = struct{}{}
		}

		if len(self.peerList) > 0 {
			cnt := count
			pos := self.peerStartPos
			for {
				peer := self.peerList[pos]
				if _, ok := ltr.sentTo[peer]; !ok {
					sendTo[peer] = append(sendTo[peer], tx)
					ltr.sentTo[peer] = struct{}{}
					cnt--
				}
				if cnt == 0 {
					break // sent it to the desired number of peers
				}
				pos++
				if pos == len(self.peerList) {
					pos = 0
				}
				if pos == self.peerStartPos {
					break // tried all available peers
				}
			}
		}
	}

	for p, list := range sendTo {
		pp := p
		ll := list
		enc, _ := rlp.EncodeToBytes(ll)

		reqID := genReqID()
		rq := &distReq{
			getCost: func(dp distPeer) uint64 {
				peer := dp.(*peer)
				return peer.GetTxRelayCost(len(ll), len(enc))
			},
			canSend: func(dp distPeer) bool {
				return !dp.(*peer).isOnlyAnnounce && dp.(*peer) == pp
			},
			request: func(dp distPeer) func() {
				peer := dp.(*peer)
				cost := peer.GetTxRelayCost(len(ll), len(enc))
				peer.fcServer.QueuedRequest(reqID, cost)
				return func() { peer.SendTxs(reqID, cost, enc) }
			},
		}
		self.reqDist.queue(rq)
	}
}
794806
func (queue *AMQP) SendBytes(bytes []byte) error {

	conn, err := amqp.Dial(queue.host)
	if err != nil {
		return err
	}
	defer conn.Close()

	ch, err := conn.Channel()
	if err != nil {
		return err
	}
	defer ch.Close()

	err = ch.Publish(
		"",         // exchange
		queue.Name, // routing key
		false,      // mandatory
		false,
		amqp.Publishing{
			DeliveryMode: amqp.Persistent,
			ContentType:  "application/octet-stream",
			Body:         bytes,
		})

	return err
}
1152521
func (s *sender) Send(message interface{}) error {
	s.encodeLock.Lock()
	defer s.encodeLock.Unlock()
	if s.encoder == nil {
		s.buffer = bufio.NewWriter(s.stream)
		s.encoder = msgpack.NewEncoder(s.buffer)
		s.encoder.AddExtensions(s.stream.initializeExtensions())
	}

	if err := s.encoder.Encode(message); err != nil {
		return err
	}

	return s.buffer.Flush()
}
1205389
func (c *MockConnection) Send(sinfo *ab.SeekInfo) error {
	if c.Closed() {
		return errors.New("mock connection is closed")
	}

	switch seek := sinfo.Start.Type.(type) {
	case *ab.SeekPosition_Specified:
		// Deliver all blocks from the given block number
		fromBlock := seek.Specified.Number
		c.Ledger().SendFrom(fromBlock)
	case *ab.SeekPosition_Oldest:
		// Deliver all blocks from the beginning
		c.Ledger().SendFrom(0)
	}

	return nil
}
731478
func (s *SesMailer) SendAsync(to, subject, htmlbody string) {
	go func() {
		if err := s.SendMail(to, subject, htmlbody); err != nil {
			beego.Error(fmt.Sprintf("Async send email not send emails: %s", err))
		}
	}()
}
365391
func (cn *conn) sendSimpleMessage(typ byte) (err error) {
	_, err = cn.c.Write([]byte{typ, '\x00', '\x00', '\x00', '\x04'})
	return err
}
880020
func (c *Conn) writeAsync(b []byte) (int, error) {
	// Prevent concurrent writes.
	c.buf.writeMu.Lock()
	defer c.buf.writeMu.Unlock()

	// Get the max buffer size to determine if the buffer's capacity
	// should be grown.
	c.buf.configMu.RLock()
	max := c.buf.max
	c.buf.configMu.RUnlock()

	// If the provided data is too large for the buffer then force
	// a synchrnous write.
	if max > 0 && len(b) > max {
		return c.writeSync(b)
	}

	// Lock access to the buffer. This prevents concurrent writes to
	// the buffer. Occasionally the lock is released temporarily to
	// check if the buffer's length allows this write operation to
	// proceed.
	c.buf.dataMu.Lock()

	// If the max buffer size is non-zero and larger than the
	// capacity of the buffer, then grow the buffer capacity.
	if max > 0 && max > c.buf.data.Cap() {
		c.buf.data.Grow(max)
	}

	// Wait until there is room in the buffer to proceed.
	for max > 0 && c.buf.data.Len()+len(b) > c.buf.data.Cap() {
		c.buf.dataMu.Unlock()
		c.buf.dataMu.Lock()
	}
	defer c.buf.dataMu.Unlock()

	// Write the data to the buffer.
	n, err := c.buf.data.Write(b)
	if err != nil {
		return n, err
	} else if n < len(b) {
		return n, fmt.Errorf("trunc write: exp=%d act=%d", len(b), n)
	}

	// Record the number of bytes written in a FIFO list.
	c.buf.dataN = append(c.buf.dataN, n)

	// Start a goroutine that reads n bytes from the buffer where n
	// is the first element in the FIFO list from above. The read
	// below may not actually correspond to the write from above;
	// that's okay. The important thing is the order of the reads,
	// and that's achieved using the circular buffer and FIFO list
	// of bytes written.
	go func() {
		// The read operation must also obtain a lock, preventing
		// concurrent access to the buffer.
		c.buf.dataMu.Lock()

		// Get the number of bytes to read.
		n := c.buf.dataN[0]
		c.buf.dataN = c.buf.dataN[1:]

		// Read the bytes from the buffer into a temporary buffer.
		b := make([]byte, n)
		if nr, err := c.buf.data.Read(b); err != nil {
			go func() { c.buf.errs <- err }()
			c.buf.dataMu.Unlock()
			return
		} else if nr < n {
			go func() {
				c.buf.errs <- fmt.Errorf("trunc read: exp=%d act=%d", n, nr)
			}()
			c.buf.dataMu.Unlock()
			return
		}

		// Ensure access to the buffer is restored.
		defer c.buf.dataMu.Unlock()

		// Write the temporary buffer into the underlying connection.
		if nw, err := c.writeSync(b); err != nil {
			go func() { c.buf.errs <- err }()
			return
		} else if nw < n {
			go func() {
				c.buf.errs <- fmt.Errorf("trunc write: exp=%d act=%d", n, nw)
			}()
			return
		}
	}()

	return n, nil
}
1157491
func (t *HTTPTransporter) SendSnapshotRequest(server Server, peer *Peer, req *SnapshotRequest) *SnapshotResponse {
	var b bytes.Buffer
	if _, err := req.Encode(&b); err != nil {
		traceln("transporter.rv.encoding.error:", err)
		return nil
	}

	url := joinPath(peer.ConnectionString, t.snapshotPath)
	traceln(server.Name(), "POST", url)

	httpResp, err := t.httpClient.Post(url, "application/protobuf", &b)
	if httpResp == nil || err != nil {
		traceln("transporter.rv.response.error:", err)
		return nil
	}
	defer httpResp.Body.Close()

	resp := &SnapshotResponse{}
	if _, err = resp.Decode(httpResp.Body); err != nil && err != io.EOF {
		traceln("transporter.rv.decoding.error:", err)
		return nil
	}

	return resp
}
136533
func (c *Client) Send(ctx context.Context, msg interface{}) error {
	return c.asynchronous.Send(ctx, msg)
}
271293
func (s *Streamer) SendBytes(id, event string, data []byte) {
	dataLen := len(data)
	lfCount := 0

	// We must sent a "data:{data}\n" for each line
	if dataLen > 0 {
		lfCount = bytes.Count(data, []byte("\n"))
		if lfCount > 0 {
			dataLen += (5 * lfCount) // data:
		}
	}

	p := format(id, event, dataLen)

	// fill in data lines
	start := 0
	ins := len(p) - (2 + dataLen)
	for i := 0; lfCount > 0; i++ {
		if data[i] == '\n' {
			copy(p[ins:], data[start:i])
			ins += i - start
			copy(p[ins:], "\ndata:")
			ins += 6

			start = i + 1
			lfCount--
		}
	}
	copy(p[ins:], data[start:])

	s.event <- p
}
1063729
func (c *Client) send(pkt packet.Generic, async bool) error {
	// reset keep alive tracker
	c.tracker.Reset()

	// send packet
	err := c.conn.Send(pkt, async)
	if err != nil {
		return err
	}

	// log sent packet
	if c.Logger != nil {
		c.Logger(fmt.Sprintf("Sent: %s", pkt.String()))
	}

	return nil
}