Ticket #183: session-defarg.diff

File session-defarg.diff, 3.6 KB (added by jinmei, 10 years ago)
  • session.cc

     
    5959public:
    6060    SessionImpl() : sequence_(-1) { queue_ = Element::createFromString("[]"); }
    6161    virtual ~SessionImpl() {}
    62     virtual void establish(const char* socket_file = NULL) = 0;
     62    virtual void establish(const char& socket_file) = 0;
    6363    virtual int getSocket() = 0;
    6464    virtual void disconnect() = 0;
    6565    virtual void writeData(const void* data, size_t datalen) = 0;
     
    7878    ASIOSession(io_service& io_service) :
    7979        io_service_(io_service), socket_(io_service_), data_length_(0)
    8080    {}
    81     virtual void establish(const char* socket_file = NULL);
     81    virtual void establish(const char& socket_file);
    8282    virtual void disconnect();
    8383    virtual int getSocket() { return (socket_.native()); }
    8484    virtual void writeData(const void* data, size_t datalen);
     
    100100
    101101
    102102void
    103 ASIOSession::establish(const char* socket_file) {
    104     if (!socket_file) {
    105         socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
    106     }
    107     if (!socket_file) {
    108         socket_file = BIND10_MSGQ_SOCKET_FILE;
    109     }
     103ASIOSession::establish(const char& socket_file) {
    110104    try {
    111         socket_.connect(boost::asio::local::stream_protocol::endpoint(socket_file), error_);
     105        socket_.connect(boost::asio::local::stream_protocol::endpoint(&socket_file), error_);
    112106    } catch (boost::system::system_error se) {
    113107        isc_throw(SessionError, se.what());
    114108    }
     
    192186    SocketSession() : sock_(-1) {}
    193187    virtual ~SocketSession() { disconnect(); }
    194188    virtual int getSocket() { return (sock_); }
    195     void establish(const char* socket_file = NULL);
     189    void establish(const char& socket_file);
    196190    virtual void disconnect()
    197191    {
    198192        if (sock_ >= 0) {
     
    227221}
    228222
    229223void
    230 SocketSession::establish(const char* socket_file) {
     224SocketSession::establish(const char& socket_file) {
    231225    int s;
    232226    struct sockaddr_un sun;
    233227
     
    236230        isc_throw(SessionError, "socket() failed");
    237231    }
    238232
    239     if (!socket_file) {
    240         socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
    241     }
    242     if (!socket_file) {
    243         socket_file = BIND10_MSGQ_SOCKET_FILE;
    244     }
    245 
    246     if (strlen(socket_file) >= sizeof(sun.sun_path)) {
     233    if (strlen(&socket_file) >= sizeof(sun.sun_path)) {
    247234        isc_throw(SessionError, "Unable to connect to message queue; socket file path too long");
    248235    }
    249236
    250237    sun.sun_family = AF_UNIX;
    251     strncpy(sun.sun_path, socket_file, sizeof(sun.sun_path) - 1);
     238    strncpy(sun.sun_path, &socket_file, sizeof(sun.sun_path) - 1);
    252239
    253240    if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
    254241        close(s);
     
    312299
    313300void
    314301Session::establish(const char* socket_file) {
    315     impl_->establish(socket_file);
     302    if (socket_file != NULL) {
     303        socket_file = getenv("BIND10_MSGQ_SOCKET_FILE");
     304    }
     305    if (socket_file != NULL) {
     306        socket_file = BIND10_MSGQ_SOCKET_FILE;
     307    }
    316308
     309    impl_->establish(*socket_file);
     310
    317311    // once established, encapsulate the implementation object so that we
    318312    // can safely release the internal resource when exception happens
    319313    // below.
  • session_unittests.cc

     
    1717#include "config.h"
    1818#include <gtest/gtest.h>
    1919#include <session.h>
     20#ifdef HAVE_BOOST_SYSTEM
    2021#include <boost/asio.hpp>
     22#endif
    2123#include <exceptions/exceptions.h>
    2224
    2325using namespace isc::cc;