[svn] commit: r1691 - in /trunk/src/lib/xfr: fd_share.cc fd_share.h xfrout_client.cc xfrout_client.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Apr 7 23:40:10 UTC 2010
Author: jinmei
Date: Wed Apr 7 23:40:10 2010
New Revision: 1691
Log:
cleanups:
- style fixes according to bind10 coding guideline
- constify things
- propset
Modified:
trunk/src/lib/xfr/fd_share.cc (contents, props changed)
trunk/src/lib/xfr/fd_share.h (contents, props changed)
trunk/src/lib/xfr/xfrout_client.cc (contents, props changed)
trunk/src/lib/xfr/xfrout_client.h (contents, props changed)
Modified: trunk/src/lib/xfr/fd_share.cc
==============================================================================
--- trunk/src/lib/xfr/fd_share.cc (original)
+++ trunk/src/lib/xfr/fd_share.cc Wed Apr 7 23:40:10 2010
@@ -11,6 +11,8 @@
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// 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>
@@ -27,14 +29,15 @@
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 = ¬hing;
nothing_ptr.iov_len = 1;
@@ -49,15 +52,17 @@
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 @@
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);
Modified: trunk/src/lib/xfr/fd_share.h
==============================================================================
--- trunk/src/lib/xfr/fd_share.h (original)
+++ trunk/src/lib/xfr/fd_share.h Wed Apr 7 23:40:10 2010
@@ -12,10 +12,10 @@
// 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 {
@@ -23,16 +23,18 @@
// 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:
Modified: trunk/src/lib/xfr/xfrout_client.cc
==============================================================================
--- trunk/src/lib/xfr/xfrout_client.cc (original)
+++ trunk/src/lib/xfr/xfrout_client.cc Wed Apr 7 23:40:10 2010
@@ -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 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;
}
Modified: trunk/src/lib/xfr/xfrout_client.h
==============================================================================
--- trunk/src/lib/xfr/xfrout_client.h (original)
+++ trunk/src/lib/xfr/xfrout_client.h Wed Apr 7 23:40:10 2010
@@ -12,9 +12,12 @@
// 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>
@@ -22,26 +25,25 @@
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 @@
} // End for namespace isc
#endif
+
+// Local Variables:
+// mode: c++
+// End:
More information about the bind10-changes
mailing list