Changeset 5 in libcf++ for trunk/include/cf/network.h


Ignore:
Timestamp:
03/21/15 19:54:07 (9 years ago)
Author:
cheese
Message:

#1 get address from local socket or peer socket

File:
1 edited

Legend:

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

    r4 r5  
    2020    {
    2121        /**
     22         * network host
     23         */
     24        class host
     25        {
     26        private:
     27            std::string mAddress;
     28            cf::uint16_t mPort;
     29
     30        public:
     31            /**
     32             * constructor
     33             * @param address host address
     34             * @param port port number
     35             */
     36            host(const std::string & address = "",
     37                 const cf::uint16_t port = 0);
     38
     39            /**
     40             * get host address
     41             * @return host address
     42             */
     43            std::string address() const;
     44
     45            /**
     46             * get port number
     47             * @return port number
     48             */
     49            cf::uint16_t port() const;
     50
     51            /**
     52             * is empty ?
     53             * @return true; false
     54             */
     55            cf::bool_t empty() const;
     56        };
     57
     58        /**
    2259         * TCP Socket
    2360         */
     
    2764            cf::socket_t mSocket;
    2865            cf::int32_t mTimeout;
    29             std::string mHost;
    30             cf::uint16_t mPort;
    3166
    3267            /**
     
    3570             * @throw cf::exception
    3671             */
    37             cf::void_t receive(bin & out)
     72            cf::void_t receive(bin & out) const
    3873                throw (cf::exception);
    3974
     
    5893
    5994            /**
    60              * connect to host:port
    61              * @param host host
    62              * @param port port
     95             * connect to address:port
     96             * @param peer peer host
    6397             * @param timeout timeout
    6498             * @throw cf::exception
    6599             */
    66             cf::void_t connect(const cf::char_t * host,
    67                                const cf::uint16_t port,
     100            cf::void_t connect(const host & peer,
    68101                               const cf::int32_t timeout = 0)
    69102                throw (cf::exception);
     
    76109             */
    77110            cf::void_t listen(const cf::uint16_t port,
    78                               const cf::int32_t backlog = 5)
     111                              const cf::int32_t backlog = 5) const
    79112                throw (cf::exception);
    80113
     
    84117             * @throw cf::exception
    85118             */
    86             tcp accept()
     119            tcp accept() const
    87120                throw (cf::exception);
    88121
     
    108141             * @throw cf::exception
    109142             */
    110             cf::void_t send(const bin & in)
     143            cf::void_t send(const bin & in) const
    111144                throw (cf::exception);
    112145
     
    117150             * @throw cf::exception
    118151             */
    119             bin receive(const cf::int32_t size)
     152            bin receive(const cf::int32_t size) const
    120153                throw (cf::exception);
    121154
     
    125158             * @throw cf::exception
    126159             */
    127             bin receive()
     160            bin receive() const
    128161                throw (cf::exception);
    129162
     
    133166            cf::void_t getOption(const cf::int32_t optname,
    134167                                 cf::void_t * optval,
    135                                  cf::int32_t * optlen)
     168                                 cf::int32_t * optlen) const
    136169                throw (cf::exception);
    137170
     
    141174            cf::void_t setOption(const cf::int32_t optname,
    142175                                 const cf::void_t * optval,
    143                                  const cf::int32_t optlen)
    144                 throw (cf::exception);
    145 
    146             /**
    147              * set non-blocking
    148              * @param flag true; false
    149              * @see setTimeout
    150              */
    151             cf::void_t setNonBlocking(const cf::bool_t flag);
     176                                 const cf::int32_t optlen) const
     177                throw (cf::exception);
    152178
    153179            /**
     
    157183             */
    158184            cf::void_t setTimeout(const cf::int32_t seconds);
     185
     186            /**
     187             * get local host
     188             * @return local host
     189             * @see cf::network::host
     190             */
     191            host local() const
     192                throw (cf::exception);
     193
     194            /**
     195             * get peer host
     196             * @return peer host
     197             * @see cf::network::host
     198             */
     199            host peer() const
     200                throw (cf::exception);
    159201        };
    160202
Note: See TracChangeset for help on using the changeset viewer.