class EventMachine::Synchrony::TCPSocket

def write_data(data = nil)

def write_data(data = nil)
  @out_buff += data if data
  loop do
    if @out_buff.empty?
      @out_req.succeed true if @out_req
      return true
    end
    if self.get_outbound_data_size > EventMachine::FileStreamer::BackpressureLevel
      # write(X) on an open socket, where the remote end is not reading, > than some buffer size, blocks
      # send(X,0) on an open socket, where the remote end is not reading, > than some buffer size, blocks
      # where that buffer size is EventMachine::FileStreamer::BackpressureLevel, returning false will
      # cause write/send to block
      EventMachine::next_tick { write_data }
      return false
    else
      # write(X) on an open socket, where the remote end is not reading, <= than some buffer size, sends and returns
      # send(X,0) on an open socket, where the remote end is not reading, <= than some buffer size, sends returns
      len = [@out_buff.bytesize, EventMachine::FileStreamer::ChunkSize].min
      self.send_data @out_buff.slice!( 0, len )
    end
  end
end