]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msgr: clean up Pipe::do_sendmsg.
authorGreg Farnum <gregory.farnum@dreamhost.com>
Wed, 28 Mar 2012 22:06:32 +0000 (15:06 -0700)
committerGreg Farnum <gregory.farnum@dreamhost.com>
Tue, 3 Apr 2012 20:22:38 +0000 (13:22 -0700)
Document it as with the tcp stuff, remove an if(0)'d debugging block,
and remove the useless "sd" parameter since it's always the same as
the Pipe's sd member.

Signed-off-by: Greg Farnum <gregory.farnum@dreamhost.com>
src/msg/SimpleMessenger.cc
src/msg/SimpleMessenger.h

index 3fef06d86c53e82139b9c601f7a06c9333fd08b1..fd930318e7be95585f9aa84773b8b5e0389467a4 100644 (file)
@@ -1093,7 +1093,7 @@ int SimpleMessenger::Pipe::connect()
   msg.msg_iov = msgvec;
   msg.msg_iovlen = 1;
   msglen = msgvec[0].iov_len;
-  if (do_sendmsg(sd, &msg, msglen)) {
+  if (do_sendmsg(&msg, msglen)) {
     ldout(msgr->cct,2) << "connect couldn't write my banner, " << strerror_r(errno, buf, sizeof(buf)) << dendl;
     goto fail;
   }
@@ -1141,7 +1141,7 @@ int SimpleMessenger::Pipe::connect()
   msg.msg_iov = msgvec;
   msg.msg_iovlen = 1;
   msglen = msgvec[0].iov_len;
-  if (do_sendmsg(sd, &msg, msglen)) {
+  if (do_sendmsg(&msg, msglen)) {
     ldout(msgr->cct,2) << "connect couldn't write my addr, " << strerror_r(errno, buf, sizeof(buf)) << dendl;
     goto fail;
   }
@@ -1182,7 +1182,7 @@ int SimpleMessenger::Pipe::connect()
 
     ldout(msgr->cct,10) << "connect sending gseq=" << gseq << " cseq=" << cseq
             << " proto=" << connect.protocol_version << dendl;
-    if (do_sendmsg(sd, &msg, msglen)) {
+    if (do_sendmsg(&msg, msglen)) {
       ldout(msgr->cct,2) << "connect couldn't write gseq, cseq, " << strerror_r(errno, buf, sizeof(buf)) << dendl;
       goto fail;
     }
@@ -2054,7 +2054,7 @@ int SimpleMessenger::Pipe::read_message(Message **pm)
   return ret;
 }
 
-int SimpleMessenger::Pipe::do_sendmsg(int sd, struct msghdr *msg, int len, bool more)
+int SimpleMessenger::Pipe::do_sendmsg(struct msghdr *msg, int len, bool more)
 {
   char buf[80];
 
@@ -2079,40 +2079,6 @@ int SimpleMessenger::Pipe::do_sendmsg(int sd, struct msghdr *msg, int len, bool
       return -1; // close enough
     }
 
-    if (0) {
-      // hex dump
-      struct iovec *v = msg->msg_iov;
-      size_t left = r;
-      size_t vpos = 0;
-      ldout(msgr->cct,0) << "do_sendmsg wrote " << r << " bytes, hexdump:\n";
-      int pos = 0;
-      int col = 0;
-      char buf[20];
-      while (left > 0) {
-       if (col == 0) {
-         snprintf(buf, sizeof(buf), "%05x : ", pos);
-         *_dout << buf;
-       }
-       snprintf(buf, sizeof(buf), " %02x", ((unsigned char*)v->iov_base)[vpos]);
-       *_dout << buf;
-       left--;
-       if (!left)
-         break;
-       vpos++;
-       pos++;
-       if (vpos == v->iov_len) {
-         v++;
-         vpos = 0;
-       }         
-       col++;
-       if (col == 16) {
-         *_dout << "\n";
-         col = 0;
-       }
-      }
-      *_dout << dendl;
-    }
-
     len -= r;
     if (len == 0) break;
     
@@ -2156,7 +2122,7 @@ int SimpleMessenger::Pipe::write_ack(uint64_t seq)
   msg.msg_iov = msgvec;
   msg.msg_iovlen = 2;
   
-  if (do_sendmsg(sd, &msg, 1 + sizeof(s), true) < 0) 
+  if (do_sendmsg(&msg, 1 + sizeof(s), true) < 0)
     return -1; 
   return 0;
 }
@@ -2175,7 +2141,7 @@ int SimpleMessenger::Pipe::write_keepalive()
   msg.msg_iov = msgvec;
   msg.msg_iovlen = 1;
   
-  if (do_sendmsg(sd, &msg, 1) < 0) 
+  if (do_sendmsg(&msg, 1) < 0)
     return -1; 
   return 0;
 }
@@ -2255,7 +2221,7 @@ int SimpleMessenger::Pipe::write_message(Message *m)
             << dendl;
     
     if (msg.msg_iovlen >= IOV_MAX-2) {
-      if (do_sendmsg(sd, &msg, msglen, true)) 
+      if (do_sendmsg(&msg, msglen, true))
        goto fail;
       
       // and restart the iov
@@ -2289,7 +2255,7 @@ int SimpleMessenger::Pipe::write_message(Message *m)
   msg.msg_iovlen++;
 
   // send
-  if (do_sendmsg(sd, &msg, msglen)) 
+  if (do_sendmsg(&msg, msglen))
     goto fail;
 
   ret = 0;
index 8b9de3b3215beef6cc88b6a25d3966f9a7465eac..ab31789dc6574449440da49f43c55b19ae26511c 100644 (file)
@@ -205,7 +205,18 @@ private:
 
     int read_message(Message **pm);
     int write_message(Message *m);
-    int do_sendmsg(int sd, struct msghdr *msg, int len, bool more=false);
+    /**
+     * Write the given data (of length len) to the Pipe's socket. This function
+     * will loop until all passed data has been written out.
+     * If more is set, the function will optimize socket writes
+     * for additional data (by passing the MSG_MORE flag, aka TCP_CORK).
+     *
+     * @param msg The msghdr to write out
+     * @param len The length of the data in msg
+     * @param more Should be set true if this is one part of a larger message
+     * @return 0, or -1 on failure (unrecoverable -- close the socket).
+     */
+    int do_sendmsg(struct msghdr *msg, int len, bool more=false);
     int write_ack(uint64_t s);
     int write_keepalive();