// Write writes data to the connection.
190808
func (bufc *bufConn) Write(b []byte) (int, error) {
	return bufc.conn.Write(b)
}
82374
func (c *Conn) Write(buf []byte) (n int, err error) {

	c.writeMutex.Lock()
	defer c.writeMutex.Unlock()

	// Our protocol specifies that writing an empty buffer means "close"
	// the connection.  We don't want callers of `Write` to do this by
	// accident, we want them to call `Close()` explicitly. So short-circuit
	// the write operation here for empty buffers.
	if len(buf) == 0 {
		return 0, nil
	}

	return c.writeWithLock(buf)
}
152488
func (w *ByteWriter) Write(b []byte) (int, error) {
	p := w.grow(len(b))
	return copy(w.buf[p:], b), nil
}
1168097
func (c *Conn) Write(b []byte) (int, error) {
	if c.W == nil {
		// all writes to Discard succeed, so there's no need to wrap errors
		return ioutil.Discard.Write(b)
	}

	c.initClosing()

	// stop now if we're already closed
	select {
	case <-c.closing:
		return 0, c.writeErr(false, connClosed)
	default:
	}

	// stop now if we're already timed out
	c.wdeadmu.RLock()
	defer c.wdeadmu.RUnlock()
	if !c.wdead.IsZero() && c.wdead.Before(time.Now()) {
		return 0, c.writeErr(true, timedOut)
	}

	// start write
	writec := make(chan nerr, 1)
	go func() {
		c.wmu.Lock()
		n, err := c.W.Write(b)
		c.wmu.Unlock()
		writec <- nerr{n, err}
	}()

	// set up deadline timeout
	var timeout <-chan time.Time
	c.wdeadmu.RLock()
	timer := deadlineTimer(c.wdead) // c.wdeadmu read lock already held above
	if timer != nil {
		timeout = timer.C
		defer timer.Stop()
	}

	// wait for write success, timeout, or closing
	select {
	case <-c.closing:
		return 0, c.writeErr(false, connClosed)
	case <-timeout:
		return 0, c.writeErr(true, timedOut)
	case nerr := <-writec:
		if nerr.err != nil {
			return nerr.n, c.writeErr(false, nerr.err) // wrap the error
		}
		return nerr.n, nil
	}
}
1131802
func (c *boltConn) Write(b []byte) (n int, err error) {
	if err := c.conn.SetWriteDeadline(time.Now().Add(c.timeout)); err != nil {
		c.connErr = errors.Wrap(err, "An error occurred setting write deadline")
		return 0, driver.ErrBadConn
	}

	n, err = c.conn.Write(b)

	if log.GetLevel() >= log.TraceLevel {
		log.Tracef("Wrote %d of %d bytes to stream:\n\n%s\n", len(b), n, sprintByteHex(b[:n]))
	}

	if err != nil {
		c.connErr = errors.Wrap(err, "An error occurred writing to stream")
		err = driver.ErrBadConn
	}
	return n, err
}
1219498
func (c *Client) Write(b []byte) (int, error) {
	return c.serializer.Write(b)
}
633604
func (s *Socket) write(rawData string) {
	// Write to the stream and check if the buffer is full.
	select {
	case <-s.isClosedChan:
		// Just return because the socket is closed.
		return
	case s.writeChan <- rawData:
	default:
		// The buffer if full. No data was send.
		// Send a ping. If no pong is received within
		// the timeout, the socket is closed.
		s.sendPing()

		// Now write the current data to the socket.
		// This will block if the buffer is still full.
		s.writeChan <- rawData
	}
}
418023
func (b *Bytes) Write(data []byte) (n int, err error) {
	b.bytes, n, err = b.write(data)
	return n, err
}
142310
func (conn *Conn) write(line string) error {
	if !conn.cfg.Flood {
		if t := conn.rateLimit(len(line)); t != 0 {
			// sleep for the current line's time value before sending it
			logging.Info("irc.rateLimit(): Flood! Sleeping for %.2f secs.",
				t.Seconds())
			<-time.After(t)
		}
	}

	if _, err := conn.io.WriteString(line + "\r\n"); err != nil {
		return err
	}
	if err := conn.io.Flush(); err != nil {
		return err
	}
	if strings.HasPrefix(line, "PASS") {
		line = "PASS **************"
	}
	logging.Debug("-> %s", line)
	return nil
}
35875
func (tcpConn *TCPConn) Write(b []byte) {
	tcpConn.Lock()
	defer tcpConn.Unlock()
	if tcpConn.closeFlag || b == nil {
		return
	}

	tcpConn.doWrite(b)
}
1044203
func (c *meteredConn) Write(b []byte) (n int, err error) {
	n, err = c.Conn.Write(b)
	egressTrafficMeter.Mark(int64(n))
	c.lock.RLock()
	if c.trafficMetered {
		c.egressMeter.Mark(int64(n))
	}
	c.lock.RUnlock()
	return n, err
}
282680
func (p *port) Write(b []byte) (n int, err error) {
	n, err = syscall.Write(p.fd, b)
	return
}
331243
func (conn *Connection) write(mode int, payload []byte) error {
	conn.socket.SetWriteDeadline(time.Now().Add(writeWait))
	return conn.socket.WriteMessage(mode, payload)
}
262117
func (conn *I2CConnection) Write(rs bool, data byte) error {
	var instructionHigh byte = 0x00
	instructionHigh |= ((data >> 4) & 0x01) << conn.PinMap.D4
	instructionHigh |= ((data >> 5) & 0x01) << conn.PinMap.D5
	instructionHigh |= ((data >> 6) & 0x01) << conn.PinMap.D6
	instructionHigh |= ((data >> 7) & 0x01) << conn.PinMap.D7

	var instructionLow byte = 0x00
	instructionLow |= (data & 0x01) << conn.PinMap.D4
	instructionLow |= ((data >> 1) & 0x01) << conn.PinMap.D5
	instructionLow |= ((data >> 2) & 0x01) << conn.PinMap.D6
	instructionLow |= ((data >> 3) & 0x01) << conn.PinMap.D7

	instructions := []byte{instructionHigh, instructionLow}
	for _, ins := range instructions {
		if rs {
			ins |= 0x01 << conn.PinMap.RS
		}
		if conn.Backlight == bool(conn.PinMap.BLPolarity) {
			ins |= 0x01 << conn.PinMap.Backlight
		}
		glog.V(3).Infof("hd44780: writing to I2C: %#x", ins)
		err := conn.pulseEnable(ins)
		if err != nil {
			return err
		}
	}
	time.Sleep(writeDelay)
	return nil
}
994935
func (w *udpWriter) Write(data []byte) (int, error) {
	return w.conn.Write(data)
}
135456
func (c *connection) Write(websocketMessageType int, data []byte) error {
	// for any-case the app tries to write from different goroutines,
	// we must protect them because they're reporting that as bug...
	c.writerMu.Lock()
	if writeTimeout := c.server.config.WriteTimeout; writeTimeout > 0 {
		// set the write deadline based on the configuration
		c.underline.SetWriteDeadline(time.Now().Add(writeTimeout))
	}

	// .WriteMessage same as NextWriter and close (flush)
	err := c.underline.WriteMessage(websocketMessageType, data)
	c.writerMu.Unlock()
	if err != nil {
		// if failed then the connection is off, fire the disconnect
		c.Disconnect()
	}
	return err
}
978856
func (c *Conn) Write(b []byte) (int, error) {
	if !c.ok() {
		return 0, syscall.EINVAL
	}
	if !c.isOpen() {
		return 0, &net.OpError{
			Op:   "write",
			Net:  c.LocalAddr().Network(),
			Addr: c.LocalAddr(),
			Err:  errClosing,
		}
	}
	c.deadlineMutex.RLock()
	d := timeToDeadline(c.wdeadline)
	c.deadlineMutex.RUnlock()
	return c.writebuf.WriteTimeout(b, d)
}