Heres how it gets called:
char *pBuf = new char[BUFFER_SIZE];
if ( ! pBuf)
return;
int len = 0,
space = BUFFER_SIZE -1; //Space that our buffer has (leaving room for NULL
char *pBufIter;
pBufIter = pBuf; //Pointer to use as an iterator
do{
len = libssh2_channel_read( (*mp_channelList)[channelNumber]->pChannel, pBufIter, space);
if (len > 0)
{
space = space - len; //Mark down how much space is left to write in
if (space > 0)
pBufIter += len; //Move the pBuf pointer to the beginning of blank space
}
} while (len > 0 && space > 0);
if (space == BUFFER_SIZE-1)
{
delete [] pBuf;
return;
}
else
{
*pBufIter = 0x0; //Put our NULL terminator in place
if ( mp_decoder)
mp_decoder->addToQueue( pBuf);
}
char *pBuf = new char[BUFFER_SIZE];
if ( ! pBuf)
return;
int len = 0,
space = BUFFER_SIZE -1; //Space that our buffer has (leaving room for NULL
char *pBufIter;
pBufIter = pBuf; //Pointer to use as an iterator
do{
len = libssh2_channel_read( (*mp_channelList)[channelNumber]->pChannel, pBufIter, space);
if (len > 0)
{
space = space - len; //Mark down how much space is left to write in
if (space > 0)
pBufIter += len; //Move the pBuf pointer to the beginning of blank space
}
} while (len > 0 && space > 0);
if (space == BUFFER_SIZE-1)
{
delete [] pBuf;
return;
}
else
{
*pBufIter = 0x0; //Put our NULL terminator in place
if ( mp_decoder)
mp_decoder->addToQueue( pBuf);
}
To copy to clipboard, switch view to plain text mode
Now the mp_decoder is a class that lives in another thread. Heres its complete function def:
void
Decoder::addToQueue(char *pData)
{
m_mutex.lock();
mp_queue->push_back( pData);
printf("%d items in queue\n", mp_queue->size() );
m_mutex.unlock();
}
void
Decoder::addToQueue(char *pData)
{
m_mutex.lock();
mp_queue->push_back( pData);
printf("%d items in queue\n", mp_queue->size() );
m_mutex.unlock();
}
To copy to clipboard, switch view to plain text mode
Note that I'm just trying to store a pointer to the character string, not the character string. The idea here is that I'm reading this data from a socket. Then I'm adding it to a list (which resides in another thread) that will then process these character strings when it can.
What blows me away is why can't just stuff that char pointer in the list. Theres actually been a few occasions where I can stick the pointer in, but the majority of the time the thing does dome sort of runtime error.
Paul
Bookmarks