bool plBufferedSocketReader::GetBlock(char * buf, int buflen)
{
    int dataAvailable = FastAmountBuffered();
    int maxRead = buflen;
    if(maxRead > dataAvailable)
        maxRead = dataAvailable;

    if (maxRead==0)
        return false;
    
    char * wrk = FastGetBufferStart();
    memcpy(buf,FastGetBufferStart(),maxRead);

    return true;
}
bool plBufferedSocketReader::GetStringInPlace(char ** buf, char * termChars)
{
    bool ans = false;
    int dataAvailable = FastAmountBuffered();
    
    *buf = FastGetBufferStart();
    for(int i=0; i<dataAvailable; i++)
    {
        if(strchr(termChars,(*buf)[i])!=0)
        {
            (*buf)[i] = '\0';
            fStartPos += i+1;                
            Compress();
            ans = true;
            break;
        }            
    }
    return ans;
}
Beispiel #3
0
int plBufferedSocketWriter::Flush(plTcpSocket & sck)    // this is where things get ugly.
{
    int ans = kSuccessNoDataSent;

    int writeSize = std::min(FastAmountBuffered(), fBytesPerFlush);
    
    if(writeSize > 0)
    {
        int nBytesWritten = 0;
//      int nBytesWritten = sck.SendData(FastGetBufferStart(), writeSize);

//      if (nBytesWritten<0 && fBlockOnSend
//          && plNet::GetError()==kBlockingError)
        {
            bool wasBlockingOrNot = sck.IsBlocking();
            sck.SetBlocking(fBlockOnSend);
            nBytesWritten = sck.SendData(FastGetBufferStart(), writeSize);        
            sck.SetBlocking(wasBlockingOrNot);
        }

        if (nBytesWritten > 0)
        {
            fStartPos += nBytesWritten;
            FullCompress();
            ans = kSuccessDataSent;
        }
        else if (nBytesWritten < 0)
        {
            if (plNet::GetError()!=kBlockingError)
                ans = kFailedWriteError;
        }
        else
        {
            ans = kFailedSocketClosed;
        }
    }        
    return ans;
}
bool plBufferedSocketReader::GetString(char * buf, int buflen, char * termChars)
{
    bool ans = false;
    int dataAvailable = FastAmountBuffered();
    int maxRead = buflen;
    if(maxRead > dataAvailable)
        maxRead = dataAvailable;
    
    char * wrk = FastGetBufferStart();
    for(int i=0; i<maxRead; i++)
    {
        if(strchr(termChars,wrk[i])!=0)
        {
            memcpy(buf,wrk,i);
            buf[i] = '\0';
            fStartPos += i+1;                
            Compress();
            ans = true;
            break;
        }            
    }
    return ans;
}
Beispiel #5
0
bool plBufferedSocketWriter::IsEmpty()
{
    return !(FastAmountBuffered() > 0);
}