示例#1
0
	void print(const x0::BufferRef& v, const char *msg = 0)
	{
		if (msg && *msg)
			printf("buffer.view(%s): '%s'\n", msg, v.str().c_str());
		else
			printf("buffer.view: '%s'\n", v.str().c_str());

		printf("  size=%ld\n", v.size());
	}
示例#2
0
文件: io_test.cpp 项目: tempbottle/x0
  void print(const x0::BufferRef& v, const char* msg = 0) {
    char prefix[64];
    if (msg && *msg)
      snprintf(prefix, sizeof(prefix), "\nbuffer.view(%s)", msg);
    else
      snprintf(prefix, sizeof(prefix), "\nbuffer.view");

    if (v)
      printf("\n%s: '%s' (size=%ld)\n", prefix, v.str().c_str(), v.size());
    else
      printf("\n%s: NULL\n", prefix);
  }
示例#3
0
	void onContent(const x0::BufferRef& chunk)
	{
		if (chunk.empty()) {
			if (created_)
				request_->status = x0::HttpStatus::Created;
			else
				request_->status = x0::HttpStatus::NoContent;

			request_->finish();
			::close(fd_);

			delete this;
		} else {
			::write(fd_, chunk.data(), chunk.size());
			// check return code and possibly early abort request with error code indicating diagnostics
		}
	}
示例#4
0
x0::Buffer ExampleFilter::process(const x0::BufferRef& input)
{
	x0::Buffer result;

	switch (mode_)
	{
		case ExampleFilter::LOWER:
			for (auto i = input.cbegin(), e = input.cend(); i != e; ++i)
				result.push_back(static_cast<char>(std::tolower(*i)));
			break;
		case ExampleFilter::UPPER:
			for (auto i = input.cbegin(), e = input.cend(); i != e; ++i)
				result.push_back(static_cast<char>(std::toupper(*i)));
			break;
		case ExampleFilter::IDENTITY:
		default:
			result.push_back(input);
	}

	return result;
}
示例#5
0
void FastCgiHealthMonitor::onStdErr(const x0::BufferRef& chunk)
{
	worker_.log(x0::Severity::error, "fastcgi: Health check error. %s", chunk.chomp().str().c_str());
}
示例#6
0
void FastCgiHealthMonitor::onStdOut(const x0::BufferRef& chunk)
{
	TRACE("onStdOut: chunk.size=%ld", chunk.size());
	process(chunk);
}
示例#7
0
	// Handler, invoked on request content body chunks,
	// which we want to "echo" back to the client.
	//
	// NOTE, this can be invoked multiple times, depending on the input.
	void onContent(const x0::BufferRef& chunk)
	{
		TRACE("onContent('%s')", chunk.str().c_str());
		request_->write<x0::BufferRefSource>(std::move(chunk));
		request_->writeCallback<EchoHandler, &EchoHandler::contentWritten>(this);
	}