/// @param bEnable true to enable option false to disable option.
@@ -284,54 +296,62 @@ public:
bool SetOptionLinger(bool bEnable, uint16 nTime);
/// Tells the kernel that even if this port is busy (in the TIME_WAIT state),
- /// go ahead and reuse it anyway. If it is busy, but with another state,
+ /// go ahead and reuse it anyway. If it is busy, but with another state,
/// you will still get an address already in use error.
/// @return true if option successfully set
bool SetOptionReuseAddr();
/// Gets the timeout value that specifies the maximum number of seconds a
- /// call to CSimpleSocket::Open waits until it completes.
+ /// call to CSimpleSocket::Open waits until it completes.
/// @return the length of time in seconds
- int32 GetConnectTimeoutSec(void) { return m_stConnectTimeout.tv_sec; };
+ int32 GetConnectTimeoutSec(void) {
+ return m_stConnectTimeout.tv_sec;
+ };
/// Gets the timeout value that specifies the maximum number of microseconds
- /// a call to CSimpleSocket::Open waits until it completes.
+ /// a call to CSimpleSocket::Open waits until it completes.
/// @return the length of time in microseconds
- int32 GetConnectTimeoutUSec(void) { return m_stConnectTimeout.tv_usec; };
+ int32 GetConnectTimeoutUSec(void) {
+ return m_stConnectTimeout.tv_usec;
+ };
- /// Sets the timeout value that specifies the maximum amount of time a call
+ /// Sets the timeout value that specifies the maximum amount of time a call
/// to CSimpleSocket::Receive waits until it completes. Use the method
/// CSimpleSocket::SetReceiveTimeout to specify the number of seconds to wait.
/// If a call to CSimpleSocket::Receive has blocked for the specified length of
- /// time without receiving additional data, it returns with a partial count
- /// or CSimpleSocket::GetSocketError set to CSimpleSocket::SocketEwouldblock if no data
- /// were received.
+ /// time without receiving additional data, it returns with a partial count
+ /// or CSimpleSocket::GetSocketError set to CSimpleSocket::SocketEwouldblock if no data
+ /// were received.
/// @param nConnectTimeoutSec of timeout in seconds.
/// @param nConnectTimeoutUsec of timeout in microseconds.
/// @return true if socket connection timeout was successfully set.
- void SetConnectTimeout(int32 nConnectTimeoutSec, int32 nConnectTimeoutUsec = 0)
- {
- m_stConnectTimeout.tv_sec = nConnectTimeoutSec;
- m_stConnectTimeout.tv_usec = nConnectTimeoutUsec;
+ void SetConnectTimeout(int32 nConnectTimeoutSec, int32 nConnectTimeoutUsec = 0)
+ {
+ m_stConnectTimeout.tv_sec = nConnectTimeoutSec;
+ m_stConnectTimeout.tv_usec = nConnectTimeoutUsec;
};
/// Gets the timeout value that specifies the maximum number of seconds a
- /// a call to CSimpleSocket::Receive waits until it completes.
+ /// a call to CSimpleSocket::Receive waits until it completes.
/// @return the length of time in seconds
- int32 GetReceiveTimeoutSec(void) { return m_stRecvTimeout.tv_sec; };
+ int32 GetReceiveTimeoutSec(void) {
+ return m_stRecvTimeout.tv_sec;
+ };
/// Gets the timeout value that specifies the maximum number of microseconds
- /// a call to CSimpleSocket::Receive waits until it completes.
+ /// a call to CSimpleSocket::Receive waits until it completes.
/// @return the length of time in microseconds
- int32 GetReceiveTimeoutUSec(void) { return m_stRecvTimeout.tv_usec; };
+ int32 GetReceiveTimeoutUSec(void) {
+ return m_stRecvTimeout.tv_usec;
+ };
- /// Sets the timeout value that specifies the maximum amount of time a call
+ /// Sets the timeout value that specifies the maximum amount of time a call
/// to CSimpleSocket::Receive waits until it completes. Use the method
/// CSimpleSocket::SetReceiveTimeout to specify the number of seconds to wait.
/// If a call to CSimpleSocket::Receive has blocked for the specified length of
- /// time without receiving additional data, it returns with a partial count
- /// or CSimpleSocket::GetSocketError set to CSimpleSocket::SocketEwouldblock if no data
- /// were received.
+ /// time without receiving additional data, it returns with a partial count
+ /// or CSimpleSocket::GetSocketError set to CSimpleSocket::SocketEwouldblock if no data
+ /// were received.
/// @param nRecvTimeoutSec of timeout in seconds.
/// @param nRecvTimeoutUsec of timeout in microseconds.
/// @return true if socket timeout was successfully set.
@@ -340,101 +360,133 @@ public:
/// Enable/disable multicast for a socket. This options is only valid for
/// socket descriptors of type CSimpleSocket::SocketTypeUdp.
/// @return true if multicast was enabled or false if socket type is not
- /// CSimpleSocket::SocketTypeUdp and the error will be set to
- /// CSimpleSocket::SocketProtocolError
+ /// CSimpleSocket::SocketTypeUdp and the error will be set to
+ /// CSimpleSocket::SocketProtocolError
bool SetMulticast(bool bEnable, uint8 multicastTTL = 1);
/// Return true if socket is multicast or false is socket is unicast
/// @return true if multicast is enabled
- bool GetMulticast() { return m_bIsMulticast; };
+ bool GetMulticast() {
+ return m_bIsMulticast;
+ };
/// Bind socket to a specific interface when using multicast.
/// @return true if successfully bound to interface
bool BindInterface(uint8 *pInterface);
/// Gets the timeout value that specifies the maximum number of seconds a
- /// a call to CSimpleSocket::Send waits until it completes.
+ /// a call to CSimpleSocket::Send waits until it completes.
/// @return the length of time in seconds
- int32 GetSendTimeoutSec(void) { return m_stSendTimeout.tv_sec; };
+ int32 GetSendTimeoutSec(void) {
+ return m_stSendTimeout.tv_sec;
+ };
/// Gets the timeout value that specifies the maximum number of microseconds
- /// a call to CSimpleSocket::Send waits until it completes.
+ /// a call to CSimpleSocket::Send waits until it completes.
/// @return the length of time in microseconds
- int32 GetSendTimeoutUSec(void) { return m_stSendTimeout.tv_usec; };
+ int32 GetSendTimeoutUSec(void) {
+ return m_stSendTimeout.tv_usec;
+ };
- /// Gets the timeout value that specifies the maximum amount of time a call
- /// to CSimpleSocket::Send waits until it completes.
+ /// Gets the timeout value that specifies the maximum amount of time a call
+ /// to CSimpleSocket::Send waits until it completes.
/// @return the length of time in seconds
bool SetSendTimeout(int32 nSendTimeoutSec, int32 nSendTimeoutUsec = 0);
/// Returns the last error that occured for the instace of the CSimpleSocket
- /// instance. This method should be called immediately to retrieve the
+ /// instance. This method should be called immediately to retrieve the
/// error code for the failing mehtod call.
/// @return last error that occured.
- CSocketError GetSocketError(void) { return m_socketErrno; };
+ CSocketError GetSocketError(void) {
+ return m_socketErrno;
+ };
/// Get the total time the of the last operation in milliseconds.
/// @return number of milliseconds of last operation.
- uint32 GetTotalTimeMs() { return m_timer.GetMilliSeconds(); };
+ uint32 GetTotalTimeMs() {
+ return m_timer.GetMilliSeconds();
+ };
/// Get the total time the of the last operation in microseconds.
/// @return number of microseconds or last operation.
- uint32 GetTotalTimeUsec() { return m_timer.GetMicroSeconds(); };
+ uint32 GetTotalTimeUsec() {
+ return m_timer.GetMicroSeconds();
+ };
/// Return Differentiated Services Code Point (DSCP) value currently set on the socket object.
/// @return DSCP for current socket object.
///
\b NOTE: Windows special notes http://support.microsoft.com/kb/248611.
- int GetSocketDscp(void);
+ int GetSocketDscp(void);
- /// Set Differentiated Services Code Point (DSCP) for socket object.
- /// @param nDscp value of TOS setting which will be converted to DSCP
- /// @return true if DSCP value was properly set
+ /// Set Differentiated Services Code Point (DSCP) for socket object.
+ /// @param nDscp value of TOS setting which will be converted to DSCP
+ /// @return true if DSCP value was properly set
///
\b NOTE: Windows special notes http://support.microsoft.com/kb/248611.
- bool SetSocketDscp(int nDscp);
+ bool SetSocketDscp(int nDscp);
- /// Return socket descriptor
- /// @return socket descriptor which is a signed 32 bit integer.
- SOCKET GetSocketDescriptor() { return m_socket; };
+ /// Return socket descriptor
+ /// @return socket descriptor which is a signed 32 bit integer.
+ SOCKET GetSocketDescriptor() {
+ return m_socket;
+ };
- /// Return socket descriptor
- /// @return socket descriptor which is a signed 32 bit integer.
- CSocketType GetSocketType() { return m_nSocketType; };
+ /// Return socket descriptor
+ /// @return socket descriptor which is a signed 32 bit integer.
+ CSocketType GetSocketType() {
+ return m_nSocketType;
+ };
/// Returns clients Internet host address as a string in standard numbers-and-dots notation.
- /// @return NULL if invalid
- uint8 *GetClientAddr() { return (uint8 *)inet_ntoa(m_stClientSockaddr.sin_addr); };
+ /// @return NULL if invalid
+ uint8 *GetClientAddr() {
+ return (uint8 *)inet_ntoa(m_stClientSockaddr.sin_addr);
+ };
- /// Returns the port number on which the client is connected.
- /// @return client port number.
- int16 GetClientPort() { return m_stClientSockaddr.sin_port; };
+ /// Returns the port number on which the client is connected.
+ /// @return client port number.
+ int16 GetClientPort() {
+ return m_stClientSockaddr.sin_port;
+ };
/// Returns server Internet host address as a string in standard numbers-and-dots notation.
- /// @return NULL if invalid
- uint8 *GetServerAddr() { return (uint8 *)inet_ntoa(m_stServerSockaddr.sin_addr); };
+ /// @return NULL if invalid
+ uint8 *GetServerAddr() {
+ return (uint8 *)inet_ntoa(m_stServerSockaddr.sin_addr);
+ };
- /// Returns the port number on which the server is connected.
- /// @return server port number.
- int16 GetServerPort() { return ntohs(m_stServerSockaddr.sin_port); };
+ /// Returns the port number on which the server is connected.
+ /// @return server port number.
+ int16 GetServerPort() {
+ return ntohs(m_stServerSockaddr.sin_port);
+ };
/// Get the TCP receive buffer window size for the current socket object.
///
\b NOTE: Linux will set the receive buffer to twice the value passed.
/// @return zero on failure else the number of bytes of the TCP receive buffer window size if successful.
- uint16 GetReceiveWindowSize() { return GetWindowSize(SO_RCVBUF); };
+ uint16 GetReceiveWindowSize() {
+ return GetWindowSize(SO_RCVBUF);
+ };
/// Get the TCP send buffer window size for the current socket object.
///
\b NOTE: Linux will set the send buffer to twice the value passed.
/// @return zero on failure else the number of bytes of the TCP receive buffer window size if successful.
- uint16 GetSendWindowSize() { return GetWindowSize(SO_SNDBUF); };
+ uint16 GetSendWindowSize() {
+ return GetWindowSize(SO_SNDBUF);
+ };
/// Set the TCP receive buffer window size for the current socket object.
///
\b NOTE: Linux will set the receive buffer to twice the value passed.
/// @return zero on failure else the number of bytes of the TCP send buffer window size if successful.
- uint16 SetReceiveWindowSize(uint16 nWindowSize) { return SetWindowSize(SO_RCVBUF, nWindowSize); };
+ uint16 SetReceiveWindowSize(uint16 nWindowSize) {
+ return SetWindowSize(SO_RCVBUF, nWindowSize);
+ };
/// Set the TCP send buffer window size for the current socket object.
///
\b NOTE: Linux will set the send buffer to twice the value passed.
/// @return zero on failure else the number of bytes of the TCP send buffer window size if successful.
- uint16 SetSendWindowSize(uint16 nWindowSize) { return SetWindowSize(SO_SNDBUF, nWindowSize); };
+ uint16 SetSendWindowSize(uint16 nWindowSize) {
+ return SetWindowSize(SO_SNDBUF, nWindowSize);
+ };
/// Disable the Nagle algorithm (Set TCP_NODELAY to true)
/// @return false if failed to set socket option otherwise return true;
@@ -448,11 +500,15 @@ public:
protected:
/// Set internal socket error to that specified error
/// @param error type of error
- void SetSocketError(CSimpleSocket::CSocketError error) { m_socketErrno = error; };
+ void SetSocketError(CSimpleSocket::CSocketError error) {
+ m_socketErrno = error;
+ };
- /// Set object socket handle to that specified as parameter
+ /// Set object socket handle to that specified as parameter
/// @param socket value of socket descriptor
- void SetSocketHandle(SOCKET socket) { m_socket = socket; };
+ void SetSocketHandle(SOCKET socket) {
+ m_socket = socket;
+ };
private:
/// Generic function used to get the send/receive window size
@@ -464,7 +520,7 @@ private:
uint16 SetWindowSize(uint32 nOptionName, uint32 nWindowSize);
- /// Attempts to send at most nNumItem blocks described by sendVector
+ /// Attempts to send at most nNumItem blocks described by sendVector
/// to the socket descriptor associated with the socket object.
/// @param sendVector pointer to an array of iovec structures
/// @param nNumItems number of items in the vector to process
@@ -476,10 +532,10 @@ private:
int32 Writev(const struct iovec *pVector, size_t nCount);
/// Flush the socket descriptor owned by the object.
- /// @return true data was successfully sent, else return false;
+ /// @return true data was successfully sent, else return false;
bool Flush();
- CSimpleSocket *operator=(CSimpleSocket &socket);
+ CSimpleSocket *operator=(CSimpleSocket &socket);
protected:
SOCKET m_socket; /// socket handle
@@ -503,10 +559,10 @@ protected:
CStatTimer m_timer; /// internal statistics.
#ifdef WIN32
WSADATA m_hWSAData; /// Windows
-#endif
- fd_set m_writeFds; /// write file descriptor set
- fd_set m_readFds; /// read file descriptor set
- fd_set m_errorFds; /// error file descriptor set
+#endif
+ fd_set m_writeFds; /// write file descriptor set
+ fd_set m_readFds; /// read file descriptor set
+ fd_set m_errorFds; /// error file descriptor set
};
--
cgit v1.2.1