Move runAfterDelay/tryRunAfterDelay into TimeoutManager
[folly.git] / folly / io / RecordIO.cpp
index 1dc245a11503c3ee100b48b5b1e4beaffe86290f..f279ae47e79863d17120f6259f6a0a78db755000 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-#include "folly/io/RecordIO.h"
+#include <folly/io/RecordIO.h>
 
 #include <sys/types.h>
-#include <unistd.h>
 
-#include "folly/Exception.h"
-#include "folly/FileUtil.h"
-#include "folly/Memory.h"
-#include "folly/Portability.h"
-#include "folly/ScopeGuard.h"
-#include "folly/String.h"
+#include <folly/Exception.h>
+#include <folly/FileUtil.h>
+#include <folly/Memory.h>
+#include <folly/Portability.h>
+#include <folly/ScopeGuard.h>
+#include <folly/String.h>
+#include <folly/portability/Unistd.h>
 
 namespace folly {
 
@@ -78,7 +78,8 @@ RecordIOReader::Iterator::Iterator(ByteRange range, uint32_t fileId, off_t pos)
   : range_(range),
     fileId_(fileId),
     recordAndPos_(ByteRange(), 0) {
-  if (pos >= range_.size()) {
+  if (size_t(pos) >= range_.size()) {
+    // Note that this branch can execute if pos is negative as well.
     recordAndPos_.second = off_t(-1);
     range_.clear();
   } else {
@@ -173,7 +174,7 @@ size_t prependHeader(std::unique_ptr<IOBuf>& buf, uint32_t fileId) {
 
 RecordInfo validateRecord(ByteRange range, uint32_t fileId) {
   if (range.size() <= headerSize()) {  // records may not be empty
-    return {0};
+    return {0, {}};
   }
   const Header* header = reinterpret_cast<const Header*>(range.begin());
   range.advance(sizeof(Header));
@@ -183,14 +184,14 @@ RecordInfo validateRecord(ByteRange range, uint32_t fileId) {
       header->flags != 0 ||
       (fileId != 0 && header->fileId != fileId) ||
       header->dataLength > range.size()) {
-    return {0};
+    return {0, {}};
   }
   if (headerHash(*header) != header->headerHash) {
-    return {0};
+    return {0, {}};
   }
   range.reset(range.begin(), header->dataLength);
   if (dataHash(range) != header->dataHash) {
-    return {0};
+    return {0, {}};
   }
   return {header->fileId, range};
 }
@@ -225,7 +226,7 @@ RecordInfo findRecord(ByteRange searchRange,
     start += sizeof(magic);
   }
 
-  return {0};
+  return {0, {}};
 }
 
 }  // namespace