Changeset 14 in libcf++


Ignore:
Timestamp:
06/13/15 18:44:16 (9 years ago)
Author:
cheese
Message:

#1 interface for connection with address/port

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf/network.h

    r11 r14  
    101101
    102102            /**
    103              * connect to address:port
     103             * connect to host
    104104             * @param peer peer host
    105105             * @param timeout timeout
     
    107107             */
    108108            cf::void_t connect(const host & peer,
     109                               const cf::int32_t timeout = 0)
     110                throw (cf::exception);
     111
     112            /**
     113             * connect to address:port
     114             * @param address address
     115             * @param port port
     116             * @param timeout timeout
     117             * @throw cf::exception
     118             */
     119            cf::void_t connect(const std::string & address,
     120                               const cf::uint16_t port,
    109121                               const cf::int32_t timeout = 0)
    110122                throw (cf::exception);
  • trunk/src/network.cpp

    r13 r14  
    155155cf::bool_t cf::network::host::empty() const
    156156{
    157     return (address().empty() || port() <= 0) ? true : false;
     157    return (address().empty() || port() == 0) ? true : false;
    158158}
    159159
     
    209209    throw (cf::exception)
    210210{
    211     if (peer.empty())
    212         THROW_EXCEPTION("invalid host info");
    213 
     211    connect(peer.address(), peer.port(), timeout);
     212}
     213
     214cf::void_t cf::network::tcp::connect(const std::string & address,
     215                                     const cf::uint16_t port,
     216                                     const cf::int32_t timeout)
     217    throw (cf::exception)
     218{
    214219    cf::int32_t result = 0;
    215220    cf::int32_t retval = 0;
     
    218223    struct hostent * hostEnt;
    219224
    220     const cf::char_t * host = peer.address().c_str();
    221     cf::uint16_t port = peer.port();
     225    const cf::char_t * host = address.c_str();
    222226
    223227    /* 1. set data */
     
    353357    cf::int32_t size = static_cast<cf::int32_t>(in.size());
    354358
    355     cf::int32_t sentSize = (cf::int32_t)::send (mSocket, buf, size, 0);
     359    cf::int32_t sentSize = (cf::int32_t)::send(mSocket, buf, size, 0);
    356360    if (sentSize != size)
    357361        THROW_EXCEPTION("cannot send (" << cf::exception::systemCode() << ")");
Note: See TracChangeset for help on using the changeset viewer.