Beispiel #1
0
bool TunIntf::sendPacketToHost(std::unique_ptr<RxPacket> pkt) {
  CHECK(fd_ != -1);
  const int l2Len = EthHdr::SIZE;
  auto buf = pkt->buf();
  if (buf->length() <= l2Len) {
    LOG(ERROR) << "Received a too small packet with length " << buf->length();
    return false;
  }
  // skip L2 header
  buf->trimStart(l2Len);
  int ret = 0;
  do {
    ret = write(fd_, buf->data(), buf->length());
  } while (ret == -1 && errno == EINTR);
  if (ret < 0) {
    sysLogError(ret, "Failed to send packet to the host from router ", rid_);
    return false;
  } else if (ret < buf->length()) {
    LOG(ERROR) << "Failed to send full packet to host from router " << rid_
               << ret << " bytes sent instead of " << buf->length();
  } else {
    VLOG(4) << "Send packet (" << ret << " bytes) to host from router "
            << rid_;
  }
  return true;
}
Beispiel #2
0
void CompressionVarintTest::runSimpleTest(const DataHolder& dh) {
  auto original = IOBuf::wrapBuffer(dh.data(uncompressedLength_));
  auto compressed = codec_->compress(original.get());
  auto breakPoint =
      1UL +
      Random::rand64(std::max(9UL, oneBasedMsbPos(uncompressedLength_)) / 9UL);
  auto tinyBuf = IOBuf::copyBuffer(compressed->data(),
                                   std::min(compressed->length(), breakPoint));
  compressed->trimStart(breakPoint);
  tinyBuf->prependChain(std::move(compressed));
  compressed = std::move(tinyBuf);

  auto uncompressed = codec_->uncompress(compressed.get());

  EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength());
  EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get()));
}
Beispiel #3
0
void removeBlanks(char s[]) {
    trimEnd(s);
    bool inBlank = false;
    for (int i = 0; s[i] != '\0'; ++i) {
        if (s[i] == '\t' || s[i] == ' ') {
            if (inBlank) {
                for (int j = i; s[j] != '\0'; ++j) {
                    s[j] = s[j+1];
                }
                --i;
            } else {
                s[i] = ' ';
                inBlank = true;
            }
        } else {
            inBlank = false;
        }
    }
    trimStart(s);
}
Beispiel #4
0
/*
 * Removes blanks (spaces, tabs, CR, LF) at the both ends of the given string
 * The string is modified and returned
 */
char* trim(char* str) {
	return trimEnd(trimStart(str));
}
void trim(char* command)
{
	trimEnd(command);
	trimStart(command);
}
Beispiel #6
0
	inline std::string& trim(std::string &string, const char* chars = " \t")
	{
		return trimStart(trimEnd(string, chars), chars);
	}