Changeset 18 in libcf++


Ignore:
Timestamp:
08/12/15 23:51:04 (9 years ago)
Author:
cheese
Message:

#1 unify descriptor for initializing

Location:
trunk
Files:
6 edited

Legend:

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

    r16 r18  
    7575             * @throw cf::exception
    7676             */
    77             tcp(const cf::socket_t attachedSocket = UNUSED_SOCKET)
     77            tcp(const cf::socket_t attachedSocket = cf::nodesc)
    7878                throw (cf::exception);
    7979
  • trunk/include/cf/types.h

    r17 r18  
    4848    typedef int32_t             socket_t;
    4949#endif
     50
     51    const cf::int32_t           nodesc = -1;
    5052};
    5153
  • trunk/src/bin.cpp

    r15 r18  
    3737cf::size_t cf::bin::size() const
    3838{
    39     return mBin.size();
     39    return static_cast<cf::size_t>(mBin.size());
    4040}
    4141
  • trunk/src/codec.cpp

    r15 r18  
    101101        cf::uint8_t * buf = NULL;
    102102        cf::long_t outlen = 0;
    103         cf::size_t memsize = in.size() / 4 * 3;
     103        cf::size_t memsize = static_cast<cf::size_t>(in.size()) / 4 * 3;
    104104        cf::memory mem(memsize);
    105105
     
    137137            THROW_EXCEPTION("input string is not base64-encoded");
    138138
    139         remain = ptr - src;
     139        remain = static_cast<cf::long_t>(ptr - src);
    140140        binlen = ((remain + 2/* max padding length */) / 4) * 3;
    141141
     
    228228        cf::uint8_t * buf = NULL;
    229229        cf::int32_t len = 0;
    230         cf::size_t memsize = in.size() / 2;
     230        cf::size_t memsize = static_cast<cf::size_t>(in.size()) / 2;
    231231        cf::memory mem(memsize);
    232232
  • trunk/src/file.cpp

    r4 r18  
    4242#endif
    4343
    44 #define NO_FD           -1
    45 
    4644/*--------------------------------------------------------------*/
    4745
     
    122120cf::file::file(const cf::char_t * path)
    123121    throw (cf::exception)
    124     : mFD(NO_FD),
     122    : mFD(cf::nodesc),
    125123      mIsLocked(false)
    126124{
     
    179177    {
    180178        ::close(mFD);
    181         mFD = NO_FD;
     179        mFD = cf::nodesc;
    182180    }
    183181
     
    194192cf::bool_t cf::file::isOpened()
    195193{
    196     return mFD > NO_FD ? true : false;
     194    return mFD > cf::nodesc ? true : false;
    197195}
    198196
  • trunk/src/network.cpp

    r15 r18  
    8484    tv.tv_usec = 0;
    8585
    86     result = select(sock + 1, &rfds, wfdsPtr, NULL, &tv);
     86    result = select(static_cast<int>(sock) + 1, &rfds, wfdsPtr, NULL, &tv);
    8787    if (result < 0)
    8888        THROW_EXCEPTION("select error");
     
    173173    }
    174174
    175     if (mSocket == UNUSED_SOCKET)
     175    if (mSocket == cf::nodesc)
    176176        mSocket = ::socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    177177
     
    192192cf::void_t cf::network::tcp::close()
    193193{
    194     if (mSocket == UNUSED_SOCKET)
     194    if (mSocket == cf::nodesc)
    195195        return;
    196196
    197197    closesocket(mSocket);
    198198
    199     mSocket = UNUSED_SOCKET;
     199    mSocket = cf::nodesc;
    200200}
    201201
     
    324324    throw (exception)
    325325{
    326     if (sock == UNUSED_SOCKET)
     326    if (sock == cf::nodesc)
    327327        THROW_EXCEPTION("has invalid socket");
    328328
     
    333333    throw (exception)
    334334{
    335     if (mSocket == UNUSED_SOCKET)
     335    if (mSocket == cf::nodesc)
    336336        THROW_EXCEPTION("has invalid socket");
    337337
    338338    cf::socket_t sock = mSocket;
    339339
    340     mSocket = UNUSED_SOCKET;
     340    mSocket = cf::nodesc;
    341341
    342342    return sock;
Note: See TracChangeset for help on using the changeset viewer.