]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msgr: fail on sd < 0
authorSage Weil <sage@newdream.net>
Wed, 7 Apr 2010 21:12:43 +0000 (14:12 -0700)
committerSage Weil <sage@newdream.net>
Wed, 7 Apr 2010 21:23:44 +0000 (14:23 -0700)
I saw a case where poll(2) was blocking despite being passed an fd of -1.
Since that's clearly invalid, we can fail tcp_{read,write} before that
point.

Weird.

src/msg/tcp.cc

index f5b3b210f9697a90fa7772b44908acb5795a6fb4..3be1f91e1ce7c80d0617161abecf41da21a69528 100644 (file)
@@ -9,6 +9,8 @@
  */
 
 int tcp_read(int sd, char *buf, int len) {
+  if (sd < 0)
+    return -1;
   struct pollfd pfd;
   pfd.fd = sd;
   pfd.events = POLLIN | POLLHUP | POLLRDHUP | POLLNVAL | POLLERR;
@@ -39,6 +41,8 @@ int tcp_read(int sd, char *buf, int len) {
 }
 
 int tcp_write(int sd, const char *buf, int len) {
+  if (sd < 0)
+    return -1;
   struct pollfd pfd;
   pfd.fd = sd;
   pfd.events = POLLOUT | POLLHUP | POLLRDHUP | POLLNVAL | POLLERR;