// Send a buffer to the Pool to reuse for other instances.
// You may no longer utilize the content of the buffer, since it may be used
// by other goroutines.
350741
func Pool(b []byte) {
	if b == nil {
		return
	}
	c := cap(b)

	// Our smallest buffer is 64 bytes, so we discard smaller buffers.
	if c < 64 {
		return
	}

	// We need to put the incoming buffer into the NEXT buffer,
	// since a buffer guarantees AT LEAST the number of bytes available
	// that is the top of this buffer.
	// That is the reason for dividing the cap by 2, so it gets into the NEXT bucket.
	// We add 2 to avoid rounding down if size is exactly power of 2.
	pn := poolNum((c + 2) >> 1)
	if pn != -1 {
		pools[pn].Put(b[0:0])
	}
	// if we didn't have a slot for this []byte, we just drop it and let the GC
	// take care of it.
}
166773
func (c *Connection) Send(ctx context.Context, messageParts ...[]byte) (<-chan Message, error) {
	if ctx == nil {
		ctx = context.Background()
	}
	msgID := atomic.AddUint64(&c.lastMessageID, 1)
	chunks, err := buildChunks(msgID, c.maxChunkSize, messageParts...)
	if err != nil {
		return nil, driver.WithStack(err)
	}
	// Prepare for receiving a response
	m := c.msgStore.Add(msgID)
	responseChan := m.responseChan

	//panic(fmt.Sprintf("chunks: %d, messageParts: %d, first: %s", len(chunks), len(messageParts), hex.EncodeToString(messageParts[0])))

	// Send all chunks
	sendErrors := make(chan error)
	deadline, ok := ctx.Deadline()
	if !ok {
		deadline = time.Time{}
	}
	go func() {
		defer close(sendErrors)
		for _, chunk := range chunks {
			if err := c.sendChunk(deadline, chunk); err != nil {
				// Cancel response
				c.msgStore.Remove(msgID)
				// Return error
				sendErrors <- driver.WithStack(err)
				return
			}
		}
	}()

	// Wait for sending to be ready, or context to be cancelled.
	select {
	case err := <-sendErrors:
		if err != nil {
			return nil, driver.WithStack(err)
		}
		return responseChan, nil
	case <-ctx.Done():
		return nil, ctx.Err()
	}
}
408347
func (t *AsyncTransport) Send(body map[string]interface{}) error {
	if len(t.bodyChannel) < t.Buffer {
		t.waitGroup.Add(1)
		p := payload{
			body:        body,
			retriesLeft: t.RetryAttempts,
		}
		t.bodyChannel <- p
	} else {
		err := ErrBufferFull{}
		rollbarError(t.Logger, err.Error())
		if t.PrintPayloadOnError {
			writePayloadToStderr(t.Logger, body)
		}
		return err
	}
	return nil
}
1347512
func (c *DeliverConnection) Send(seekInfo *ab.SeekInfo) error {
	if c.Closed() {
		return errors.New("connection is closed")
	}

	logger.Debugf("Sending %#v", seekInfo)

	env, err := c.createSignedEnvelope(seekInfo)
	if err != nil {
		return err
	}

	return c.deliverStream().Send(env)
}
932051
func (r *Runner) Buffer() *gbytes.Buffer {
	if r.sessionReady == nil {
		ginkgo.Fail(fmt.Sprintf("ginkgomon.Runner '%s' improperly created without using New", r.Name))
	}
	<-r.sessionReady
	return r.session.Buffer()
}
479026
func (oc ChanOutput) Send(v interface{}) (err error) {
	if oc == nil {
		return errors.New("nil channel")
	}

	// We allow ourselves a timeout of 1 second.
	t := time.NewTimer(time.Second)
	defer t.Stop()

	select {
	case oc <- v:
	case <-t.C:
		return errors.New("failed to send (not listening)")
	}
	return nil
}
844355
func (b *Buffer) Flush() {
	b.prepare(b.bufferSize())

	for i := range b.buffers {
		if buffer := &b.buffers[i]; buffer.acquire() {
			buffer.flush(b.Serializer, buffer.len())
			buffer.release()
		}
	}
}
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()
}
555957
func (s *SimpleSender) Send(data []byte) (int, error) {
	// no need for locking here, as the underlying fdNet
	// already serialized writes
	n, err := s.c.(*net.UDPConn).WriteToUDP(data, s.ra)
	if err != nil {
		return 0, err
	}
	if n == 0 {
		return n, errors.New("Wrote no bytes")
	}
	return n, nil
}
765745
func (c *Client) Send(message string) error {
	_, err := c.conn.Write([]byte(message))
	return err
}
544749
func (b *Buffer) Write(buf []byte) (int, error) {
	// Account for total bytes written
	n := len(buf)
	b.written += int64(n)

	// If the buffer is larger than ours, then we only care
	// about the last size bytes anyways
	if int64(n) > b.size {
		buf = buf[int64(n)-b.size:]
	}

	// Copy in place
	remain := b.size - b.writeCursor
	copy(b.data[b.writeCursor:], buf)
	if int64(len(buf)) > remain {
		copy(b.data, buf[remain:])
	}

	// Update location of the cursor
	b.writeCursor = ((b.writeCursor + int64(len(buf))) % b.size)
	return n, nil
}
535667
func (p *Pool) Get() *ByteBuffer {
	v := p.pool.Get()
	if v != nil {
		return v.(*ByteBuffer)
	}
	return &ByteBuffer{
		B: make([]byte, 0, atomic.LoadUint64(&p.defaultSize)),
	}
}
184505
func (bp *BufferPool) Get() *bytes.Buffer {
	return bp.pool.Get().(*bytes.Buffer)
}
1310134
func (b *Buffer) Flush() (size int, err error) {
	for _, buf := range b.buffer {
		if size, err = b.write(buf); err != nil {
			return
		}
	}

	b.buffer = b.buffer[:0]
	return
}
128441
func (c *Conn) Send(to, msg string) error {
	return c.conn.Send(to, msg)
}
567787
func (c *Client) send(msgs []interface{}) error {
	if len(msgs) == 0 {
		return nil
	}

	batch := new(Batch)
	batch.Messages = msgs
	batch.MessageId = c.uid()
	batch.SentAt = timestamp(c.now())
	batch.Context = DefaultContext

	b, err := json.Marshal(batch)
	if err != nil {
		return fmt.Errorf("error marshalling msgs: %s", err)
	}

	for i := 0; i < 10; i++ {
		if err = c.upload(b); err == nil {
			return nil
		}
		Backo.Sleep(i)
	}

	return err
}
898486
func (w *WebsocketSession) Send(str string) error {
	if atomic.LoadInt32(&w.closed) == 1 {
		return ErrSessionClosed
	}

	w.mu.Lock()
	defer w.mu.Unlock()

	b, _ := json.Marshal([]string{str})
	return w.conn.WriteMessage(websocket.TextMessage, b)
}