diff options
author | Maks Naumov <maksqwe1@ukr.net> | 2014-08-25 21:45:02 +0300 |
---|---|---|
committer | Maks Naumov <maksqwe1@ukr.net> | 2014-09-15 01:11:55 +0300 |
commit | 25c5ffe9eb2213fc18ab498320fbf9af79e1250d (patch) | |
tree | c4cc334ae2659a58b6ce9bd8f38beac500fc6452 /lib | |
parent | f60bdf7715b6808f85a549a32d0e422e23bf765f (diff) |
SlingboxLib: Fix alternative CSlingbox constructor
CSlingbox::CSlingbox(const char * szAddress, unsigned int uiPort /* = 5001 */) {
// Call default constructor
CSlingbox();
...
}
"CSlingbox();" - object is created and immediately removed.
Therefore with CSlingbox(const char * szAddress, unsigned int uiPort /* = 5001 */) class members will not be initialized.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/SlingboxLib/SlingboxLib.cpp | 32 | ||||
-rw-r--r-- | lib/SlingboxLib/SlingboxLib.h | 1 |
2 files changed, 20 insertions, 13 deletions
diff --git a/lib/SlingboxLib/SlingboxLib.cpp b/lib/SlingboxLib/SlingboxLib.cpp index f2d7017de1..0632e6f8e8 100644 --- a/lib/SlingboxLib/SlingboxLib.cpp +++ b/lib/SlingboxLib/SlingboxLib.cpp @@ -41,24 +41,16 @@ typedef int socklen_t; // Default constructor. CSlingbox::CSlingbox() { - // Set all variables to default/invalid values - m_socCommunication = INVALID_SOCKET; - m_socStream = INVALID_SOCKET; - memset(m_szAddress, 0, sizeof(m_szAddress)); - m_uiPort = 0; - m_usCode = 0; - m_usSequence = 0; - m_iChannel = -1; - m_iInput = -1; - memset(&m_receivedMessages, 0, sizeof(m_receivedMessages)); + // initialize all members + init(); } // Alternative constructor used to set the address (IP or hostname) and port of the -// Slingbox we want to connect to. If no port is specified default port 5001 is used. +// Slingbox we want to connect to. If no port is specified default port 5001 is used. CSlingbox::CSlingbox(const char * szAddress, unsigned int uiPort /* = 5001 */) { - // Call default constructor - CSlingbox(); + // initialize all members + init(); // Set address and port variables to passed values SetAddress(szAddress, uiPort); @@ -74,6 +66,20 @@ CSlingbox::~CSlingbox() CloseSocket(m_socCommunication); } +// Function used to initialize class members +void CSlingbox::init() +{ + // Set all variables to default/invalid values + m_socCommunication = INVALID_SOCKET; + m_socStream = INVALID_SOCKET; + memset(m_szAddress, 0, sizeof(m_szAddress)); + m_uiPort = 0; + m_usCode = 0; + m_usSequence = 0; + m_iChannel = -1; + m_iInput = -1; + memset(&m_receivedMessages, 0, sizeof(m_receivedMessages)); +} // Function used to find a Slingbox. Address and port of found Slingbox can be // retrieved with the GetAddress function afterwards. bool CSlingbox::FindSlingbox(unsigned int uiTimeout /* = 10 */) diff --git a/lib/SlingboxLib/SlingboxLib.h b/lib/SlingboxLib/SlingboxLib.h index ad368f00f1..a8835bc02b 100644 --- a/lib/SlingboxLib/SlingboxLib.h +++ b/lib/SlingboxLib/SlingboxLib.h @@ -91,6 +91,7 @@ public: bool SendIRCommand(uint8_t ucCommand); protected: + void init(); // Function used to send and receive messages to and from the Slingbox struct MessageHeader; bool SendReceiveMessage(SOCKET socSocket, MessageHeader * pHeader, |