Add writable() to AsyncTransport
[folly.git] / folly / io / async / AsyncSocket.cpp
index dc550a310e61ca9f8fdecaa7b69cdf72b61f0a6d..60848917f80a5b9d9bc51320fb050a4d3d82cde2 100644 (file)
@@ -1189,6 +1189,18 @@ bool AsyncSocket::readable() const {
   return rc == 1;
 }
 
+bool AsyncSocket::writable() const {
+  if (fd_ == -1) {
+    return false;
+  }
+  struct pollfd fds[1];
+  fds[0].fd = fd_;
+  fds[0].events = POLLOUT;
+  fds[0].revents = 0;
+  int rc = poll(fds, 1, 0);
+  return rc == 1;
+}
+
 bool AsyncSocket::isPending() const {
   return ioHandler_.isPending();
 }