Changeset 7 in libcf++ for trunk/src/network.cpp


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

#1 fix and add interfaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.