Changeset 7 in libcf++ for trunk/src/network.cpp
- Timestamp:
- 03/29/15 16:30:07 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/network.cpp
r6 r7 39 39 #endif 40 40 41 #define UNUSED_SOCKET -142 43 41 /*--------------------------------------------------------------*/ 44 42 /** … … 62 60 } 63 61 64 static cf::void_t setNonBlocking(const cf::socket_t sock,65 const cf::bool_t flag)66 {67 #ifdef _ON_WINDOWS68 cf::ulong_t mode = flag ? 1 : 0;69 ioctlsocket(sock, FIONBIO, &mode);70 #else71 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 #endif78 }79 80 62 static cf::void_t waitForTimeout(const cf::socket_t sock, 81 63 const cf::int32_t timeout, … … 206 188 { 207 189 close(); 190 } 191 192 cf::socket_t cf::network::tcp::descriptor() const 193 { 194 return mSocket; 208 195 } 209 196 … … 348 335 THROW_EXCEPTION("has invalid socket"); 349 336 350 close();351 352 337 mSocket = sock; 353 338 } … … 477 462 } 478 463 464 cf::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 479 479 cf::void_t cf::network::tcp::setTimeout(const cf::int32_t seconds) 480 480 { 481 setNonBlocking( mSocket,seconds > 0 /*? true : false*/);481 setNonBlocking(seconds > 0 /*? true : false*/); 482 482 mTimeout = seconds; 483 483 } … … 535 535 return std::string(asciiz); 536 536 } 537 538 539 cf::uint32_t cf::network::byteOrder::htonl(cf::uint32_t in) 540 { 541 return htonl(in); 542 } 543 544 cf::uint16_t cf::network::byteOrder::htons(cf::uint16_t in) 545 { 546 return htons(in); 547 } 548 549 cf::uint32_t cf::network::byteOrder::ntohl(cf::uint32_t in) 550 { 551 return ntohl(in); 552 } 553 554 cf::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.