Switch uses of networking headers to <folly/portability/Sockets.h>
[folly.git] / folly / io / ShutdownSocketSet.cpp
index 52125c258e4cc2834975f8a66ed8415482523207..9114c8f088b85fee77f474d3b48236a8e2f58407 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.
@@ -16,7 +16,6 @@
 
 #include <folly/io/ShutdownSocketSet.h>
 
-#include <sys/socket.h>
 #include <sys/types.h>
 
 #include <chrono>
@@ -26,6 +25,7 @@
 
 #include <folly/FileUtil.h>
 #include <folly/Malloc.h>
+#include <folly/portability/Sockets.h>
 
 namespace folly {
 
@@ -39,7 +39,7 @@ ShutdownSocketSet::ShutdownSocketSet(size_t maxFd)
 void ShutdownSocketSet::add(int fd) {
   // Silently ignore any fds >= maxFd_, very unlikely
   DCHECK_GE(fd, 0);
-  if (fd >= maxFd_) {
+  if (size_t(fd) >= maxFd_) {
     return;
   }
 
@@ -53,7 +53,7 @@ void ShutdownSocketSet::add(int fd) {
 
 void ShutdownSocketSet::remove(int fd) {
   DCHECK_GE(fd, 0);
-  if (fd >= maxFd_) {
+  if (size_t(fd) >= maxFd_) {
     return;
   }
 
@@ -81,7 +81,7 @@ retry:
 
 int ShutdownSocketSet::close(int fd) {
   DCHECK_GE(fd, 0);
-  if (fd >= maxFd_) {
+  if (size_t(fd) >= maxFd_) {
     return folly::closeNoInt(fd);
   }
 
@@ -113,7 +113,7 @@ retry:
 
 void ShutdownSocketSet::shutdown(int fd, bool abortive) {
   DCHECK_GE(fd, 0);
-  if (fd >= maxFd_) {
+  if (fd >= 0 && size_t(fd) >= maxFd_) {
     doShutdown(fd, abortive);
     return;
   }