Browse Source

cleanups:
- style fixes according to bind10 coding guideline
- constify things
- propset


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1691 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya 15 years ago
parent
commit
da1023a042
4 changed files with 68 additions and 52 deletions
  1. 24 19
      src/lib/xfr/fd_share.cc
  2. 8 6
      src/lib/xfr/fd_share.h
  3. 22 19
      src/lib/xfr/xfrout_client.cc
  4. 14 8
      src/lib/xfr/xfrout_client.h

+ 24 - 19
src/lib/xfr/fd_share.cc

@@ -12,6 +12,8 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+// $Id$
+
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -27,14 +29,15 @@ namespace xfr {
         int fd[n]; \
     }
 
+namespace {
 int
-send_fds_with_buffer(int sock, const int *fds, unsigned n_fds, void *buffer)
+send_fds_with_buffer(const int sock, const int* fds, const unsigned n_fds,
+                     void* buffer)
 {
     struct msghdr msghdr;
     char nothing = '!';
     struct iovec nothing_ptr;
-    struct cmsghdr *cmsg;
-    int i;
+    struct cmsghdr* cmsg;
 
     nothing_ptr.iov_base = &nothing;
     nothing_ptr.iov_len = 1;
@@ -49,15 +52,17 @@ send_fds_with_buffer(int sock, const int *fds, unsigned n_fds, void *buffer)
     cmsg->cmsg_len = msghdr.msg_controllen;
     cmsg->cmsg_level = SOL_SOCKET;
     cmsg->cmsg_type = SCM_RIGHTS;
-    for(i = 0; i < n_fds; i++)
+    for (int i = 0; i < n_fds; ++i) {
         ((int *)CMSG_DATA(cmsg))[i] = fds[i];
-    
-    int ret =  sendmsg(sock, &msghdr, 0);
+    }
+
+    const int ret =  sendmsg(sock, &msghdr, 0);
     return (ret >= 0 ? 0 : -1);
 }
 
 int
-recv_fds_with_buffer(int sock, int *fds, unsigned n_fds, void *buffer)
+recv_fds_with_buffer(const int sock, int* fds, const unsigned n_fds,
+                     void* buffer)
 {
     struct msghdr msghdr;
     char nothing;
@@ -78,35 +83,35 @@ recv_fds_with_buffer(int sock, int *fds, unsigned n_fds, void *buffer)
     cmsg->cmsg_len = msghdr.msg_controllen;
     cmsg->cmsg_level = SOL_SOCKET;
     cmsg->cmsg_type = SCM_RIGHTS;
-    for(i = 0; i < n_fds; i++)
+    for (i = 0; i < n_fds; i++) {
         ((int *)CMSG_DATA(cmsg))[i] = -1;
-    
-    if(recvmsg(sock, &msghdr, 0) < 0)
+    }
+
+    if (recvmsg(sock, &msghdr, 0) < 0) {
         return (-1);
+    }
 
-    for(i = 0; i < n_fds; i++) {
+    for (i = 0; i < n_fds; i++) {
         fds[i] = ((int *)CMSG_DATA(cmsg))[i];
     }
 
-    n_fds = (msghdr.msg_controllen - sizeof(struct cmsghdr)) / sizeof(int);
-    return n_fds;
+    return ((msghdr.msg_controllen - sizeof(struct cmsghdr)) / sizeof(int));
+}
 }
 
 int
-recv_fd(int sock)
-{
+recv_fd(const int sock) {
     FD_BUFFER_CREATE(1) buffer;
     int fd = 0;
-    int ret = recv_fds_with_buffer(sock, &fd, 1, &buffer);
-    if (ret == -1)
+    if (recv_fds_with_buffer(sock, &fd, 1, &buffer) == -1) {
         return -1;
+    }
 
     return fd;
 }
 
 int
-send_fd(int sock, int fd)
-{
+send_fd(const int sock, const int fd) {
     FD_BUFFER_CREATE(1) buffer;
     int ret = send_fds_with_buffer(sock, &fd, 1, &buffer);
     return ((ret < 0) ? -1 : ret);

+ 8 - 6
src/lib/xfr/fd_share.h

@@ -12,27 +12,29 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+// $Id$
+
 #ifndef FD_SHARE_H_
 #define FD_SHARE_H_
 
-#include <stdlib.h>
-
 namespace isc {
 namespace xfr {
 
 // Receive socket descriptor on unix domain socket 'sock'.
 // Returned value is the socket descriptor received.
 // Errors are indicated by a return value of -1.
-int
-recv_fd(int sock);
+int recv_fd(int sock);
 
 // Send socket descriptor "fd" to server over unix domain socket 'sock', 
 // the connection from socket 'sock' to unix domain server should be established first.
 // Errors are indicated by a return value of -1.
-int
-send_fd(int sock, int fd);
+int send_fd(int sock, int fd);
 
 } // End for namespace xfr
 } // End for namespace isc
 
 #endif
+
+// Local Variables: 
+// mode: c++
+// End: 

+ 22 - 19
src/lib/xfr/xfrout_client.cc

@@ -12,6 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+// $Id$
 
 #include <cstdlib>
 #include <cstring>
@@ -25,45 +26,47 @@ namespace isc {
 namespace xfr {
 
 void
-XfroutClient::connect()
-{
+XfroutClient::connect() {
     socket_.connect(stream_protocol::endpoint(file_path_));
 }
 
 void
-XfroutClient::disconnect()
-{
+XfroutClient::disconnect() {
     socket_.close();
 }
 
 void
-XfroutClient::sendData(uint8_t *msg_data, uint16_t msg_len)
-{
+XfroutClient::sendData(const uint8_t* msg_data, const uint16_t msg_len) {
     int count = 0;
-    while(count < msg_len) {
-        int size = send(socket_.native(), msg_data + count, msg_len - count, 0);
-        if (size == -1) 
-            isc_throw(XfroutError, "auth failed to send data to xfrout module\n");
-       
-       count += size;
+    while (count < msg_len) {
+        const int size = send(socket_.native(), msg_data + count,
+                              msg_len - count, 0);
+        if (size == -1) {
+            isc_throw(XfroutError, "auth failed to send data to xfrout module");
+        }
+        count += size;
     }
 
     return;
 }
 
 int 
-XfroutClient::sendXfroutRequestInfo(int tcp_sock, uint8_t *msg_data, uint16_t  msg_len)
+XfroutClient::sendXfroutRequestInfo(const int tcp_sock, uint8_t* msg_data,
+                                    const uint16_t msg_len)
 {
-    if (-1 == send_fd(socket_.native(), tcp_sock))
-        isc_throw(XfroutError, "Fail to send socket descriptor to xfrout module\n");
+    if (-1 == send_fd(socket_.native(), tcp_sock)) {
+        isc_throw(XfroutError,
+                  "Fail to send socket descriptor to xfrout module");
+    }
 
-    sendData((uint8_t *)&msg_len, 2);
+    sendData((uint8_t*)&msg_len, 2);
     sendData(msg_data, msg_len);
     
     int databuf = 0;
-    int status = recv(socket_.native(), &databuf, sizeof(int), 0);
-    if (status != 0)
-        isc_throw(XfroutError, "xfr query doesn't been processed properly by xfrout module\n");
+    if (recv(socket_.native(), &databuf, sizeof(int), 0) != 0) {
+        isc_throw(XfroutError,
+                  "xfr query hasn't been processed properly by xfrout module");
+    }
 
     return 0;
 }

+ 14 - 8
src/lib/xfr/xfrout_client.h

@@ -12,36 +12,38 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+// $Id$
 
 #ifndef _XFROUT_CLIENT_H
 #define _XFROUT_CLIENT_H
 
+#include <string>
+
 #include <boost/asio.hpp>
 #include <exceptions/exceptions.h>
 
 namespace isc {
 namespace xfr {
 
-class XfroutError: public Exception 
-{
-public: 
+class XfroutError: public Exception {
+public:
     XfroutError(const char *file, size_t line, const char *what):
         isc::Exception(file, line, what) {}
 };
 
 using boost::asio::local::stream_protocol;
-class XfroutClient
-{
+class XfroutClient {
 public:
-    XfroutClient(const std::string &file):
+    XfroutClient(const std::string& file):
         socket_(io_service_), file_path_(file) {}
 
     void connect();
     void disconnect();
-    int sendXfroutRequestInfo(int tcp_sock, uint8_t *msg_data, uint16_t msg_len);
+    int sendXfroutRequestInfo(int tcp_sock, uint8_t* msg_data,
+                              uint16_t msg_len);
 
 private:
-    void sendData(uint8_t *msg_data, uint16_t msg_len);
+    void sendData(const uint8_t *msg_data, uint16_t msg_len);
 
 private:
     boost::asio::io_service io_service_;
@@ -54,3 +56,7 @@ private:
 } // End for namespace isc
 
 #endif
+
+// Local Variables: 
+// mode: c++
+// End: