APIs to determine which end of the socket has closed it
[folly.git] / folly / io / TypedIOBuf.h
index 26eccccca8e3ec2ebc97828ebb4118e97607be91..9182fe43a9d9d120fef3a4b86e512a4a8bbd61cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@
 #include <iterator>
 #include <type_traits>
 
-#include "folly/Malloc.h"
-#include "folly/io/IOBuf.h"
+#include <folly/Malloc.h>
+#include <folly/io/IOBuf.h>
 
 namespace folly {
 
@@ -153,6 +153,11 @@ class TypedIOBuf {
     return data()[idx];
   }
 
+  T& operator[](ssize_t idx) {
+    assert(idx >= 0 && idx < length());
+    return writableData()[idx];
+  }
+
   /**
    * Append one element.
    */
@@ -168,7 +173,7 @@ class TypedIOBuf {
   void push(IT begin, IT end) {
     uint32_t n = std::distance(begin, end);
     if (usingJEMalloc()) {
-      // Rely on rallocm() and avoid exponential growth to limit
+      // Rely on xallocx() and avoid exponential growth to limit
       // amount of memory wasted.
       reserve(headroom(), n);
     } else if (tailroom() < n) {
@@ -211,4 +216,3 @@ class TypedIOBuf {
 }  // namespace folly
 
 #endif /* FOLLY_IO_TYPEDIOBUF_H_ */
-