Writes bytes to the socket, possible with a timeout.

 @param bytes [String] the data that should be written to the socket.
 @raise [Errno::ETIMEDOUT] if the timeout is exceeded.
 @return [Integer] the number of bytes written.
497148
def write(bytes)
      loop do
        written = 0
        begin
          # unlike plain tcp sockets, ssl sockets don't support IO.select
          # properly.
          # Instead, timeouts happen on a per write basis, and we have to
          # catch exceptions from write_nonblock, and gradually build up
          # our write buffer.
          written += @ssl_socket.write_nonblock(bytes)
        rescue Errno::EFAULT => error
          raise error
        rescue OpenSSL::SSL::SSLError, Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitWritable => error
          if error.is_a?(OpenSSL::SSL::SSLError) && error.message == 'write would block'
            if select_with_timeout(@ssl_socket, :write)
              retry
            else
              raise Errno::ETIMEDOUT
            end
          else
            raise error
          end
        end

        # Fast, common case.
        break if written == bytes.size

        # This takes advantage of the fact that most ruby implementations
        # have Copy-On-Write strings. Thusly why requesting a subrange
        # of data, we actually don't copy data because the new string
        # simply references a subrange of the original.
        bytes = bytes[written, bytes.size]
      end
    end
1289428
def write(self, len, buf):
        
        ret = libxml2mod.xmlOutputBufferWrite(self._o, len, buf)
        return ret
73982
def write(buffer)
      bytes_parsed = @parser.write(buffer)
      if bytes_parsed != buffer.size
        msg = "Parser error, #{bytes_parsed} of #{buffer.length} bytes parsed"
        @on_error.call(msg) unless @on_error.nil?
      end
    end
1230231
def copy_in_bytes bytes, len
      data_buffer = LibC.malloc len
      # writes the exact number of bytes, no null byte to terminate string
      data_buffer.write_string bytes, len

      # use libC to call free on the data buffer; earlier versions used an
      # FFI::Function here that called back into Ruby, but Rubinius won't 
      # support that and there are issues with the other runtimes too
      LibXS.xs_msg_init_data @pointer, data_buffer, len, LibC::Free, nil
    end
108000
def write_bytes(self, data):
        
        if not isinstance(data, six.binary_type):
            raise TypeError(
                'data must be %s, not %s' %
                (six.binary_type.__class__.__name__, data.__class__.__name__))
        with self.open(mode='wb') as f:
            return f.write(data)
907091
def write(self, data):
        
        for _ in range(64 - len(data)):
            data.append(0)
        #logging.debug("send: %s", data)
        self.device.write(bytearray([0]) + data)
        return
296949
def write(self, byte):
        
        if self.is_closed_flag:
            raise Exception("Unable to write - already closed!")
        self.written += len(byte)
        self.file.write(byte)
595242
def write(self, data, debug_info=None):
        
        self.num_write_bytes += len(data)
        if self.debug:
            if not debug_info:
                debug_info = str(len(data))
            sys.stderr.write("%s: WRITE %s:\n%s\n" % (
                self.__class__.__name__,
                debug_info,
                pyhsm.util.hexdump(data)
            ))
        write_sock(self.socket_file, CMD_WRITE, data)
        return read_sock(self.socket_file)
1098865
def write(self, data):
        '''
        
        '''
        if not hasattr(self, '_sock'):
            return None

        try:
            self._sock.sendall(data)

            if self.connection.debug > 1:
                self.connection.logger.debug(
                    'sent %d bytes to %s' % (len(data), self._host))

            return
        except EnvironmentError:
            # sockets raise this type of error, and since if sendall() fails
            # we're left in an indeterminate state, assume that any error we
            # catch means that the connection is dead. Note that this
            # assumption requires this to be a blocking socket; if we ever
            # support non-blocking in this class then this whole method has
            # to change a lot.
            self.connection.logger.exception(
                'error writing to %s' % (self._host))

        self.connection.transport_closed(
            msg='error writing to %s' % (self._host))
399282
def write (self, bytes, header=None):
        
        if header is None:
            header = PCapPacketHeader(orig_len=len(bytes))

        if self._stream is None:
            if self._threshold.nseconds is not None:
                # Round down to the nearest multiple of nseconds
                nseconds  = self._threshold.nseconds
                remainder = int( math.floor( header.ts % nseconds ) )
                delta     = datetime.timedelta(seconds=remainder)
                timestamp = header.timestamp - delta
            else:
                timestamp = header.timestamp

            self._filename  = timestamp.strftime(self._format)
            self._startTime = calendar.timegm(
                timestamp.replace(microsecond=0).timetuple() )

            if self._dryrun:
                self._stream        = True
                self._total.nbytes += len(PCapGlobalHeader())
            else:
                self._stream        = open(self._filename, 'w')
                self._total.nbytes += len(self._stream.header)

        if not self._dryrun:
            self._stream.write(bytes, header)

        self._total.nbytes   += len(bytes) + len(header)
        self._total.npackets += 1
        self._total.nseconds  = header.ts - self._startTime

        if self.rollover:
            self.close()

        return header.incl_len
1374524
public BinaryEncoder writeBytes(byte[] bytes) throws IOException {
    writeLong(bytes.length);
    output.write(bytes, 0, bytes.length);
    return this;
  }
797601
def send(self, s):
        '''
        '''
        s = self._coerce_send_string(s)
        self._log(s, 'send')

        b = self._encoder.encode(s, final=False)
        if PY3:
            return self.proc.stdin.write(b)
        else:
            # On Python 2, .write() returns None, so we return the length of
            # bytes written ourselves. This assumes they all got written.
            self.proc.stdin.write(b)
            return len(b)
475989
def write(self, data):
        

        try:
            ret = self._wrap_socket_library_call(
                lambda: SSL_write(self._ssl.value, data), ERR_WRITE_TIMEOUT)
        except openssl_error() as err:
            if err.ssl_error == SSL_ERROR_SYSCALL and err.result == -1:
                raise_ssl_error(ERR_PORT_UNREACHABLE, err)
            raise
        if ret:
            self._handshake_done = True
        return ret
396626
async def write(self, data, eof = False, buffering = True):
        
        if not self.outputstream:
            self.outputstream = Stream()
            self._startResponse()
        elif (not buffering or eof) and not self._sendHeaders:
            self._startResponse()
        if not isinstance(data, bytes):
            data = data.encode(self.encoding)
        await self.outputstream.write(data, self.connection, eof, False, buffering)
1133236
public static void writeBytes(byte[] bytes, long value, int offset, int numBytes) {
        int shift = 0;
        for(int i = offset + numBytes - 1; i >= offset; i--) {
            bytes[i] = (byte) (0xFF & (value >> shift));
            shift += 8;
        }
    }
733060
def _write(self, s):
        
        while s:
            n = self.sslobj.write(s)
            if not n:
                raise IOError('Socket closed')
            s = s[n:]
549434
def write(sock, payload):
    """"""
    try:
        length = sock.send(payload)
    except ssl.SSLError as e:
        return -1, (ssl.SSLError, e.strerror if strerror else e.message)
    except socket.herror as (_, msg):
        return -1, (socket.error, msg)
    except socket.gaierror as (_, msg):
        return -1, (socket.gaierror, msg)
    except socket.timeout:
        return -1, (socket.timeout, "timeout")
    except socket.error as (_, msg):
        return -1, (socket.error, msg)
    
    return length, None