Changeset 7 in libcf++


Ignore:
Timestamp:
03/29/15 16:30:07 (9 years ago)
Author:
cheese
Message:

#1 fix and add interfaces

Location:
trunk
Files:
11 edited

Legend:

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

    r4 r7  
    2929         * shallow-copy constructor(default constructor)
    3030         * @param in binary
    31          * @param size binary size
     31         * @param length binary size
    3232         */
    3333        bin(const cf::uint8_t * in = NULL,
    34             const cf::size_t size = 0);
     34            const cf::size_t length = 0);
    3535
    3636        /**
     
    7878         * set
    7979         * @param in data
    80          * @param size size
     80         * @param length size
    8181         */
    8282        cf::void_t set(const cf::uint8_t * in,
    83                        const cf::size_t size);
     83                       const cf::size_t length);
    8484
    8585        /**
     
    110110         * @return on success, position; otherwise, (cf::size_t)-1
    111111         * @param in binary
    112          * @param size binary size
     112         * @param length binary size
    113113         */
    114114        cf::size_t find(const cf::uint8_t * in,
    115                         const cf::size_t size) const;
     115                        const cf::size_t length) const;
    116116
    117117        /**
  • trunk/include/cf/exception.h

    r4 r7  
    6565         * destructor derived from std::exception::~exception()
    6666         */
    67         ~exception()
     67        virtual ~exception()
    6868            throw ();
    6969
  • trunk/include/cf/file.h

    r4 r7  
    7676         * destructor
    7777         */
    78         ~file();
     78        virtual ~file();
    7979
    8080        /**
  • trunk/include/cf/logger.h

    r4 r7  
    5858         * destructor
    5959         */
    60         ~logger();
     60        virtual ~logger();
    6161
    6262        /**
     
    114114            DAILY       = 0x00000010,   /**< daily rotation */
    115115            SIZE        = 0x00000020,   /**< size rotation */
    116             SECURE      = 0x00000100    /**< encrypt message */
     116            PID         = 0x00000100    /**< process-id in log file name */
    117117        };
    118118
  • trunk/include/cf/memory.h

    r4 r7  
    3232         * destructor. free memory
    3333         */
    34         ~memory();
     34        virtual ~memory();
    3535
    3636        /**
  • trunk/include/cf/network.h

    r5 r7  
    1212#include <string>
    1313
     14#define UNUSED_SOCKET   -1
     15
    1416namespace cf
    1517{
     
    7981             * @throw cf::exception
    8082             */
    81             tcp(const cf::socket_t attachedSocket = -1)
     83            tcp(const cf::socket_t attachedSocket = UNUSED_SOCKET)
    8284                throw (cf::exception);
    8385
     
    8587             * destructor
    8688             */
    87             ~tcp();
     89            virtual ~tcp();
     90
     91            /**
     92             * get socket descriptor
     93             * @return socket descriptor
     94             */
     95            cf::socket_t descriptor() const;
    8896
    8997            /**
     
    178186
    179187            /**
     188             * set non-blocking
     189             * @param flag true; false
     190             */
     191            cf::void_t setNonBlocking(const cf::bool_t flag);
     192
     193            /**
    180194             * set timeout
    181195             * @param seconds timeout seconds
     
    215229                throw (cf::exception);
    216230        };
     231
     232        /**
     233         * byteOrder
     234         */
     235        class byteOrder
     236        {
     237        public:
     238            /**
     239             * host to network long
     240             * @return long for network
     241             * @param long for host
     242             */
     243            static cf::uint32_t htonl(cf::uint32_t in);
     244
     245            /**
     246             * host to network short
     247             * @return short for network
     248             * @param short for host
     249             */
     250            static cf::uint16_t htons(cf::uint16_t in);
     251
     252            /**
     253             * network to host long
     254             * @return long for host
     255             * @param long for network
     256             */
     257            static cf::uint32_t ntohl(cf::uint32_t in);
     258
     259            /**
     260             * network to host short
     261             * @return short for host
     262             * @param short for network
     263             */
     264            static cf::uint16_t ntohs(cf::uint16_t in);
     265        };
    217266    }
    218267}
  • trunk/include/cf/task.h

    r4 r7  
    6363             * destructor
    6464             */
    65             ~mutex();
     65            virtual ~mutex();
    6666
    6767            /**
     
    113113             * destructor for unlocking
    114114             */
    115             ~scopedLock();
     115            virtual ~scopedLock();
    116116
    117117            /**
     
    155155             * destructor
    156156             */
    157             ~thread();
     157            virtual ~thread();
    158158
    159159            /**
  • trunk/src/bin.cpp

    r4 r7  
    1010
    1111cf::bin::bin(const cf::uint8_t * in,
    12              const cf::size_t size)
     12             const cf::size_t length)
    1313{
    14     set(in, size);
     14    set(in, length);
    1515}
    1616
     
    5555
    5656cf::void_t cf::bin::set(const cf::uint8_t * in,
    57                         const cf::size_t size)
     57                        const cf::size_t length)
    5858{
    5959    if (!in)
    6060        return;
    6161
    62     resize(size);
    63     memcpy(buffer(), in, size);
     62    resize(length);
     63    memcpy(buffer(), in, length);
    6464}
    6565
     
    123123
    124124cf::size_t cf::bin::find(const cf::uint8_t * in,
    125                          const cf::size_t size) const
     125                         const cf::size_t length) const
    126126{
    127     cf::size_t limit = this->size() - size;
     127    cf::size_t limit = size() - length;
    128128
    129129    if (limit < 0 || !in)
    130130        return -1;
    131131
    132     for (cf::size_t iter = 0, iterIn = 0 ; iter <= limit ; iter++)
     132    for (cf::size_t iter = 0 ; iter <= limit ; iter++)
    133133    {
    134         for (iterIn = 0 ; iterIn < size ; iterIn++)
    135         {
    136             if (*((buffer() + iter) + iterIn) != *(in + iterIn))
    137                 break;
    138         }
    139 
    140         if (iterIn == size)
     134        if (!memcmp(buffer() + iter, in, length))
    141135            return iter;
    142136    }
  • trunk/src/codec.cpp

    r4 r7  
    2121    if (in.empty())
    2222        THROW_EXCEPTION("input is empty");
     23
    2324    try
    2425    {
  • trunk/src/logger.cpp

    r4 r7  
    4949        }
    5050
    51         filepath += STR("." << cf::task::process::id());
     51        if (option & cf::logger::PID)
     52            filepath += STR("." << cf::task::process::id());
    5253
    5354        /* FORCED : append file-extension */
  • trunk/src/network.cpp

    r6 r7  
    3939#endif
    4040
    41 #define UNUSED_SOCKET   -1
    42 
    4341/*--------------------------------------------------------------*/
    4442/**
     
    6260}
    6361
    64 static cf::void_t setNonBlocking(const cf::socket_t sock,
    65                                  const cf::bool_t flag)
    66 {
    67 #ifdef _ON_WINDOWS
    68     cf::ulong_t mode = flag ? 1 : 0;
    69     ioctlsocket(sock, FIONBIO, &mode);
    70 #else
    71     cf::int32_t mode = fcntl(sock, F_GETFL, 0);
    72 
    73     if (flag)   mode |=  O_NONBLOCK;
    74     else        mode &= ~O_NONBLOCK;
    75 
    76     fcntl(sock, F_SETFL, mode);
    77 #endif
    78 }
    79 
    8062static cf::void_t waitForTimeout(const cf::socket_t sock,
    8163                                 const cf::int32_t timeout,
     
    206188{
    207189    close();
     190}
     191
     192cf::socket_t cf::network::tcp::descriptor() const
     193{
     194    return mSocket;
    208195}
    209196
     
    348335        THROW_EXCEPTION("has invalid socket");
    349336
    350     close();
    351 
    352337    mSocket = sock;
    353338}
     
    477462}
    478463
     464cf::void_t cf::network::tcp::setNonBlocking(const cf::bool_t flag)
     465{
     466#ifdef _ON_WINDOWS
     467    cf::ulong_t mode = flag ? 1 : 0;
     468    ioctlsocket(mSocket, FIONBIO, &mode);
     469#else
     470    cf::int32_t mode = fcntl(mSocket, F_GETFL, 0);
     471
     472    if (flag)   mode |=  O_NONBLOCK;
     473    else        mode &= ~O_NONBLOCK;
     474
     475    fcntl(mSocket, F_SETFL, mode);
     476#endif
     477}
     478
    479479cf::void_t cf::network::tcp::setTimeout(const cf::int32_t seconds)
    480480{
    481     setNonBlocking(mSocket, seconds > 0 /*? true : false*/);
     481    setNonBlocking(seconds > 0 /*? true : false*/);
    482482    mTimeout = seconds;
    483483}
     
    535535    return std::string(asciiz);
    536536}
     537
     538
     539cf::uint32_t cf::network::byteOrder::htonl(cf::uint32_t in)
     540{
     541    return htonl(in);
     542}
     543
     544cf::uint16_t cf::network::byteOrder::htons(cf::uint16_t in)
     545{
     546    return htons(in);
     547}
     548
     549cf::uint32_t cf::network::byteOrder::ntohl(cf::uint32_t in)
     550{
     551    return ntohl(in);
     552}
     553
     554cf::uint16_t cf::network::byteOrder::ntohs(cf::uint16_t in)
     555{
     556    return ntohs(in);
     557}
Note: See TracChangeset for help on using the changeset viewer.