00001 00014 // TcpSocket.cpp -- implementation for the TcpSocket class 00015 00016 #include "TcpSocket.h" 00017 00018 00020 // class TcpSocket 00021 00022 // Default constructor 00023 TcpSocket::TcpSocket(TcpBinding binding) : ConnectableSocket(SOCK_STREAM, AF_INET) 00024 { 00025 if ( binding == bound ) 00026 Socket::bind(SocketAddress()); 00027 } 00028 00029 // Construct from the OS native descriptor 00030 TcpSocket::TcpSocket(SOCKET socketHandle) : ConnectableSocket(socketHandle) 00031 { 00032 } 00033 00034 // Construct from the given SocketAddress 00035 TcpSocket::TcpSocket(const SocketAddress& address) : ConnectableSocket(SOCK_STREAM,address.getAddressFamily(),0) 00036 { 00037 Socket::bind(address); 00038 } 00039 00040 00041 // Close and reopen the TcpSocket (all active connections will be lost) 00042 void TcpSocket::reset() 00043 { 00044 Socket::reset(SOCK_STREAM,AF_INET); 00045 } 00046 00047 00048 // Whether keep-alives are being sent 00049 bool TcpSocket::keepAlive() const 00050 { 00051 return getBoolOption(SO_KEEPALIVE); 00052 } 00053 00054 00055 // Set the keep-alive socket option 00056 void TcpSocket::setKeepAlives( bool flag ) 00057 { 00058 setBoolOption(SO_KEEPALIVE, flag); 00059 }