コード例 #1
0
    std::pair<size_t, bool> StreamWriter<StreamType>::append_key(const std::string& key)
    {
        std::size_t key_size = key.size();
        append_size(key_size);
        write(reinterpret_cast<const byte*>(key.c_str()), key_size);

        return std::make_pair(1 + key_size, true);
    }
コード例 #2
0
 std::pair<size_t, bool> StreamWriter<StreamType>::append_binary(const Value::BinaryType& bin)
 {
     write(Marker::Binary);
     auto rtn = append_size(bin.size());
     write(bin.data(), bin.size());
     rtn.first += bin.size() + 1;
     return rtn;
 }
コード例 #3
0
ファイル: encoder.hpp プロジェクト: TigerZhang/resp
 /**
  * @param cmd Redis command.
  * @return At least one buffer, may multi, if multi, user could use scatter-gather io to send them.
  */
 std::vector<buffer_t> encode(buffer_t const& cmd)
 {
   std::vector<buffer_t> buffers;
   buffers.reserve(1);
   append_size(buffers, '*', 1);
   append(buffers, cmd);
   return buffers;
 }
コード例 #4
0
 std::pair<size_t, bool> StreamWriter<StreamType>::append_string(const std::string& str)
 {
     const std::size_t size = str.size();
     write(Marker::String);
     auto rtn = append_size(size);
     write(reinterpret_cast<const byte*>(str.data()), size);
     rtn.first += size + 1;
     return rtn;
 }
コード例 #5
0
ファイル: encoder.hpp プロジェクト: TigerZhang/resp
 static void encode(std::vector<buffer_t>& buffers, buffer_t const& cmd, std::vector<buffer_t> const& args)
 {
   append_size(buffers, '*', args.size() + 1);
   append(buffers, cmd);
   for (size_t i=0; i<args.size(); ++i)
   {
     append(buffers, args[i]);
   }
 }
コード例 #6
0
ファイル: simple_net_buffer.cpp プロジェクト: mmanley/Antares
static status_t
append_data(net_buffer *buffer, const void *data, size_t size)
{
	size_t used = buffer->size;

	status_t status = append_size(buffer, size, NULL);
	if (status < B_OK)
		return status;

	write_data(buffer, used, data, size);

	return B_OK;
}
コード例 #7
0
ファイル: encoder.hpp プロジェクト: TigerZhang/resp
 /// Encode redis command + arg(s).
 std::vector<buffer_t> encode(
   buffer_t const& cmd,
   buffer_t const& arg1,
   buffer_t const& arg2
   )
 {
   std::vector<buffer_t> buffers;
   buffers.reserve(3);
   append_size(buffers, '*', 3);
   append(buffers, cmd);
   append(buffers, arg1);
   append(buffers, arg2);
   return buffers;
 }
コード例 #8
0
ファイル: encoder.hpp プロジェクト: TigerZhang/resp
 static void append(std::vector<buffer_t>& buffers, buffer_t const& arg)
 {
   append_size(buffers, '$', arg.size());
   if (arg.size() > RESP_LARGE_BUFFER_SIZE)
   {
     buffers.push_back(arg);
     buffers.push_back("\r\n");
   }
   else
   {
     buffer_t& buffer = buffers.back();
     buffer.append(arg);
     buffer.append("\r\n");
   }
 }
コード例 #9
0
ファイル: template.c プロジェクト: gtk-gnutella/gwc
struct mem_buf *
template_get_chunk(struct template_chunk *chunk, const gwc_full_stats_t *stats)
{
  char buf[1024], *p = buf;
  size_t avail = sizeof buf;

  switch (chunk->type) {
  case chunk_http_response:
  case chunk_http_header:
  case chunk_data:
    /* Must be handled elsewhere */
    p = NULL;
    RUNTIME_ASSERT(0);
    break;

  case crab_stats_total_updates:
    p = append_uint64(buf, &avail, stats->total.updates);
    break;
  case crab_stats_total_updates_ip:
    p = append_uint64(buf, &avail, stats->total.ip_updates);
    break;
  case crab_stats_total_updates_url:
    p = append_uint64(buf, &avail, stats->total.url_updates);
    break;
  case crab_stats_total_requests:
    p = append_uint64(buf, &avail, stats->total.requests);
    break;
  case crab_stats_total_requests_base:
    p = append_uint64(buf, &avail, stats->total.base_requests);
    break;
  case crab_stats_total_requests_data:
    p = append_uint64(buf, &avail, stats->total.data_requests);
    break;
  case crab_stats_total_requests_get:
    p = append_uint64(buf, &avail, stats->total.get_requests);
    break;
  case crab_stats_total_requests_hostfile:
    p = append_uint64(buf, &avail, stats->total.hostfile_requests);
    break;
  case crab_stats_total_requests_urlfile:
    p = append_uint64(buf, &avail, stats->total.urlfile_requests);
    break;
  case crab_stats_total_requests_ping:
    p = append_uint64(buf, &avail, stats->total.ping_requests);
    break;
  case crab_stats_total_requests_statfile:
    p = append_uint64(buf, &avail, stats->total.statfile_requests);
    break;
  case crab_stats_total_accepts:
    p = append_uint64(buf, &avail, stats->total.accepts);
    break;
  case crab_stats_total_blocked:
    p = append_uint64(buf, &avail, stats->total.blocked);
    break;
  case crab_stats_total_errors:
    p = append_uint64(buf, &avail, stats->total.errors);
    break;
  case crab_stats_total_http_400s:
    p = append_uint64(buf, &avail, stats->total.http_400s);
    break;
  case crab_stats_total_http_404s:
    p = append_uint64(buf, &avail, stats->total.http_404s);
    break;
  case crab_stats_total_too_early:
    p = append_uint64(buf, &avail, stats->total.too_early);
    break;
  case crab_stats_total_rx:
    p = append_size(buf, &avail, stats->total.rx);
    break;
  case crab_stats_total_tx:
    p = append_size(buf, &avail, stats->total.tx);
    break;

  case crab_stats_hourly_updates:
    p = append_uint64(buf, &avail, stats->hourly.updates);
    break;
  case crab_stats_hourly_updates_ip:
    p = append_uint64(buf, &avail, stats->hourly.ip_updates);
    break;
  case crab_stats_hourly_updates_url:
    p = append_uint64(buf, &avail, stats->hourly.url_updates);
    break;
  case crab_stats_hourly_requests:
    p = append_uint64(buf, &avail, stats->hourly.requests);
    break;
  case crab_stats_hourly_requests_base:
    p = append_uint64(buf, &avail, stats->hourly.base_requests);
    break;
  case crab_stats_hourly_requests_data:
    p = append_uint64(buf, &avail, stats->hourly.data_requests);
    break;
  case crab_stats_hourly_requests_get:
    p = append_uint64(buf, &avail, stats->hourly.get_requests);
    break;
  case crab_stats_hourly_requests_hostfile:
    p = append_uint64(buf, &avail, stats->hourly.hostfile_requests);
    break;
  case crab_stats_hourly_requests_urlfile:
    p = append_uint64(buf, &avail, stats->hourly.urlfile_requests);
    break;
  case crab_stats_hourly_requests_ping:
    p = append_uint64(buf, &avail, stats->hourly.ping_requests);
    break;
  case crab_stats_hourly_requests_statfile:
    p = append_uint64(buf, &avail, stats->hourly.statfile_requests);
    break;
  case crab_stats_hourly_accepts:
    p = append_uint64(buf, &avail, stats->hourly.accepts);
    break;
  case crab_stats_hourly_blocked:
    p = append_uint64(buf, &avail, stats->hourly.blocked);
    break;
  case crab_stats_hourly_errors:
    p = append_uint64(buf, &avail, stats->hourly.errors);
    break;
  case crab_stats_hourly_http_400s:
    p = append_uint64(buf, &avail, stats->hourly.http_400s);
    break;
  case crab_stats_hourly_http_404s:
    p = append_uint64(buf, &avail, stats->hourly.http_404s);
    break;
  case crab_stats_hourly_too_early:
    p = append_uint64(buf, &avail, stats->hourly.too_early);
    break;
  case crab_stats_hourly_rx:
    p = append_size(buf, &avail, stats->hourly.rx);
    break;
  case crab_stats_hourly_tx:
    p = append_size(buf, &avail, stats->hourly.tx);
    break;

  case crab_startup_time:
    p = append_date(buf, &avail, stats->start_time.tv_sec);
    break;
    
  case crab_user_agent:
    p = append_string(buf, &avail, GWC_USER_AGENT);
    break;

  case crab_uri:
    p = append_string(buf, &avail, OPTION(gwc_uri));
    break;

  case crab_url:
    p = append_string(buf, &avail, OPTION(gwc_url));
    break;

  case crab_network_id:
    p = append_string(buf, &avail,
          OPTION(network_id) ? OPTION(network_id) : "gnutella");
    break;
    
  case crab_contact_address:
    p = append_string(buf, &avail,
          OPTION(contact_address) ? OPTION(contact_address) : "");
    break;

#if defined(HAVE_GETRUSAGE)
#define RU_TIME(x) stats->ru.x
#else
#define RU_TIME(x) 0
#endif /* HAVE_GETRUSAGE */
 
  case crab_rusage_utime:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_utime.tv_sec) * 1000000 +
        RU_TIME(ru_utime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
  case crab_rusage_stime:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_stime.tv_sec) * 1000000 +
        RU_TIME(ru_stime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
    
   case crab_rusage_utime_percent:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_utime.tv_sec) * 1000000 +
        RU_TIME(ru_utime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
  case crab_rusage_stime_percent:
    {
      uint64_t v;

      v = (uint64_t) RU_TIME(ru_stime.tv_sec) * 1000000 +
        RU_TIME(ru_stime.tv_usec);
      p = append_uint64(buf, &avail, v);
    }
    break;
    
#if defined(HAVE_GETRUSAGE) && defined(HAVE_BSD_STRUCT_RUSAGE)
#define RU(x) stats->ru.x
#else
#define RU(x) 0
#endif /* HAVE_GETRUSAGE && HAVE_BSD_STRUCT_RUSAGE */
    
  case crab_rusage_maxrss:
    p = append_uint64(buf, &avail, RU(ru_maxrss));
    break;
  case crab_rusage_ixrss:
    p = append_uint64(buf, &avail, RU(ru_ixrss));
    break;
  case crab_rusage_idrss:
    p = append_uint64(buf, &avail, RU(ru_idrss));
    break;
  case crab_rusage_isrss:
    p = append_uint64(buf, &avail, RU(ru_isrss));
    break;
  case crab_rusage_minflt:
    p = append_uint64(buf, &avail, RU(ru_minflt));
    break;
  case crab_rusage_majflt:
    p = append_uint64(buf, &avail, RU(ru_majflt));
    break;
  case crab_rusage_nswap:
    p = append_uint64(buf, &avail, RU(ru_nswap));
    break;
  case crab_rusage_inblock:
    p = append_uint64(buf, &avail, RU(ru_inblock));
    break;
  case crab_rusage_oublock:
    p = append_uint64(buf, &avail, RU(ru_oublock));
    break;
  case crab_rusage_msgsnd:
    p = append_uint64(buf, &avail, RU(ru_msgsnd));
    break;
  case crab_rusage_msgrcv:
    p = append_uint64(buf, &avail, RU(ru_msgrcv));
    break;
  case crab_rusage_nsignals:
    p = append_uint64(buf, &avail, RU(ru_nsignals));
    break;
  case crab_rusage_nvcsw:
    p = append_uint64(buf, &avail, RU(ru_nvcsw));
    break;
  case crab_rusage_nivcsw:
    p = append_uint64(buf, &avail, RU(ru_nivcsw));
    break;
    
#undef RU

  default:
    CRIT("Unknown chunk type (%u)", (unsigned) chunk->type);
    p = NULL;
    RUNTIME_ASSERT(0);
  }

  if (p && p != buf) {
    return mem_buf_new_copy(buf, p - buf);
  }
  return NULL;
}