Trying to fix connectivity tool.

This commit is contained in:
lotodore
2011-01-17 10:44:47 +00:00
parent 4a6367cea3
commit 0255568b80
2 changed files with 270 additions and 262 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ MOC_DIR = mocs
OBJECTS_DIR = obj
DEFINES += PREFIX=\"$${PREFIX}\"
QT -= core gui
QMAKE_CXXFLAGS += -std=gnu++0x
#QMAKE_CXXFLAGS += -std=gnu++0x
#PRECOMPILED_HEADER = src/pch_lib.h
INCLUDEPATH += . \
+19 -11
View File
@@ -33,10 +33,12 @@ using namespace std;
using boost::asio::ip::tcp;
namespace po = boost::program_options;
#define BUF_SIZE 1024
// Global receive buffer
boost::array<char, 512> recBuf;
boost::array<char, BUF_SIZE> recBuf;
size_t recBufPos = 0;
boost::array<char, 512> sendBuf;
boost::array<char, BUF_SIZE> sendBuf;
static int
net_packet_print_to_string(const void *buffer, size_t size, void *packetStr)
@@ -51,9 +53,11 @@ xer_encode(&asn_DEF_PokerTHMessage, msg, XER_F_BASIC, &net_packet_print_to_strin
cout << packetString << endl;*/
PokerTHMessage_t *
receiveMessage(tcp::socket &socket, bool recursed = false)
receiveMessage(tcp::socket &socket)
{
PokerTHMessage_t *msg = NULL;
do
{
asn_dec_rval_t retVal = ber_decode(0, &asn_DEF_PokerTHMessage, (void **)&msg, recBuf.data(), recBufPos);
if(retVal.code == RC_OK)
{
@@ -71,14 +75,9 @@ receiveMessage(tcp::socket &socket, bool recursed = false)
{
// Free the partially decoded message (if applicable).
ASN_STRUCT_FREE(asn_DEF_PokerTHMessage, msg);
if (!recursed)
{
recBufPos += socket.receive(boost::asio::buffer(recBuf.c_array() + recBufPos, 512 - recBufPos));
return receiveMessage(socket, true);
}
else
return msg = NULL;
recBufPos += socket.receive(boost::asio::buffer(recBuf.c_array() + recBufPos, BUF_SIZE - recBufPos));
}
} while (recBufPos < BUF_SIZE && msg != NULL);
return msg;
}
@@ -88,7 +87,7 @@ sendMessage(tcp::socket &socket, PokerTHMessage_t *msg)
bool retVal = false;
if (msg)
{
asn_enc_rval_t e = der_encode_to_buffer(&asn_DEF_PokerTHMessage, msg, sendBuf.data(), 512);
asn_enc_rval_t e = der_encode_to_buffer(&asn_DEF_PokerTHMessage, msg, sendBuf.data(), BUF_SIZE);
if (e.encoded != -1)
{
socket.send(boost::asio::buffer(sendBuf.data(), e.encoded));
@@ -102,6 +101,8 @@ sendMessage(tcp::socket &socket, PokerTHMessage_t *msg)
int
main(int argc, char *argv[])
{
try
{
// Check command line options.
po::options_description desc("Allowed options");
desc.add_options()
@@ -367,6 +368,13 @@ main(int argc, char *argv[])
}
perfTimer.restart();
gsasl_done(authContext);
}
catch (...)
{
cout << "Exception caught" << endl;
return 1;
}
return 0;
}