From 335b84a80d119e095e246298894be6013d4575be Mon Sep 17 00:00:00 2001 From: Ananth Suryanarayana Date: Tue, 2 Aug 2016 17:40:33 -0700 Subject: [PATCH] Fix cpplint errors in src/io All production C++ code under src/io pass cleanly with these changes Change-Id: I7fb24437dd502d7ef36f82d5b5a12dfdb4ab901e Partial-Bug: 1602347 --- src/analytics/collector.cc | 4 +- src/analytics/ipfix_collector.cc | 4 +- src/analytics/ipfix_collector.h | 8 +- src/analytics/main.cc | 4 +- src/analytics/protobuf_server.cc | 22 ++--- src/analytics/sflow_collector.cc | 4 +- src/analytics/sflow_collector.h | 4 +- src/analytics/sflow_generator.cc | 2 +- src/analytics/sflow_generator.h | 2 +- src/analytics/syslog_collector.cc | 8 +- src/analytics/syslog_collector.h | 2 +- src/analytics/viz_collector.cc | 4 +- src/bfd/bfd_udp_connection.cc | 2 +- src/bfd/bfd_udp_connection.h | 2 +- src/bgp/bgp_sandesh.cc | 4 +- src/io/event_manager.cc | 8 +- src/io/event_manager.h | 7 +- src/io/io_log.h | 6 +- src/io/io_utils.cc | 32 +++---- src/io/io_utils.h | 10 +-- src/io/netlink.hpp | 28 +++--- src/io/server_manager.h | 8 +- src/io/ssl_server.cc | 15 ++-- src/io/ssl_server.h | 12 +-- src/io/ssl_session.cc | 33 +++---- src/io/ssl_session.h | 13 +-- src/io/tcp_message_write.cc | 14 +-- src/io/tcp_message_write.h | 20 ++--- src/io/tcp_server.cc | 25 +++--- src/io/tcp_server.h | 28 ++++-- src/io/tcp_session.cc | 90 ++++++++++--------- src/io/tcp_session.h | 44 +++++---- src/io/test/tcp_io_test.cc | 12 +-- src/io/test/udp_io_test.cc | 32 +++---- src/io/test/usock_io_test.cc | 10 +-- src/io/udp_server.cc | 24 ++--- src/io/udp_server.h | 22 ++--- src/io/usock_server.cc | 52 +++++------ src/io/usock_server.h | 74 ++++++--------- .../agent/nexthop_server/nexthop_server.cc | 2 +- src/xmpp/xmpp_server.cc | 4 +- 41 files changed, 356 insertions(+), 345 deletions(-) diff --git a/src/analytics/collector.cc b/src/analytics/collector.cc index e2580329040..d2c445ca6c8 100644 --- a/src/analytics/collector.cc +++ b/src/analytics/collector.cc @@ -372,10 +372,10 @@ void Collector::GetGeneratorUVEInfo(vector &genlist) { if (session) { ginfo.set_session_stats(session->GetStats()); SocketIOStats rx_stats; - session->GetRxSocketStats(rx_stats); + session->GetRxSocketStats(&rx_stats); ginfo.set_session_rx_socket_stats(rx_stats); SocketIOStats tx_stats; - session->GetTxSocketStats(tx_stats); + session->GetTxSocketStats(&tx_stats); ginfo.set_session_tx_socket_stats(tx_stats); } diff --git a/src/analytics/ipfix_collector.cc b/src/analytics/ipfix_collector.cc index cc5289aa486..78ecd77cab4 100644 --- a/src/analytics/ipfix_collector.cc +++ b/src/analytics/ipfix_collector.cc @@ -26,7 +26,7 @@ static map uflowfields_ = boost::assign::map_list_of( "ingressInterface","pifindex"); -void IpfixCollector::HandleReceive(boost::asio::const_buffer& buffer, +void IpfixCollector::HandleReceive(const boost::asio::const_buffer& buffer, boost::asio::ip::udp::endpoint remote_endpoint, size_t bytes_transferred, const boost::system::error_code& error) { @@ -81,7 +81,7 @@ void IpfixCollector::Shutdown() { } } -void IpfixCollector::ProcessIpfixPacket(boost::asio::const_buffer& buffer, +void IpfixCollector::ProcessIpfixPacket(const boost::asio::const_buffer& buffer, size_t length, boost::asio::ip::udp::endpoint generator_ip) { num_packets_++; diff --git a/src/analytics/ipfix_collector.h b/src/analytics/ipfix_collector.h index 2a2671bc82e..b6aa00ba8a8 100644 --- a/src/analytics/ipfix_collector.h +++ b/src/analytics/ipfix_collector.h @@ -45,13 +45,13 @@ class IpfixCollector : public UdpServer { std::map uflowfields_; boost::scoped_ptr colinfo_; - void HandleReceive(boost::asio::const_buffer& buffer, + void HandleReceive(const boost::asio::const_buffer& buffer, boost::asio::ip::udp::endpoint remote_endpoint, size_t bytes_transferred, const boost::system::error_code& error); - void ProcessIpfixPacket(boost::asio::const_buffer& buffer, - size_t length, - boost::asio::ip::udp::endpoint generator_ip); + void ProcessIpfixPacket(const boost::asio::const_buffer& buffer, + size_t length, + boost::asio::ip::udp::endpoint generator_ip); int RegisterCb(void); diff --git a/src/analytics/main.cc b/src/analytics/main.cc index f1decc781d0..224df60839a 100644 --- a/src/analytics/main.cc +++ b/src/analytics/main.cc @@ -114,10 +114,10 @@ bool CollectorSummaryLogger(Collector *collector, const string & hostname, // Get socket stats SocketIOStats rx_stats; - collector->GetRxSocketStats(rx_stats); + collector->GetRxSocketStats(&rx_stats); state.set_rx_socket_stats(rx_stats); SocketIOStats tx_stats; - collector->GetTxSocketStats(tx_stats); + collector->GetTxSocketStats(&tx_stats); state.set_tx_socket_stats(tx_stats); CollectorInfo::Send(state); diff --git a/src/analytics/protobuf_server.cc b/src/analytics/protobuf_server.cc index b1b59c60444..dc4b136d8d3 100644 --- a/src/analytics/protobuf_server.cc +++ b/src/analytics/protobuf_server.cc @@ -383,7 +383,7 @@ void ProcessProtobufMessage(const Message& message, } // namespace impl class ProtobufServer::ProtobufServerImpl { - public: +public: ProtobufServerImpl(EventManager *evm, uint16_t udp_server_port, StatWalker::StatTableInsertFn stat_db_callback) : udp_server_(new ProtobufUdpServer(evm, udp_server_port, @@ -417,12 +417,12 @@ class ProtobufServer::ProtobufServerImpl { return udp_server_->GetReceivedMessageStatistics(v_rx_msg_stats); } - private: +private: // // ProtobufUdpServer // class ProtobufUdpServer : public UdpServer { - public: + public: ProtobufUdpServer(EventManager *evm, uint16_t port, StatWalker::StatTableInsertFn stat_db_callback) : UdpServer(evm, kBufferSize), @@ -447,7 +447,7 @@ class ProtobufServer::ProtobufServerImpl { return true; } - virtual void OnRead(boost::asio::const_buffer &recv_buffer, + virtual void OnRead(const boost::asio::const_buffer &recv_buffer, const boost::asio::ip::udp::endpoint &remote_endpoint) { uint64_t timestamp; Message *message = NULL; @@ -476,12 +476,12 @@ class ProtobufServer::ProtobufServerImpl { std::vector *v_rx_msg_stats) { if (v_tx_stats != NULL) { SocketIOStats tx_stats; - GetTxSocketStats(tx_stats); + GetTxSocketStats(&tx_stats); v_tx_stats->push_back(tx_stats); } if (v_rx_stats != NULL) { SocketIOStats rx_stats; - GetRxSocketStats(rx_stats); + GetRxSocketStats(&rx_stats); v_rx_stats->push_back(rx_stats); } if (v_rx_msg_stats != NULL) { @@ -494,12 +494,12 @@ class ProtobufServer::ProtobufServerImpl { msg_stats_.GetRx(v_rx_msg_stats); } - private: + private: // // MessageStatistics // class MessageStatistics { - public: + public: void UpdateRx( const boost::asio::ip::udp::endpoint &remote_endpoint, const std::string &message_name, @@ -519,7 +519,7 @@ class ProtobufServer::ProtobufServerImpl { std::vector *semsv) { GetRxInternal(semsv, false); } - private: + private: class MessageInfo; void GetRxInternal( @@ -567,7 +567,7 @@ class ProtobufServer::ProtobufServerImpl { // MessageInfo // class MessageInfo { - public: + public: MessageInfo() : messages_(0), bytes_(0), @@ -598,7 +598,7 @@ class ProtobufServer::ProtobufServerImpl { sems->set_last_timestamp(last_timestamp_); } - private: + private: uint64_t messages_; uint64_t bytes_; uint64_t errors_; diff --git a/src/analytics/sflow_collector.cc b/src/analytics/sflow_collector.cc index 497f0464290..79a550a812e 100644 --- a/src/analytics/sflow_collector.cc +++ b/src/analytics/sflow_collector.cc @@ -35,7 +35,7 @@ void SFlowCollector::Shutdown() { } } -void SFlowCollector::HandleReceive(boost::asio::const_buffer& buffer, +void SFlowCollector::HandleReceive(const boost::asio::const_buffer& buffer, boost::asio::ip::udp::endpoint remote_endpoint, size_t bytes_transferred, const boost::system::error_code& error) { @@ -47,7 +47,7 @@ void SFlowCollector::HandleReceive(boost::asio::const_buffer& buffer, } } -void SFlowCollector::ProcessSFlowPacket(boost::asio::const_buffer& buffer, +void SFlowCollector::ProcessSFlowPacket(const boost::asio::const_buffer& buffer, size_t length, const std::string& generator_ip) { num_packets_++; diff --git a/src/analytics/sflow_collector.h b/src/analytics/sflow_collector.h index 7f71dbcb9fa..96495b71488 100644 --- a/src/analytics/sflow_collector.h +++ b/src/analytics/sflow_collector.h @@ -24,11 +24,11 @@ class SFlowCollector : public UdpServer { virtual void Shutdown(); private: - void HandleReceive(boost::asio::const_buffer& buffer, + void HandleReceive(const boost::asio::const_buffer& buffer, boost::asio::ip::udp::endpoint remote_endpoint, size_t bytes_transferred, const boost::system::error_code& error); - void ProcessSFlowPacket(boost::asio::const_buffer& buffer, + void ProcessSFlowPacket(const boost::asio::const_buffer& buffer, size_t length, const std::string& generator_ip); SFlowGenerator* GetSFlowGenerator(const std::string& generator_ip); diff --git a/src/analytics/sflow_generator.cc b/src/analytics/sflow_generator.cc index 6f4db84e95f..a497a0bb8b8 100644 --- a/src/analytics/sflow_generator.cc +++ b/src/analytics/sflow_generator.cc @@ -33,7 +33,7 @@ SFlowGenerator::SFlowGenerator(const std::string& ip_address, SFlowGenerator::~SFlowGenerator() { } -bool SFlowGenerator::EnqueueSFlowPacket(boost::asio::const_buffer& buffer, +bool SFlowGenerator::EnqueueSFlowPacket(const boost::asio::const_buffer& buffer, size_t length, uint64_t timestamp) { num_packets_++; time_last_pkt_seen_ = timestamp; diff --git a/src/analytics/sflow_generator.h b/src/analytics/sflow_generator.h index 01fb05b5940..c6cb409d702 100644 --- a/src/analytics/sflow_generator.h +++ b/src/analytics/sflow_generator.h @@ -28,7 +28,7 @@ class SFlowGenerator { SFlowCollector* sflow_collector, DbHandlerPtr db_handler); ~SFlowGenerator(); - bool EnqueueSFlowPacket(boost::asio::const_buffer& buffer, + bool EnqueueSFlowPacket(const boost::asio::const_buffer& buffer, size_t length, uint64_t timestamp); private: bool ProcessSFlowPacket(boost::shared_ptr); diff --git a/src/analytics/syslog_collector.cc b/src/analytics/syslog_collector.cc index 90855b8706f..643917cf17d 100644 --- a/src/analytics/syslog_collector.cc +++ b/src/analytics/syslog_collector.cc @@ -63,7 +63,7 @@ class SyslogTcpSession : public TcpSession typedef boost::intrusive_ptr SyslogTcpSessionPtr; SyslogTcpSession (SyslogTcpListener *server, Socket *socket); - virtual void OnRead (boost::asio::const_buffer buf); + virtual void OnRead (const boost::asio::const_buffer buf); }; class TCPSyslogQueueEntry : public SyslogQueueEntry @@ -91,7 +91,7 @@ class UDPSyslogQueueEntry : public SyslogQueueEntry public: UDPSyslogQueueEntry (SyslogUDPListener* svr, udp::endpoint ep, - boost::asio::const_buffer &d, size_t l): + const boost::asio::const_buffer &d, size_t l): SyslogQueueEntry (d, l, ep.address ().to_string (), ep.port ()), ep_ (ep), b_(d), server_ (svr) { @@ -612,7 +612,7 @@ void SyslogUDPListener::Start (std::string ipaddress, int port) } void SyslogUDPListener::HandleReceive ( - boost::asio::const_buffer &recv_buffer, + const boost::asio::const_buffer &recv_buffer, udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error) @@ -705,7 +705,7 @@ SyslogTcpSession::SyslogTcpSession (SyslogTcpListener *server, Socket *socket) : //set_observer(boost::bind(&SyslogTcpSession::OnEvent, this, _1, _2)); } void -SyslogTcpSession::OnRead (boost::asio::const_buffer buf) +SyslogTcpSession::OnRead (const boost::asio::const_buffer buf) { boost::system::error_code ec; // TODO: handle error diff --git a/src/analytics/syslog_collector.h b/src/analytics/syslog_collector.h index 996bba845d4..8fda72a2c5a 100644 --- a/src/analytics/syslog_collector.h +++ b/src/analytics/syslog_collector.h @@ -56,7 +56,7 @@ class SyslogUDPListener: public UdpServer virtual void Shutdown (); private: - void HandleReceive (boost::asio::const_buffer &recv_buffer, + void HandleReceive(const boost::asio::const_buffer &recv_buffer, boost::asio::ip::udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error); diff --git a/src/analytics/viz_collector.cc b/src/analytics/viz_collector.cc index cd969686654..b9d5de04029 100644 --- a/src/analytics/viz_collector.cc +++ b/src/analytics/viz_collector.cc @@ -272,10 +272,10 @@ class ShowCollectorServerHandler { // Socket statistics SocketIOStats rx_socket_stats; Collector *collector(vsc->Analytics()->GetCollector()); - collector->GetRxSocketStats(rx_socket_stats); + collector->GetRxSocketStats(&rx_socket_stats); resp->set_rx_socket_stats(rx_socket_stats); SocketIOStats tx_socket_stats; - collector->GetTxSocketStats(tx_socket_stats); + collector->GetTxSocketStats(&tx_socket_stats); resp->set_tx_socket_stats(tx_socket_stats); // Collector statistics resp->set_stats(vsc->Analytics()->GetCollector()->GetStats()); diff --git a/src/bfd/bfd_udp_connection.cc b/src/bfd/bfd_udp_connection.cc index 415dfb29780..0c634fdf9af 100644 --- a/src/bfd/bfd_udp_connection.cc +++ b/src/bfd/bfd_udp_connection.cc @@ -26,7 +26,7 @@ void UDPConnectionManager::UDPRecvServer::RegisterCallback( } void UDPConnectionManager::UDPRecvServer::HandleReceive( - boost::asio::const_buffer &recv_buffer, + const boost::asio::const_buffer &recv_buffer, boost::asio::ip::udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error) { diff --git a/src/bfd/bfd_udp_connection.h b/src/bfd/bfd_udp_connection.h index c94bb621301..2cea7f5e9be 100644 --- a/src/bfd/bfd_udp_connection.h +++ b/src/bfd/bfd_udp_connection.h @@ -35,7 +35,7 @@ class UDPConnectionManager : public Connection { public: UDPRecvServer(EventManager *evm, int recvPort); void RegisterCallback(RecvCallback callback); - void HandleReceive(boost::asio::const_buffer &recv_buffer, + void HandleReceive(const boost::asio::const_buffer &recv_buffer, boost::asio::ip::udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error); diff --git a/src/bgp/bgp_sandesh.cc b/src/bgp/bgp_sandesh.cc index c7112ea75cf..df6b8d97927 100644 --- a/src/bgp/bgp_sandesh.cc +++ b/src/bgp/bgp_sandesh.cc @@ -407,10 +407,10 @@ class ShowBgpServerHandler { ShowBgpServerResp *resp = new ShowBgpServerResp; SocketIOStats peer_socket_stats; - bsc->bgp_server->session_manager()->GetRxSocketStats(peer_socket_stats); + bsc->bgp_server->session_manager()->GetRxSocketStats(&peer_socket_stats); resp->set_rx_socket_stats(peer_socket_stats); - bsc->bgp_server->session_manager()->GetTxSocketStats(peer_socket_stats); + bsc->bgp_server->session_manager()->GetTxSocketStats(&peer_socket_stats); resp->set_tx_socket_stats(peer_socket_stats); resp->set_context(req->context()); diff --git a/src/io/event_manager.cc b/src/io/event_manager.cc index ca63f0733b2..54070456908 100644 --- a/src/io/event_manager.cc +++ b/src/io/event_manager.cc @@ -4,11 +4,13 @@ #include "Thrift.h" +#include + #include "io/event_manager.h" #include "base/logging.h" #include "io/io_log.h" -using namespace boost::asio; +using boost::asio::io_service; SandeshTraceBufferPtr IOTraceBuf(SandeshTraceBufferCreate(IO_TRACE_BUF, 1000)); @@ -18,13 +20,11 @@ EventManager::EventManager() { void EventManager::Shutdown() { shutdown_ = true; - - // TODO: make sure that are no users of this event manager. io_service_.stop(); } void EventManager::Run() { - using namespace apache::thrift; + using apache::thrift::TException; assert(mutex_.try_lock()); io_service::work work(io_service_); diff --git a/src/io/event_manager.h b/src/io/event_manager.h index 5c1938f5d15..210819e5b74 100644 --- a/src/io/event_manager.h +++ b/src/io/event_manager.h @@ -2,10 +2,13 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ +#ifndef SRC_IO_EVENT_MANAGER_H_ +#define SRC_IO_EVENT_MANAGER_H_ + #pragma once -#include #include +#include #include "base/util.h" @@ -42,3 +45,5 @@ class EventManager { DISALLOW_COPY_AND_ASSIGN(EventManager); }; + +#endif // SRC_IO_EVENT_MANAGER_H_ diff --git a/src/io/io_log.h b/src/io/io_log.h index 306bf10742c..1220829041b 100644 --- a/src/io/io_log.h +++ b/src/io/io_log.h @@ -2,9 +2,9 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#ifndef __IO_LOG_H__ +#ifndef SRC_IO_IO_LOG_H_ -#define __IO_LOG_H__ +#define SRC_IO_IO_LOG_H_ #include "base/logging.h" #include "sandesh/sandesh_types.h" @@ -180,5 +180,5 @@ do { \ #define UDP_UT_LOG_DEBUG(arg) \ IO_UT_LOG_DEBUG(UdpMessage, "UDP", UDP_DIR_NA, arg) -#endif // __IO_LOG_H__ +#endif // SRC_IO_IO_LOG_H_ diff --git a/src/io/io_utils.cc b/src/io/io_utils.cc index ba1e268ebec..e39fd326d5f 100644 --- a/src/io/io_utils.cc +++ b/src/io/io_utils.cc @@ -24,40 +24,40 @@ SocketStats::SocketStats() { read_blocked_duration_usecs = 0; } -void SocketStats::GetRxStats(SocketIOStats &socket_stats) const { - socket_stats.calls = read_calls; - socket_stats.bytes = read_bytes; +void SocketStats::GetRxStats(SocketIOStats *socket_stats) const { + socket_stats->calls = read_calls; + socket_stats->bytes = read_bytes; if (read_calls) { - socket_stats.average_bytes = read_bytes/read_calls; + socket_stats->average_bytes = read_bytes/read_calls; } - socket_stats.blocked_count = read_blocked; - socket_stats.blocked_duration = duration_usecs_to_string( + socket_stats->blocked_count = read_blocked; + socket_stats->blocked_duration = duration_usecs_to_string( read_blocked_duration_usecs); if (read_blocked) { - socket_stats.average_blocked_duration = + socket_stats->average_blocked_duration = duration_usecs_to_string( read_blocked_duration_usecs/ read_blocked); } - socket_stats.errors = read_errors; + socket_stats->errors = read_errors; } -void SocketStats::GetTxStats(SocketIOStats &socket_stats) const { - socket_stats.calls = write_calls; - socket_stats.bytes = write_bytes; +void SocketStats::GetTxStats(SocketIOStats *socket_stats) const { + socket_stats->calls = write_calls; + socket_stats->bytes = write_bytes; if (write_calls) { - socket_stats.average_bytes = write_bytes/write_calls; + socket_stats->average_bytes = write_bytes/write_calls; } - socket_stats.blocked_count = write_blocked; - socket_stats.blocked_duration = duration_usecs_to_string( + socket_stats->blocked_count = write_blocked; + socket_stats->blocked_duration = duration_usecs_to_string( write_blocked_duration_usecs); if (write_blocked) { - socket_stats.average_blocked_duration = + socket_stats->average_blocked_duration = duration_usecs_to_string( write_blocked_duration_usecs/ write_blocked); } - socket_stats.errors = write_errors; + socket_stats->errors = write_errors; } } // namespace io diff --git a/src/io/io_utils.h b/src/io/io_utils.h index 6c602e2824b..1aeb77822dd 100644 --- a/src/io/io_utils.h +++ b/src/io/io_utils.h @@ -2,8 +2,8 @@ // Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. // -#ifndef IO_IO_UTILS_H_ -#define IO_IO_UTILS_H_ +#ifndef SRC_IO_IO_UTILS_H_ +#define SRC_IO_IO_UTILS_H_ #include @@ -14,8 +14,8 @@ namespace io { struct SocketStats { SocketStats(); - void GetRxStats(SocketIOStats &socket_stats) const; - void GetTxStats(SocketIOStats &socket_stats) const; + void GetRxStats(SocketIOStats *socket_stats) const; + void GetTxStats(SocketIOStats *socket_stats) const; tbb::atomic read_calls; tbb::atomic read_bytes; @@ -32,4 +32,4 @@ struct SocketStats { } // namespace io -#endif // IO_IO_UTILS_H_ +#endif // SRC_IO_IO_UTILS_H_ diff --git a/src/io/netlink.hpp b/src/io/netlink.hpp index ccb8b098529..3b426350bc4 100644 --- a/src/io/netlink.hpp +++ b/src/io/netlink.hpp @@ -2,8 +2,8 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#ifndef __IO_NETLINK_H__ -#define __IO_NETLINK_H__ +#ifndef SRC_IO_NETLINK_HPP_ +#define SRC_IO_NETLINK_HPP_ #include #include #include @@ -14,23 +14,21 @@ #include #include -using namespace boost::asio; - class EventManager; -struct RtMsg{ - struct rt_msghdr m_rtm; - char m_space[512]; +struct RtMsg{ + struct rt_msghdr m_rtm; + char m_space[512]; }; class netlink_sock { public: - netlink_sock(boost::asio::io_service &ios) : socket_(ios) { + explicit netlink_sock(boost::asio::io_service &ios) : socket_(ios) { socket_.open(); RtMsgTest(); } - netlink_sock(boost::asio::io_service &ios, int proto) : + netlink_sock(const boost::asio::io_service &ios, int proto) : socket_(ios, proto) { RtMsgTest(); } @@ -62,14 +60,14 @@ class netlink_sock { socket_.async_send(boost::asio::buffer(&msg_, len), boost::bind(&netlink_sock::write_handler, this, placeholders::error, - placeholders::bytes_transferred) - ); + placeholders::bytes_transferred)); } void read_handler(const boost::system::error_code& error, size_t bytes_transferred) { - std::cout << "Came in READ_HANDLER. Bytes read " << bytes_transferred << std::endl; + std::cout << "Came in READ_HANDLER. Bytes read " + << bytes_transferred << std::endl; if (error) { std::cerr << "read error: " << boost::system::system_error(error).what() << std::endl; @@ -87,15 +85,13 @@ class netlink_sock { socket_.async_receive(boost::asio::buffer(&msg_, 200), boost::bind(&netlink_sock::read_handler, this, placeholders::error, - placeholders::bytes_transferred) - ); + placeholders::bytes_transferred)); } boost::asio::netlink::raw::socket socket_; boost::array buff_; RtMsg msg_; int seqno_; - }; -#endif +#endif // SRC_IO_NETLINK_HPP_ diff --git a/src/io/server_manager.h b/src/io/server_manager.h index 7097e20d231..446c62e3a82 100644 --- a/src/io/server_manager.h +++ b/src/io/server_manager.h @@ -2,11 +2,11 @@ * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. */ -#ifndef IO_SERVER_MANAGER_H_ -#define IO_SERVER_MANAGER_H_ +#ifndef SRC_IO_SERVER_MANAGER_H_ +#define SRC_IO_SERVER_MANAGER_H_ -#include #include +#include // // ServerManager is the place holder for all the TcpServer and UdpServer @@ -67,4 +67,4 @@ typename ServerManager::ServerSet template tbb::mutex ServerManager::mutex_; -#endif // IO_SERVER_MANAGER_H_ +#endif // SRC_IO_SERVER_MANAGER_H_ diff --git a/src/io/ssl_server.cc b/src/io/ssl_server.cc index de3b41bdb61..21b0a5f11de 100644 --- a/src/io/ssl_server.cc +++ b/src/io/ssl_server.cc @@ -5,8 +5,8 @@ #include #include -#include "ssl_server.h" -#include "ssl_session.h" +#include "io/ssl_server.h" +#include "io/ssl_session.h" #include "io/event_manager.h" #include "io/io_utils.h" @@ -49,8 +49,8 @@ TcpSession *SslServer::AllocSession(bool server_session) { return session; } -void SslServer::AcceptHandlerComplete(TcpSessionPtr &session) { - SslSession *ssl= static_cast(session.get()); +void SslServer::AcceptHandlerComplete(TcpSessionPtr session) { + SslSession *ssl = static_cast(session.get()); if (ssl->IsSslDisabled() || ssl->IsSslHandShakeDelayed()) { TcpServer::AcceptHandlerComplete(session); } else { @@ -87,8 +87,8 @@ void SslServer::AcceptHandShakeHandler(TcpServerPtr server, } } -void SslServer::ConnectHandlerComplete(TcpSessionPtr &session) { - SslSession *ssl= static_cast(session.get()); +void SslServer::ConnectHandlerComplete(TcpSessionPtr session) { + SslSession *ssl = static_cast(session.get()); if (ssl->IsSslDisabled() || ssl->IsSslHandShakeDelayed()) { TcpServer::ConnectHandlerComplete(session); } else { @@ -104,8 +104,7 @@ void SslServer::ConnectHandlerComplete(TcpSessionPtr &session) { } void SslServer::ConnectHandShakeHandler(TcpServerPtr server, - TcpSessionPtr session, - const boost::system::error_code& error) { + TcpSessionPtr session, const boost::system::error_code& error) { SslServer *ssl_server = static_cast(server.get()); SslSession *ssl_session = static_cast(session.get()); ssl_session->ssl_handshake_in_progress_ = false; diff --git a/src/io/ssl_server.h b/src/io/ssl_server.h index 82e666ebe2f..8b7fd34c666 100644 --- a/src/io/ssl_server.h +++ b/src/io/ssl_server.h @@ -2,8 +2,8 @@ * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. */ -#ifndef __src_io_ssl_server_h__ -#define __src_io_ssl_server_h__ +#ifndef SRC_IO_SSL_SERVER_H_ +#define SRC_IO_SSL_SERVER_H_ #include @@ -44,19 +44,19 @@ class SslServer : public TcpServer { TcpSession *AllocSession(bool server_session); // override accept complete handler to trigger handshake - virtual void AcceptHandlerComplete(TcpSessionPtr &session); + virtual void AcceptHandlerComplete(TcpSessionPtr session); // override connect complete handler to trigger handshake - void ConnectHandlerComplete(TcpSessionPtr &session); + void ConnectHandlerComplete(TcpSessionPtr session); Socket *accept_socket() const; void set_accept_socket(); boost::asio::ssl::context context_; - std::auto_ptr so_ssl_accept_; // SSL socket used in async_accept + std::auto_ptr so_ssl_accept_; // SSL socket used in async_accept bool ssl_enabled_; bool ssl_handshake_delayed_; DISALLOW_COPY_AND_ASSIGN(SslServer); }; -#endif //__src_io_ssl_server_h__ +#endif // SRC_IO_SSL_SERVER_H_ diff --git a/src/io/ssl_session.cc b/src/io/ssl_session.cc index 2833764b920..f86c5a2422f 100644 --- a/src/io/ssl_session.cc +++ b/src/io/ssl_session.cc @@ -2,17 +2,24 @@ * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. */ +#include "io/ssl_session.h" + +#include + #include #include -#include "ssl_session.h" #include "io/io_log.h" #include "io/io_utils.h" using boost::asio::async_write; using boost::asio::buffer; +using boost::asio::buffer_cast; using boost::asio::mutable_buffer; +using boost::asio::mutable_buffers_1; using boost::asio::null_buffers; +using boost::asio::placeholders::error; +using boost::asio::ssl::stream_base; using boost::bind; using boost::function; using boost::system::error_code; @@ -21,8 +28,6 @@ using std::srand; using std::string; using std::time; -using namespace boost::asio; - class SslSession::SslReader : public Task { public: typedef function ReadHandler; @@ -44,6 +49,7 @@ class SslSession::SslReader : public Task { return true; } string Description() const { return "SslSession::SslReader"; } + private: SslSessionPtr session_; ReadHandler read_fn_; @@ -70,7 +76,6 @@ SslSession::~SslSession() { Task* SslSession::CreateReaderTask(mutable_buffer buffer, size_t bytes_transferred) { - Buffer rdbuf(buffer_cast(buffer), bytes_transferred); SslReader *task = new SslReader(this->reader_task_id(), SslSessionPtr(this), bind(&SslSession::OnRead, this, _1), rdbuf); @@ -83,21 +88,20 @@ TcpSession::Socket *SslSession::socket() const { return &ssl_socket_->next_layer(); } -size_t SslSession::ReadSome(mutable_buffer buffer, error_code &error) { +size_t SslSession::ReadSome(mutable_buffer buffer, error_code *error) { // Read data from the tcp socket or from the ssl socket, as appropriate. assert(!ssl_handshake_in_progress_); if (!IsSslHandShakeSuccessLocked()) return TcpSession::ReadSome(buffer, error); // do ssl read here in IO context, ignore errors - return ssl_socket_->read_some(mutable_buffers_1(buffer), error); + return ssl_socket_->read_some(mutable_buffers_1(buffer), *error); } size_t SslSession::WriteSome(const uint8_t *data, size_t len, - error_code &error) { - + error_code *error) { if (IsSslHandShakeSuccessLocked()) { - return ssl_socket_->write_some(buffer(data, len), error); + return ssl_socket_->write_some(buffer(data, len), *error); } else { return (TcpSession::WriteSome(data, len, error)); } @@ -107,7 +111,7 @@ void SslSession::AsyncWrite(const u_int8_t *data, size_t size) { if (IsSslHandShakeSuccessLocked()) { async_write(*ssl_socket_.get(), buffer(data, size), bind(&TcpSession::AsyncWriteHandler, - TcpSessionPtr(this), placeholders::error)); + TcpSessionPtr(this), error)); } else { return (TcpSession::AsyncWrite(data, size)); } @@ -116,7 +120,6 @@ void SslSession::AsyncWrite(const u_int8_t *data, size_t size) { void SslSession::SslHandShakeCallback(SslHandShakeCallbackHandler cb, SslSessionPtr session, const error_code &error) { - session->ssl_handshake_in_progress_ = false; if (!error) { session->SetSslHandShakeSuccess(); @@ -135,13 +138,13 @@ void SslSession::TriggerSslHandShakeInternal( error_code ec; session->ssl_handshake_in_progress_ = true; if (session->IsServerSession()) { - session->ssl_socket_->async_handshake(ssl::stream_base::server, + session->ssl_socket_->async_handshake(stream_base::server, bind(&SslSession::SslHandShakeCallback, cb, session, - placeholders::error)); + error)); } else { - session->ssl_socket_->async_handshake(ssl::stream_base::client, + session->ssl_socket_->async_handshake(stream_base::client, bind(&SslSession::SslHandShakeCallback, cb, session, - placeholders::error)); + error)); } } diff --git a/src/io/ssl_session.h b/src/io/ssl_session.h index 99dcebb1a50..1f686fcfced 100644 --- a/src/io/ssl_session.h +++ b/src/io/ssl_session.h @@ -2,8 +2,8 @@ * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. */ -#ifndef __src_io_ssl_session_h__ -#define __src_io_ssl_session_h__ +#ifndef SRC_IO_SSL_SESSION_H_ +#define SRC_IO_SSL_SESSION_H_ #include "io/tcp_session.h" #include "io/ssl_server.h" @@ -65,12 +65,13 @@ class SslSession : public TcpSession { // session mutex held, to avoid concurrent read and write operations // on same socket. size_t ReadSome(boost::asio::mutable_buffer buffer, - boost::system::error_code &error); + boost::system::error_code *error); std::size_t WriteSome(const uint8_t *data, std::size_t len, - boost::system::error_code &error); + boost::system::error_code *error); void AsyncWrite(const u_int8_t *data, std::size_t size); - static void TriggerSslHandShakeInternal(SslSessionPtr, SslHandShakeCallbackHandler); + static void TriggerSslHandShakeInternal(SslSessionPtr ptr, + SslHandShakeCallbackHandler cb); virtual Task* CreateReaderTask(boost::asio::mutable_buffer, size_t); @@ -102,4 +103,4 @@ class SslSession : public TcpSession { DISALLOW_COPY_AND_ASSIGN(SslSession); }; -#endif // __src_io_ssl_session_h__ +#endif // SRC_IO_SSL_SESSION_H_ diff --git a/src/io/tcp_message_write.cc b/src/io/tcp_message_write.cc index b28bdb00ed2..cd52ffded82 100644 --- a/src/io/tcp_message_write.cc +++ b/src/io/tcp_message_write.cc @@ -9,8 +9,10 @@ #include "io/tcp_session.h" #include "io/io_log.h" -using namespace boost::asio; -using namespace boost::system; +using boost::asio::buffer; +using boost::asio::buffer_cast; +using boost::asio::mutable_buffer; +using boost::system::error_code; using tbb::mutex; TcpMessageWriter::TcpMessageWriter(TcpSession *session) : @@ -25,7 +27,7 @@ TcpMessageWriter::~TcpMessageWriter() { buffer_queue_.clear(); } -int TcpMessageWriter::Send(const uint8_t *data, size_t len, error_code &ec) { +int TcpMessageWriter::Send(const uint8_t *data, size_t len, error_code *ec) { int wrote = 0; // Update socket write call statistics. @@ -37,7 +39,7 @@ int TcpMessageWriter::Send(const uint8_t *data, size_t len, error_code &ec) { if (buffer_queue_.empty()) { wrote = session_->WriteSome(data, len, ec); - if (TcpSession::IsSocketErrorHard(ec)) return -1; + if (TcpSession::IsSocketErrorHard(*ec)) return -1; assert(wrote >= 0); if ((size_t)wrote != len) { @@ -56,13 +58,13 @@ int TcpMessageWriter::Send(const uint8_t *data, size_t len, error_code &ec) { } // Socket is ready for write. Flush any pending data -void TcpMessageWriter::HandleWriteReady(error_code &error) { +void TcpMessageWriter::HandleWriteReady(error_code *error) { while (!buffer_queue_.empty()) { boost::asio::mutable_buffer head = buffer_queue_.front(); const uint8_t *data = buffer_cast(head) + offset_; int remaining = buffer_size(head) - offset_; int wrote = session_->WriteSome(data, remaining, error); - if (TcpSession::IsSocketErrorHard(error)) { + if (TcpSession::IsSocketErrorHard(*error)) { return; } assert(wrote >= 0); diff --git a/src/io/tcp_message_write.h b/src/io/tcp_message_write.h index 914d26d1678..264fdfded66 100644 --- a/src/io/tcp_message_write.h +++ b/src/io/tcp_message_write.h @@ -2,8 +2,10 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#ifndef __MESSAGE_WRITE_H__ -#define __MESSAGE_WRITE_H__ +#ifndef SRC_IO_TCP_MESSAGE_WRITE_H_ +#define SRC_IO_TCP_MESSAGE_WRITE_H_ + +#include #include #include @@ -11,11 +13,8 @@ #include #include #include -#include #include "base/util.h" -using namespace boost::system; - class TcpSession; class TcpMessageWriter { @@ -24,20 +23,21 @@ class TcpMessageWriter { explicit TcpMessageWriter(TcpSession *session); ~TcpMessageWriter(); - // return false for send - int Send(const uint8_t *msg, size_t len, error_code &ec); + // return false for send + int Send(const uint8_t *msg, size_t len, + boost::system::error_code *ec); private: friend class TcpSession; typedef boost::intrusive_ptr TcpSessionPtr; typedef std::list BufferQueue; void BufferAppend(const uint8_t *data, int len); - void DeleteBuffer(boost::asio::mutable_buffer buffer); - void HandleWriteReady(boost::system::error_code &ec); + void DeleteBuffer(boost::asio::mutable_buffer buffer); + void HandleWriteReady(boost::system::error_code *ec); BufferQueue buffer_queue_; int offset_; TcpSession *session_; }; -#endif +#endif // SRC_IO_TCP_MESSAGE_WRITE_H_ diff --git a/src/io/tcp_server.cc b/src/io/tcp_server.cc index 199cacdb92a..e02a123d6eb 100644 --- a/src/io/tcp_server.cc +++ b/src/io/tcp_server.cc @@ -2,12 +2,13 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#include "tcp_server.h" +#include "io/tcp_server.h" + +#include #include #include #include -#include #include "base/logging.h" #include "io/event_manager.h" @@ -20,8 +21,10 @@ using boost::asio::socket_base; using boost::bind; using boost::system::error_code; -using namespace boost::asio::ip; -using namespace std; +using boost::asio::ip::tcp; +using boost::asio::socket_base; +using std::ostringstream; +using std::string; TcpServer::TcpServer(EventManager *evm) : evm_(evm), socket_open_failure_(false) { @@ -248,7 +251,7 @@ bool TcpServer::HasSessionReadAvailable() const { if (accept_socket()->available(error) > 0) { return true; } - for (SessionMap::const_iterator iter = session_map_.begin(); + for (SessionMap::const_iterator iter = session_map_.begin(); iter != session_map_.end(); ++iter) { if (iter->second->socket()->available(error) > 0) { @@ -357,7 +360,7 @@ void TcpServer::AcceptHandlerInternal(TcpServerPtr server, AsyncAccept(); } -void TcpServer::AcceptHandlerComplete(TcpSessionPtr &session) { +void TcpServer::AcceptHandlerComplete(TcpSessionPtr session) { tcp::endpoint remote = session->remote_endpoint(); { tbb::mutex::scoped_lock lock(mutex_); @@ -403,7 +406,7 @@ void TcpServer::ConnectHandler(TcpServerPtr server, TcpSessionPtr session, ConnectHandlerComplete(session); } -void TcpServer::ConnectHandlerComplete(TcpSessionPtr &session) { +void TcpServer::ConnectHandlerComplete(TcpSessionPtr session) { error_code ec; Endpoint remote = session->socket()->remote_endpoint(ec); if (ec) { @@ -435,7 +438,7 @@ void TcpServer::Connect(TcpSession *session, Endpoint remote) { } int TcpServer::SetMd5SocketOption(int fd, uint32_t peer_ip, - const std::string &md5_password) { + const string &md5_password) { assert(md5_password.size() <= TCP_MD5SIG_MAXKEYLEN); if (!peer_ip) { TCP_SERVER_LOG_ERROR(this, TCP_DIR_NA, "Invalid peer IP"); @@ -470,7 +473,7 @@ int TcpServer::SetMd5SocketOption(int fd, uint32_t peer_ip, } int TcpServer::SetListenSocketMd5Option(uint32_t peer_ip, - const std::string &md5_password) { + const string &md5_password) { int retval = 0; if (acceptor_) { retval = SetMd5SocketOption(acceptor_->native_handle(), peer_ip, @@ -479,11 +482,11 @@ int TcpServer::SetListenSocketMd5Option(uint32_t peer_ip, return retval; } -void TcpServer::GetRxSocketStats(SocketIOStats &socket_stats) const { +void TcpServer::GetRxSocketStats(SocketIOStats *socket_stats) const { stats_.GetRxStats(socket_stats); } -void TcpServer::GetTxSocketStats(SocketIOStats &socket_stats) const { +void TcpServer::GetTxSocketStats(SocketIOStats *socket_stats) const { stats_.GetTxStats(socket_stats); } diff --git a/src/io/tcp_server.h b/src/io/tcp_server.h index cfdc6bd2d8f..afca524598b 100644 --- a/src/io/tcp_server.h +++ b/src/io/tcp_server.h @@ -2,16 +2,18 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#ifndef __TCPSERVER_H__ -#define __TCPSERVER_H__ +#ifndef SRC_IO_TCP_SERVER_H_ +#define SRC_IO_TCP_SERVER_H_ + +#include +#include #include #include +#include #include #include #include -#include -#include #include "base/util.h" #include "io/server_manager.h" @@ -76,8 +78,16 @@ class TcpServer { // wait until the server has deleted all sessions. void WaitForEmpty(); - void GetRxSocketStats(SocketIOStats &socket_stats) const; - void GetTxSocketStats(SocketIOStats &socket_stats) const; + void GetRxSocketStats(SocketIOStats *socket_stats) const; + void GetTxSocketStats(SocketIOStats *socket_stats) const; + + void GetRxSocketStats(SocketIOStats &socket_stats) const { + GetRxSocketStats(&socket_stats); + } + + void GetTxSocketStats(SocketIOStats &socket_stats) const { + GetTxSocketStats(&socket_stats); + } int SetMd5SocketOption(int fd, uint32_t peer_ip, const std::string &md5_password); @@ -113,8 +123,8 @@ class TcpServer { Endpoint LocalEndpoint() const; - virtual void AcceptHandlerComplete(TcpSessionPtr &session); - virtual void ConnectHandlerComplete(TcpSessionPtr &session); + virtual void AcceptHandlerComplete(TcpSessionPtr session); + virtual void ConnectHandlerComplete(TcpSessionPtr session); private: @@ -188,4 +198,4 @@ class TcpServerManager { static ServerManager impl_; }; -#endif // __TCPSERVER_H__ +#endif // SRC_IO_TCP_SERVER_H_ diff --git a/src/io/tcp_session.cc b/src/io/tcp_session.cc index 3410d69d4a8..384a6a109e0 100644 --- a/src/io/tcp_session.cc +++ b/src/io/tcp_session.cc @@ -4,6 +4,9 @@ #include "io/tcp_session.h" +#include +#include + #include #include #include @@ -31,10 +34,18 @@ using boost::scoped_array; using boost::system::error_code; using std::min; using std::ostringstream; -using std::size_t; using std::string; -using namespace boost::asio; +using boost::asio::error::eof; +using boost::asio::error::try_again; +using boost::asio::error::would_block; +using boost::asio::error::in_progress; +using boost::asio::error::interrupted; +using boost::asio::error::network_down; +using boost::asio::error::network_reset; +using boost::asio::error::network_unreachable; +using boost::asio::error::no_buffer_space; +using boost::asio::placeholders::error; int TcpSession::reader_task_id_ = -1; @@ -42,8 +53,8 @@ class TcpSession::Reader : public Task { public: typedef function ReadHandler; - Reader(TcpSessionPtr session, ReadHandler read_fn, Buffer buffer) - : Task(session->reader_task_id(), session->GetSessionInstance()), + Reader(TcpSessionPtr session, ReadHandler read_fn, Buffer buffer) + : Task(session->reader_task_id(), session->GetSessionInstance()), session_(session), read_fn_(read_fn), buffer_(buffer) { } virtual bool Run() { @@ -61,6 +72,7 @@ class TcpSession::Reader : public Task { return true; } string Description() const { return "TcpSession::Reader"; } + private: TcpSessionPtr session_; ReadHandler read_fn_; @@ -177,8 +189,8 @@ void TcpSession::DeferWriter() { server_->stats_.write_blocked++; socket()->async_write_some(null_buffers(), bind(&TcpSession::WriteReadyInternal, - TcpSessionPtr(this), - placeholders::error, UTCTimestampUsec())); + TcpSessionPtr(this), + error, UTCTimestampUsec())); } void TcpSession::AsyncReadSome() { @@ -190,14 +202,14 @@ void TcpSession::AsyncReadSome() { } size_t TcpSession::WriteSome(const uint8_t *data, size_t len, - error_code &error) { - return socket()->write_some(buffer(data, len), error); + error_code *error) { + return socket()->write_some(buffer(data, len), *error); } void TcpSession::AsyncWrite(const u_int8_t *data, size_t size) { async_write(*socket(), buffer(data, size), bind(&TcpSession::AsyncWriteHandler, TcpSessionPtr(this), - placeholders::error)); + error)); } TcpSession::Endpoint TcpSession::local_endpoint() const { @@ -205,9 +217,9 @@ TcpSession::Endpoint TcpSession::local_endpoint() const { if (!established_) return Endpoint(); - error_code err; - Endpoint local = socket()->local_endpoint(err); - if (err) { + error_code error; + Endpoint local = socket()->local_endpoint(error); + if (error) { return Endpoint(); } return local; @@ -220,10 +232,10 @@ void TcpSession::set_observer(EventObserver observer) { void TcpSession::SetName() { ostringstream out; - error_code err; + error_code error; Endpoint local; - local = socket()->local_endpoint(err); + local = socket()->local_endpoint(error); out << local.address().to_string() << ":" << local.port() << "::"; out << remote_.address().to_string() << ":" << remote_.port(); @@ -294,8 +306,8 @@ void TcpSession::CloseInternal(const error_code &ec, tbb::mutex::scoped_lock lock(mutex_); if (socket() != NULL && !closed_) { - error_code err; - socket()->close(err); + error_code error; + socket()->close(error); } closed_ = true; if (!established_) { @@ -352,7 +364,7 @@ void TcpSession::WriteReadyInternal(TcpSessionPtr session, // if (session->IsClosedLocked()) return; - session->writer_->HandleWriteReady(ec); + session->writer_->HandleWriteReady(&ec); if (session->IsSocketErrorHard(ec)) { goto session_error; } @@ -394,7 +406,7 @@ bool TcpSession::Send(const u_int8_t *data, size_t size, size_t *sent) { if (socket()->non_blocking()) { error_code error; - int len = writer_->Send(data, size, error); + int len = writer_->Send(data, size, &error); lock.release(); if (len < 0) { TCP_SESSION_LOG_ERROR(this, TCP_DIR_OUT, @@ -416,15 +428,14 @@ bool TcpSession::Send(const u_int8_t *data, size_t size, size_t *sent) { Task* TcpSession::CreateReaderTask(mutable_buffer buffer, size_t bytes_transferred) { - Buffer rdbuf(buffer_cast(buffer), bytes_transferred); Reader *task = new Reader(TcpSessionPtr(this), bind(&TcpSession::OnRead, this, _1), rdbuf); return (task); } -size_t TcpSession::ReadSome(mutable_buffer buffer, error_code &error) { - return socket()->read_some(mutable_buffers_1(buffer), error); +size_t TcpSession::ReadSome(mutable_buffer buffer, error_code *error) { + return socket()->read_some(mutable_buffers_1(buffer), *error); } void TcpSession::AsyncReadHandler(TcpSessionPtr session) { @@ -437,11 +448,11 @@ void TcpSession::AsyncReadHandler(TcpSessionPtr session) { } error_code error; - size_t bytes_transferred = session->ReadSome(buffer, error); + size_t bytes_transferred = session->ReadSome(buffer, &error); if (IsSocketErrorHard(error)) { session->ReleaseBufferLocked(buffer); - // eof is returned when the peer closed the socket, no need to log err - if (error != error::eof) { + // eof is returned when the peer closed the socket, no need to log error + if (error != eof) { TCP_SESSION_LOG_ERROR(session, TCP_DIR_IN, "Read failed due to error " << error.value() << " : " << error.message()); @@ -503,7 +514,7 @@ int TcpSession::ClearMd5SocketOption(uint32_t peer_ip) { return server()->SetMd5SocketOption(socket_->native_handle(), peer_ip, ""); } -TcpMessageReader::TcpMessageReader(TcpSession *session, +TcpMessageReader::TcpMessageReader(TcpSession *session, ReceiveCallback callback) : session_(session), callback_(callback), offset_(0), remain_(-1) { } @@ -518,8 +529,8 @@ int TcpMessageReader::AllocBufferSize(int length) { return kMaxMessageSize; } int bufsize = 1 << 8; - for (; bufsize < kMaxMessageSize && bufsize < length; - bufsize <<= 1); + for (; bufsize < kMaxMessageSize && bufsize < length; bufsize <<= 1) { + } return bufsize; } @@ -606,7 +617,7 @@ void TcpMessageReader::OnRead(Buffer buffer) { int msglength = MsgLength(queue_.front(), offset_); if (msglength < 0) { int queuelen = QueueByteLength(); - if (queuelen + (int) size < kHeaderLenSize) { + if (queuelen + static_cast(size) < kHeaderLenSize) { queue_.push_back(buffer); return; } @@ -671,21 +682,21 @@ void TcpMessageReader::OnRead(Buffer buffer) { bool TcpSession::IsSocketErrorHard(const error_code &ec) { if (!ec) return false; - if (ec == error::try_again) + if (ec == try_again) return false; - if (ec == error::would_block) + if (ec == would_block) return false; - if (ec == error::in_progress) + if (ec == in_progress) return false; - if (ec == error::interrupted) + if (ec == interrupted) return false; - if (ec == error::network_down) + if (ec == network_down) return false; - if (ec == error::network_reset) + if (ec == network_reset) return false; - if (ec == error::network_unreachable) + if (ec == network_unreachable) return false; - if (ec == error::no_buffer_space) + if (ec == no_buffer_space) return false; return true; @@ -772,9 +783,8 @@ error_code TcpSession::SetSocketOptions() { char *buffer_size_str = getenv("TCP_SESSION_SOCKET_BUFFER_SIZE"); if (!buffer_size_str) return ec; - unsigned long int sz = strtoul(buffer_size_str, NULL, 0); + uint64_t sz = strtoul(buffer_size_str, NULL, 0); if (sz) { - // // Set socket send and receive buffer size // @@ -801,11 +811,11 @@ error_code TcpSession::SetSocketOptions() { return ec; } -void TcpSession::GetRxSocketStats(SocketIOStats &socket_stats) const { +void TcpSession::GetRxSocketStats(SocketIOStats *socket_stats) const { stats_.GetRxStats(socket_stats); } -void TcpSession::GetTxSocketStats(SocketIOStats &socket_stats) const { +void TcpSession::GetTxSocketStats(SocketIOStats *socket_stats) const { stats_.GetTxStats(socket_stats); } diff --git a/src/io/tcp_session.h b/src/io/tcp_session.h index e3132db5cc7..9a83465fa24 100644 --- a/src/io/tcp_session.h +++ b/src/io/tcp_session.h @@ -2,11 +2,15 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#ifndef __TCP_SESSION_H__ -#define __TCP_SESSION_H__ +#ifndef SRC_IO_TCP_SESSION_H_ +#define SRC_IO_TCP_SESSION_H_ + +#include +#include -#include #include +#include +#include #include #include @@ -16,8 +20,6 @@ #include #include -#include -#include #ifndef _LIBCPP_VERSION #include #endif @@ -92,14 +94,14 @@ class TcpSession { virtual void ReleaseBuffer(Buffer buffer); // This function returns the instance to run SessionTask. - // Returning Task::kTaskInstanceAny would allow multiple session tasks to + // Returning Task::kTaskInstanceAny would allow multiple session tasks to // run in parallel. - // Derived class may override implementation if it expects the all the + // Derived class may override implementation if it expects the all the // Tasks of the session to run in specific instance - // Note: Two tasks of same task ID and task instance can't run + // Note: Two tasks of same task ID and task instance can't run // at in parallel - // E.g. BgpSession is created per BgpPeer and to ensure that - // there is one SessionTask per peer, PeerIndex is returned + // E.g. BgpSession is created per BgpPeer and to ensure that + // there is one SessionTask per peer, PeerIndex is returned // from this function virtual int GetSessionInstance() const; @@ -149,8 +151,17 @@ class TcpSession { } const io::SocketStats &GetSocketStats() const { return stats_; } - void GetRxSocketStats(SocketIOStats &socket_stats) const; - void GetTxSocketStats(SocketIOStats &socket_stats) const; + void GetRxSocketStats(SocketIOStats *socket_stats) const; + void GetTxSocketStats(SocketIOStats *socket_stats) const; + + void GetRxSocketStats(SocketIOStats &socket_stats) const { + GetRxSocketStats(&socket_stats); + } + + void GetTxSocketStats(SocketIOStats &socket_stats) const { + GetTxSocketStats(&socket_stats); + } + int SetMd5SocketOption(uint32_t peer_ip, const std::string &md5_password); int ClearMd5SocketOption(uint32_t peer_ip); @@ -172,9 +183,9 @@ class TcpSession { void AsyncReadSome(); virtual size_t ReadSome(boost::asio::mutable_buffer buffer, - boost::system::error_code &error); + boost::system::error_code *error); virtual std::size_t WriteSome(const uint8_t *data, std::size_t len, - boost::system::error_code &error); + boost::system::error_code *error); virtual void AsyncWrite(const u_int8_t *data, std::size_t size); virtual int reader_task_id() const { @@ -183,7 +194,8 @@ class TcpSession { EventObserver observer() { return observer_; } boost::system::error_code SetSocketKeepaliveOptions(int keepalive_time, - int keepalive_intvl, int keepalive_probes, int tcp_user_timeout_val = 0); + int keepalive_intvl, int keepalive_probes, + int tcp_user_timeout_val = 0); void CloseInternal(const boost::system::error_code &ec, bool call_observer, bool notify_server = true); @@ -300,4 +312,4 @@ class TcpMessageReader { DISALLOW_COPY_AND_ASSIGN(TcpMessageReader); }; -#endif // __TCP_SESSION_H__ +#endif // SRC_IO_TCP_SESSION_H_ diff --git a/src/io/test/tcp_io_test.cc b/src/io/test/tcp_io_test.cc index b29426d30e9..0b33a65f6e5 100644 --- a/src/io/test/tcp_io_test.cc +++ b/src/io/test/tcp_io_test.cc @@ -33,7 +33,7 @@ namespace { class EchoServer; class EchoSession : public TcpSession { - public: +public: EchoSession(EchoServer *server, Socket *socket); int GetTotal() const { return total_; } void ResetTotal() { total_ = 0; } @@ -42,7 +42,7 @@ class EchoSession : public TcpSession { } bool called; - protected: +protected: virtual ~EchoSession() { } @@ -52,7 +52,7 @@ class EchoSession : public TcpSession { TCP_UT_LOG_DEBUG("Received " << len << " bytes"); total_ += len; } - private: +private: void OnEvent(TcpSession *session, Event event) { if (event == CLOSE) { TCP_UT_LOG_DEBUG("Event Close"); @@ -74,7 +74,7 @@ class EchoSession : public TcpSession { }; class EchoServer : public TcpServer { - public: +public: explicit EchoServer(EventManager *evm) : TcpServer(evm), session_(NULL) { } ~EchoServer() { @@ -340,7 +340,7 @@ TEST_F(EchoServerTest, DeferRead) { server_->GetSession()->ResetTotal(); // Verify read statistics SocketIOStats rx_stats; - server_->GetSession()->GetRxSocketStats(rx_stats); + server_->GetSession()->GetRxSocketStats(&rx_stats); EXPECT_EQ(1, rx_stats.blocked_count); EXPECT_EQ(sizeof(msg), rx_stats.bytes); EXPECT_EQ("00:00:00", rx_stats.blocked_duration); @@ -356,7 +356,7 @@ TEST_F(EchoServerTest, DeferRead) { TASK_UTIL_ASSERT_EQ(sizeof(msg1), server_->GetSession()->GetTotal()); // Verify read statistics SocketIOStats rx_stats1; - server_->GetSession()->GetRxSocketStats(rx_stats1); + server_->GetSession()->GetRxSocketStats(&rx_stats1); EXPECT_EQ(1, rx_stats1.blocked_count); EXPECT_EQ(sizeof(msg) + sizeof(msg1), rx_stats1.bytes); EXPECT_NE("00:00:00", rx_stats1.blocked_duration); diff --git a/src/io/test/udp_io_test.cc b/src/io/test/udp_io_test.cc index 7ae7205fadf..c166164227b 100644 --- a/src/io/test/udp_io_test.cc +++ b/src/io/test/udp_io_test.cc @@ -23,14 +23,14 @@ using boost::asio::mutable_buffer; using boost::asio::ip::udp; class EchoServer: public UdpServer { - public: +public: explicit EchoServer(EventManager *evm) : UdpServer(evm), tx_count_(0), rx_count_(0) { } ~EchoServer() { } - void HandleReceive(boost::asio::const_buffer &recv_buffer, + void HandleReceive(const boost::asio::const_buffer &recv_buffer, udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error) { UDP_UT_LOG_DEBUG("EchoServer rx " << bytes_transferred << "(" << @@ -78,13 +78,13 @@ class EchoServer: public UdpServer { int GetTxBytes() { return tx_count_; } int GetRxBytes() { return rx_count_; } - private: +private: int tx_count_; int rx_count_; }; class EchoClient : public UdpServer { - public: +public: explicit EchoClient(boost::asio::io_service *io_service, int buffer_size = kDefaultBufferSize) : UdpServer(io_service, buffer_size), @@ -116,7 +116,7 @@ class EchoClient : public UdpServer { error << ")\n"); } - void HandleReceive(boost::asio::const_buffer &recv_buffer, + void HandleReceive(const boost::asio::const_buffer &recv_buffer, udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error) { rx_count_ += bytes_transferred; @@ -133,7 +133,7 @@ class EchoClient : public UdpServer { int GetRxBytes() { return rx_count_; } bool client_rx_done() { return client_rx_done_; } - private: +private: int tx_count_; int rx_count_; std::string snd_buf_; @@ -141,7 +141,7 @@ class EchoClient : public UdpServer { }; class EchoServerTest : public ::testing::Test { - protected: +protected: EchoServerTest() { } virtual void SetUp() { @@ -177,7 +177,7 @@ class EchoServerTest : public ::testing::Test { class EchoServerBranchTest : public ::testing::Test { - protected: +protected: EchoServerBranchTest() : _test_run(false) {} virtual void SetUp() { @@ -205,7 +205,7 @@ class EchoServerBranchTest : public ::testing::Test { UDP_UT_LOG_DEBUG("UDP branch test Shutdown: " << _test_run); } - private: +private: bool _test_run; }; @@ -238,7 +238,7 @@ TEST_F(EchoServerBranchTest, Basic) { } class UdpRecvServerTest: public UdpServer { - public: +public: explicit UdpRecvServerTest(EventManager *evm) : UdpServer(evm), recv_msg_(0) { @@ -246,7 +246,7 @@ class UdpRecvServerTest: public UdpServer { ~UdpRecvServerTest() { } - void OnRead(boost::asio::const_buffer &recv_buffer, + void OnRead(const boost::asio::const_buffer &recv_buffer, const udp::endpoint &remote_endpoint) { UDP_UT_LOG_DEBUG("Received " << boost::asio::buffer_size(recv_buffer) << " bytes from " << remote_endpoint); @@ -258,12 +258,12 @@ class UdpRecvServerTest: public UdpServer { return recv_msg_; } - private: +private: int recv_msg_; }; class UdpLocalClient { - public: +public: explicit UdpLocalClient(int port) : dst_port_(port), socket_(-1) { @@ -298,13 +298,13 @@ class UdpLocalClient { int res = shutdown(socket_, SHUT_RDWR); assert(res == 0); } - private: +private: int dst_port_; int socket_; }; class UdpRecvTest : public ::testing::Test { - protected: +protected: UdpRecvTest() : evm_(new EventManager()) { } @@ -348,7 +348,7 @@ TEST_F(UdpRecvTest, Basic) { TASK_UTIL_EXPECT_EQ((int) 2 * sizeof(msg), len); TASK_UTIL_EXPECT_EQ(2, server_->GetNumRecvMsg()); SocketIOStats rx_stats; - server_->GetRxSocketStats(rx_stats); + server_->GetRxSocketStats(&rx_stats); EXPECT_EQ(2, rx_stats.calls); EXPECT_EQ(len, rx_stats.bytes); client.Close(); diff --git a/src/io/test/usock_io_test.cc b/src/io/test/usock_io_test.cc index da8be609cb4..c707471f771 100644 --- a/src/io/test/usock_io_test.cc +++ b/src/io/test/usock_io_test.cc @@ -13,7 +13,7 @@ namespace { class UsockServer: public UnixDomainSocketServer { public: - UsockServer(boost::asio::io_service & io_service, const char *path) + UsockServer(boost::asio::io_service *io_service, const char *path) : UnixDomainSocketServer(io_service, path) { set_observer(boost::bind(&UsockServer::EventHandler, this, _1, _2, _3)); } @@ -32,7 +32,7 @@ class UsockServer: public UnixDomainSocketServer { }; class UsockClient { - public: +public: explicit UsockClient(const std::string &path) : sock_path_(path), socket_(-1) { @@ -69,20 +69,20 @@ class UsockClient { assert(res == 0); } - private: +private: std::string sock_path_; int socket_; }; class UsockTest : public ::testing::Test { - protected: +protected: UsockTest() : evm_(new EventManager()) { } virtual void SetUp() { snprintf(socket_path_, 512, "/tmp/contrail-iotest-%u.sock", getpid()); std::remove(socket_path_); - server_.reset(new UsockServer(*evm_->io_service(), socket_path_)); + server_.reset(new UsockServer(evm_->io_service(), socket_path_)); thread_.reset(new ServerThread(evm_.get())); } diff --git a/src/io/udp_server.cc b/src/io/udp_server.cc index be22578b791..747adc04434 100644 --- a/src/io/udp_server.cc +++ b/src/io/udp_server.cc @@ -2,11 +2,13 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ +#include "io/udp_server.h" + #include -#include -#include -#include -#include + +#include "base/logging.h" +#include "io/io_log.h" +#include "io/io_utils.h" using boost::asio::buffer_cast; using boost::asio::mutable_buffer; @@ -19,7 +21,7 @@ int UdpServer::reader_task_id_ = -1; class UdpServer::Reader : public Task { public: Reader(UdpServerPtr server, const udp::endpoint &remote_endpoint, - const_buffer &buffer) + const const_buffer &buffer) : Task(server->reader_task_id(), server->reader_task_instance(remote_endpoint)), server_(server), @@ -163,7 +165,7 @@ mutable_buffer UdpServer::AllocateBuffer() { return AllocateBuffer(buffer_size_); } -void UdpServer::DeallocateBuffer(const_buffer &buffer) { +void UdpServer::DeallocateBuffer(const const_buffer &buffer) { const u_int8_t *p = buffer_cast(buffer); { tbb::mutex::scoped_lock lock(mutex_); @@ -191,7 +193,7 @@ void UdpServer::StartSend(udp::endpoint ep, std::size_t bytes_to_send, } } -void UdpServer::HandleSendInternal(const_buffer send_buffer, +void UdpServer::HandleSendInternal(const const_buffer send_buffer, udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error) { if (state_ != OK) { @@ -257,7 +259,7 @@ void UdpServer::HandleReceiveInternal(const_buffer recv_buffer, StartReceive(); } -void UdpServer::HandleReceive(const_buffer &recv_buffer, +void UdpServer::HandleReceive(const const_buffer &recv_buffer, udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error) { const_buffer rdbuf(buffer_cast(recv_buffer), @@ -269,7 +271,7 @@ void UdpServer::HandleReceive(const_buffer &recv_buffer, scheduler->Enqueue(task); } -void UdpServer::OnRead(const_buffer &recv_buffer, +void UdpServer::OnRead(const const_buffer &recv_buffer, const udp::endpoint &remote_endpoint) { UDP_SERVER_LOG_ERROR(this, UDP_DIR_IN, "Receive UDP: " << "Default implementation of OnRead does NOT process received message"); @@ -302,11 +304,11 @@ int UdpServer::GetLocalEndpointPort() { return ep.port(); } -void UdpServer::GetRxSocketStats(SocketIOStats &socket_stats) const { +void UdpServer::GetRxSocketStats(SocketIOStats *socket_stats) const { stats_.GetRxStats(socket_stats); } -void UdpServer::GetTxSocketStats(SocketIOStats &socket_stats) const { +void UdpServer::GetTxSocketStats(SocketIOStats *socket_stats) const { stats_.GetTxStats(socket_stats); } diff --git a/src/io/udp_server.h b/src/io/udp_server.h index dd23801d234..a60b4300c79 100644 --- a/src/io/udp_server.h +++ b/src/io/udp_server.h @@ -2,8 +2,8 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#ifndef IO_UDP_SERVER_H_ -#define IO_UDP_SERVER_H_ +#ifndef SRC_IO_UDP_SERVER_H_ +#define SRC_IO_UDP_SERVER_H_ #include #include @@ -16,7 +16,7 @@ class SocketIOStats; class UdpServer { - public: +public: enum ServerState { OK = 42, Uninitialized, @@ -48,22 +48,22 @@ class UdpServer { // buffers boost::asio::mutable_buffer AllocateBuffer(); boost::asio::mutable_buffer AllocateBuffer(std::size_t s); - void DeallocateBuffer(boost::asio::const_buffer &buffer); + void DeallocateBuffer(const boost::asio::const_buffer &buffer); // statistics const io::SocketStats &GetSocketStats() const { return stats_; } - void GetRxSocketStats(SocketIOStats &socket_stats) const; - void GetTxSocketStats(SocketIOStats &socket_stats) const; + void GetRxSocketStats(SocketIOStats *socket_stats) const; + void GetTxSocketStats(SocketIOStats *socket_stats) const; - protected: +protected: EventManager *event_manager() { return evm_; } virtual bool DisableSandeshLogMessages() { return false; } virtual std::string ToString() { return name_; } virtual void HandleReceive( - boost::asio::const_buffer &recv_buffer, + const boost::asio::const_buffer &recv_buffer, boost::asio::ip::udp::endpoint remote_endpoint, std::size_t bytes_transferred, const boost::system::error_code& error); - virtual void OnRead(boost::asio::const_buffer &recv_buffer, + virtual void OnRead(const boost::asio::const_buffer &recv_buffer, const boost::asio::ip::udp::endpoint &remote_endpoint); virtual int reader_task_id() const { return reader_task_id_; @@ -84,7 +84,7 @@ class UdpServer { std::size_t bytes_transferred, const boost::system::error_code& error); - private: +private: class Reader; friend void intrusive_ptr_add_ref(UdpServer *server); friend void intrusive_ptr_release(UdpServer *server); @@ -135,4 +135,4 @@ class UdpServerManager { static ServerManager impl_; }; -#endif // IO_UDP_SERVER_H_ +#endif // SRC_IO_UDP_SERVER_H_ diff --git a/src/io/usock_server.cc b/src/io/usock_server.cc index 12e3468a30e..d30069c6bbc 100644 --- a/src/io/usock_server.cc +++ b/src/io/usock_server.cc @@ -1,3 +1,7 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + /* * The primary method implemented here is Send(), to transmit a * message over the Unix socket. It uses boost::asio::async_write to @@ -6,14 +10,13 @@ * buffers are tail-queued. Upon write_complete callback, the next * message from the front of the queue is sent. */ -#include "usock_server.h" +#include "io/usock_server.h" using boost::asio::buffer_cast; using boost::asio::buffer; using boost::asio::mutable_buffer; -UnixDomainSocketSession::~UnixDomainSocketSession() -{ +UnixDomainSocketSession::~UnixDomainSocketSession() { if (observer_) { observer_(this, CLOSE); } @@ -26,9 +29,7 @@ UnixDomainSocketSession::~UnixDomainSocketSession() buffer_queue_.clear(); } -void -UnixDomainSocketSession::Start() -{ +void UnixDomainSocketSession::Start() { if (observer_) { observer_(this, READY); } @@ -41,9 +42,7 @@ UnixDomainSocketSession::Start() bytes_transferred)); } -void -UnixDomainSocketSession::Send(const uint8_t * data, int data_len) -{ +void UnixDomainSocketSession::Send(const uint8_t * data, int data_len) { if (!data || !data_len) { return; } @@ -54,9 +53,7 @@ UnixDomainSocketSession::Send(const uint8_t * data, int data_len) } } -void -UnixDomainSocketSession::WriteToSocket() -{ +void UnixDomainSocketSession::WriteToSocket() { if (buffer_queue_.empty()) { return; } @@ -70,9 +67,7 @@ UnixDomainSocketSession::WriteToSocket() boost::asio::placeholders::error)); } -void -UnixDomainSocketSession::AppendBuffer(const uint8_t *src, int bytes) -{ +void UnixDomainSocketSession::AppendBuffer(const uint8_t *src, int bytes) { u_int8_t *data = new u_int8_t[bytes]; memcpy(data, src, bytes); boost::asio::mutable_buffer buffer = @@ -80,18 +75,14 @@ UnixDomainSocketSession::AppendBuffer(const uint8_t *src, int bytes) buffer_queue_.push_back(buffer); } -void -UnixDomainSocketSession::DeleteBuffer(boost::asio::mutable_buffer buffer) -{ +void UnixDomainSocketSession::DeleteBuffer(boost::asio::mutable_buffer buffer) { const uint8_t *data = buffer_cast (buffer); delete []data; return; } -void -UnixDomainSocketSession::HandleRead(const boost::system::error_code &error, - size_t bytes_transferred) -{ +void UnixDomainSocketSession::HandleRead(const boost::system::error_code &error, + size_t bytes_transferred) { if (error) { return; } @@ -100,9 +91,8 @@ UnixDomainSocketSession::HandleRead(const boost::system::error_code &error, } } -void -UnixDomainSocketSession::HandleWrite(const boost::system::error_code &error) -{ +void UnixDomainSocketSession::HandleWrite( + const boost::system::error_code &error) { /* * async_write() is atomic in that it returns success once the entire message * is sent. If there is an error, it's okay to return from here so that the @@ -134,12 +124,11 @@ UnixDomainSocketSession::HandleWrite(const boost::system::error_code &error) bytes_transferred)); } -UnixDomainSocketServer::UnixDomainSocketServer(boost::asio::io_service &io, - const std::string &file) +UnixDomainSocketServer::UnixDomainSocketServer( + boost::asio::io_service *io, const std::string &file) : io_service_(io), - acceptor_(io, boost::asio::local::stream_protocol::endpoint(file)), - session_idspace_(0) -{ + acceptor_(*io, boost::asio::local::stream_protocol::endpoint(file)), + session_idspace_(0) { SessionPtr new_session(new UnixDomainSocketSession(io_service_)); acceptor_.async_accept(new_session->socket(), boost::bind(&UnixDomainSocketServer:: @@ -149,8 +138,7 @@ UnixDomainSocketServer::UnixDomainSocketServer(boost::asio::io_service &io, void UnixDomainSocketServer::HandleAccept(SessionPtr session, - const boost::system::error_code &error) -{ + const boost::system::error_code &error) { UnixDomainSocketSession *socket_session = session.get(); if (error) { diff --git a/src/io/usock_server.h b/src/io/usock_server.h index 65b7c9ae8b1..c93924ded6a 100644 --- a/src/io/usock_server.h +++ b/src/io/usock_server.h @@ -1,12 +1,17 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + /* * Implement a UNIX domain socket interface using boost::asio. */ -#ifndef _IO_USOCK_SERVER_H_ -#define _IO_USOCK_SERVER_H_ +#ifndef SRC_IO_USOCK_SERVER_H_ +#define SRC_IO_USOCK_SERVER_H_ #include #include #include +#include #include #include #include @@ -17,15 +22,13 @@ #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) class UnixDomainSocketSession : -public boost::enable_shared_from_this -{ - public: +public boost::enable_shared_from_this { +public: static const int kPDULen = 4096; static const int kPDUHeaderLen = 4; static const int kPDUDataLen = 4092; - enum Event - { + enum Event { EVENT_NONE, READY, CLOSE @@ -34,40 +37,23 @@ public boost::enable_shared_from_this typedef boost::function EventObserver; - UnixDomainSocketSession (boost::asio::io_service &io_service) - : socket_(io_service), session_id_(0) - { + explicit UnixDomainSocketSession(boost::asio::io_service *io_service) + : socket_(*io_service), session_id_(0) { } ~UnixDomainSocketSession(); - boost::asio::local::stream_protocol::socket &socket() - { + boost::asio::local::stream_protocol::socket &socket() { return socket_; } - void - set_observer(EventObserver observer) - { - observer_ = observer; - } - - uint64_t - session_id() - { - return session_id_; - } - - void - set_session_id(uint64_t id) - { - session_id_ = id; - } - + void set_observer(EventObserver observer) { observer_ = observer; } + uint64_t session_id() { return session_id_; } + void set_session_id(uint64_t id) { session_id_ = id; } void Start(); void Send(const uint8_t * data, int data_len); - private: +private: typedef std::list BufferQueue; void WriteToSocket(); @@ -85,12 +71,9 @@ public boost::enable_shared_from_this typedef boost::shared_ptr SessionPtr; -class UnixDomainSocketServer -{ - public: - - enum Event - { +class UnixDomainSocketServer { +public: + enum Event { EVENT_NONE, NEW_SESSION, DELETE_SESSION @@ -100,26 +83,23 @@ class UnixDomainSocketServer UnixDomainSocketSession *, Event) > EventObserver; - UnixDomainSocketServer(boost::asio::io_service &io_service, + UnixDomainSocketServer(boost::asio::io_service *io_service, const std::string &file); void HandleAccept(SessionPtr new_session, const boost::system::error_code &error); - void set_observer(EventObserver observer) - { - observer_ = observer; - } + void set_observer(EventObserver observer) { observer_ = observer; } - private: - boost::asio::io_service &io_service_; +private: + boost::asio::io_service *io_service_; EventObserver observer_; boost::asio::local::stream_protocol::acceptor acceptor_; uint64_t session_idspace_; }; -#else // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) +#else // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) #error Local sockets not available on this platform. -#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) +#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) -#endif +#endif // SRC_IO_USOCK_SERVER_H_ diff --git a/src/vnsw/agent/nexthop_server/nexthop_server.cc b/src/vnsw/agent/nexthop_server/nexthop_server.cc index 368d71a2d56..13e60060873 100644 --- a/src/vnsw/agent/nexthop_server/nexthop_server.cc +++ b/src/vnsw/agent/nexthop_server/nexthop_server.cc @@ -20,7 +20,7 @@ NexthopDBServer::NexthopDBServer(boost::asio::io_service &io, : io_service_(io), endpoint_path_(path), nexthop_table_(), client_table_() { std::remove(endpoint_path_.c_str()); - io_server_.reset(new UnixDomainSocketServer(io_service_, endpoint_path_)); + io_server_.reset(new UnixDomainSocketServer(&io_service_, endpoint_path_)); io_server_->set_observer(boost::bind(&NexthopDBServer::EventHandler, this, _1, _2, _3)); } diff --git a/src/xmpp/xmpp_server.cc b/src/xmpp/xmpp_server.cc index 6af6c67b550..a4ad851ba89 100644 --- a/src/xmpp/xmpp_server.cc +++ b/src/xmpp/xmpp_server.cc @@ -611,9 +611,9 @@ void XmppServer::FillShowConnections( void XmppServer::FillShowServer(ShowXmppServerResp *resp) const { SocketIOStats peer_socket_stats; - GetRxSocketStats(peer_socket_stats); + GetRxSocketStats(&peer_socket_stats); resp->set_rx_socket_stats(peer_socket_stats); - GetTxSocketStats(peer_socket_stats); + GetTxSocketStats(&peer_socket_stats); resp->set_tx_socket_stats(peer_socket_stats); resp->set_current_connections(connection_map_.size()); resp->set_max_connections(max_connections_);