diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-15 16:06:38 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-15 16:06:38 -0500 |
commit | 274a42aacecfcbcbdd80e3845e3b01991b65f925 (patch) | |
tree | a5eabe9a6cc772e662c06b59d900c6b08eacb3c7 /lib/libtdekrb/src | |
parent | 93e334df145c1682214d0c386ae7e621c188a2cc (diff) | |
download | ulab-274a42aacecfcbcbdd80e3845e3b01991b65f925.tar.gz ulab-274a42aacecfcbcbdd80e3845e3b01991b65f925.zip |
Use circular buffer in krb client and server sockets
Diffstat (limited to 'lib/libtdekrb/src')
-rw-r--r-- | lib/libtdekrb/src/tdekrbclientsocket.cpp | 70 | ||||
-rw-r--r-- | lib/libtdekrb/src/tdekrbclientsocket.h | 1 | ||||
-rw-r--r-- | lib/libtdekrb/src/tdekrbserversocket.cpp | 70 | ||||
-rw-r--r-- | lib/libtdekrb/src/tdekrbserversocket.h | 1 |
4 files changed, 68 insertions, 74 deletions
diff --git a/lib/libtdekrb/src/tdekrbclientsocket.cpp b/lib/libtdekrb/src/tdekrbclientsocket.cpp index 3705889..b49d48d 100644 --- a/lib/libtdekrb/src/tdekrbclientsocket.cpp +++ b/lib/libtdekrb/src/tdekrbclientsocket.cpp @@ -99,7 +99,7 @@ static int logSASLMessages(void *context __attribute__((unused)), int priority, return SASL_OK; } -TDEKerberosClientSocket::TDEKerberosClientSocket(TQObject *parent, const char *name) : TQSocket(parent, name), m_kerberosRequested(false), m_criticalSection(0), m_bufferLength(0), m_krbInitRunning(false), m_krbInitState(-1), m_dataTimeout(-1), kerberosInitLoopTimer(NULL), m_canary(NULL), m_negotiatedMaxBufferSize(NET_SEC_BUF_SIZE) { +TDEKerberosClientSocket::TDEKerberosClientSocket(TQObject *parent, const char *name) : TQSocket(parent, name), m_kerberosRequested(false), m_criticalSection(0), m_bufferLength(0), m_bufferReadPointer(0), m_krbInitRunning(false), m_krbInitState(-1), m_dataTimeout(-1), kerberosInitLoopTimer(NULL), m_canary(NULL), m_negotiatedMaxBufferSize(NET_SEC_BUF_SIZE) { saslData = new SASLDataPrivate; saslData->m_krbConnection = NULL; m_buffer = new TQBuffer(); @@ -181,14 +181,12 @@ bool TDEKerberosClientSocket::at(TQIODevice::Offset off, int hidebasehack) { // Remove the specified bytes from the buffer m_bufferLength = m_bufferLength-off; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+off]; - } + m_bufferReadPointer = m_bufferReadPointer+off; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } return true; @@ -256,10 +254,11 @@ int TDEKerberosClientSocket::ungetch(int ch) { int ret; if (kerberosStatus() == KerberosInUse) { - ret = m_buffer->ungetch(ch); - if (ret >= 0) { - m_bufferLength++; - } + // FIXME + // UNIMPLEMENTED + // This feature, if supported, will be very expensive, requiring a full allocation+copy/shift+deallocation of the buffer array, + // followed by insertion of the new character to the head of the array + ret = -1; } else { ret = TQSocket::ungetch(ch); @@ -293,7 +292,7 @@ int TDEKerberosClientSocket::processPendingData() { return -1; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -354,7 +353,7 @@ TQ_LONG TDEKerberosClientSocket::readBlock(char *data, TQ_ULONG maxlen) { return -1; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -367,19 +366,17 @@ TQ_LONG TDEKerberosClientSocket::readBlock(char *data, TQ_ULONG maxlen) { if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; } - m_buffer->at(0); + m_buffer->at(m_bufferReadPointer); ret = m_buffer->readBlock(data, maxlen); if (ret > 0) { // Remove the read bytes from the buffer m_bufferLength = m_bufferLength-ret; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+ret]; - } + m_bufferReadPointer = m_bufferReadPointer+ret; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } } @@ -418,7 +415,7 @@ TQ_LONG TDEKerberosClientSocket::readLine(char *data, TQ_ULONG maxlen) { return -1; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -431,19 +428,17 @@ TQ_LONG TDEKerberosClientSocket::readLine(char *data, TQ_ULONG maxlen) { if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; } - m_buffer->at(0); + m_buffer->at(m_bufferReadPointer); ret = m_buffer->readLine(data, maxlen); if (ret > 0) { // Remove the read bytes from the buffer m_bufferLength = m_bufferLength-ret; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+ret]; - } + m_bufferReadPointer = m_bufferReadPointer+ret; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } } @@ -473,7 +468,7 @@ TQString TDEKerberosClientSocket::readLine() { return TQString::null; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -486,20 +481,18 @@ TQString TDEKerberosClientSocket::readLine() { if (maxlen > m_bufferLength) { maxlen = m_bufferLength; } - m_buffer->at(0); + m_buffer->at(m_bufferReadPointer); buf = (char*)malloc(maxlen); readlen = m_buffer->readLine(buf, maxlen); if (readlen > 0) { // Remove the read bytes from the buffer m_bufferLength = m_bufferLength-readlen; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+readlen]; - } + m_bufferReadPointer = m_bufferReadPointer+readlen; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } ret = TQString(buf); } @@ -726,8 +719,13 @@ int TDEKerberosClientSocket::writeEndOfFrame() { bool TDEKerberosClientSocket::canReadFrame() { processPendingData(); - if (m_buffer->buffer().contains(255) > 0) { - return true; + if (m_bufferLength > 0) { + if (m_buffer->buffer().find(255, m_bufferReadPointer) >= 0) { + return true; + } + else { + return false; + } } else { return false; @@ -738,18 +736,16 @@ void TDEKerberosClientSocket::clearFrameTail() { int i; int eofLoc; if (m_bufferLength > 0) { - eofLoc = m_buffer->buffer().find(255, 0) + 1; - if ((eofLoc > 0) && (eofLoc <= m_bufferLength)) { + eofLoc = m_buffer->buffer().find(255, m_bufferReadPointer) + 1; + if ((eofLoc > 0) && (eofLoc <= (m_bufferLength+m_bufferReadPointer))) { // Remove the remaining frame bytes (including the End of Frame marker) from the buffer - m_bufferLength = m_bufferLength-eofLoc; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+eofLoc]; - } + m_bufferLength = m_bufferLength-(eofLoc-m_bufferReadPointer); + m_bufferReadPointer = m_bufferReadPointer+(eofLoc-m_bufferReadPointer); if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } } diff --git a/lib/libtdekrb/src/tdekrbclientsocket.h b/lib/libtdekrb/src/tdekrbclientsocket.h index a9034f0..d295192 100644 --- a/lib/libtdekrb/src/tdekrbclientsocket.h +++ b/lib/libtdekrb/src/tdekrbclientsocket.h @@ -103,6 +103,7 @@ class TDEKerberosClientSocket : public TQSocket int m_criticalSection; TQBuffer* m_buffer; long m_bufferLength; + long m_bufferReadPointer; bool m_krbInitRunning; int m_krbInitState; TQString m_prevStatusMessage; diff --git a/lib/libtdekrb/src/tdekrbserversocket.cpp b/lib/libtdekrb/src/tdekrbserversocket.cpp index b2e735c..1926cb3 100644 --- a/lib/libtdekrb/src/tdekrbserversocket.cpp +++ b/lib/libtdekrb/src/tdekrbserversocket.cpp @@ -100,7 +100,7 @@ static int logSASLMessages(void *context __attribute__((unused)), int priority, return SASL_OK; } -TDEKerberosServerSocket::TDEKerberosServerSocket(TQObject *parent, const char *name) : TQSocket(parent, name), m_kerberosRequested(false), m_criticalSection(0), m_bufferLength(0), m_krbInitRunning(false), m_krbInitState(-1), m_dataTimeout(-1), kerberosInitLoopTimer(NULL), m_canary(NULL), m_negotiatedMaxBufferSize(NET_SEC_BUF_SIZE) { +TDEKerberosServerSocket::TDEKerberosServerSocket(TQObject *parent, const char *name) : TQSocket(parent, name), m_kerberosRequested(false), m_criticalSection(0), m_bufferLength(0), m_bufferReadPointer(0), m_krbInitRunning(false), m_krbInitState(-1), m_dataTimeout(-1), kerberosInitLoopTimer(NULL), m_canary(NULL), m_negotiatedMaxBufferSize(NET_SEC_BUF_SIZE) { saslData = new SASLDataPrivate; saslData->m_krbConnection = NULL; m_buffer = new TQBuffer(); @@ -182,14 +182,12 @@ bool TDEKerberosServerSocket::at(TQIODevice::Offset off, int hidebasehack) { // Remove the specified bytes from the buffer m_bufferLength = m_bufferLength-off; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+off]; - } + m_bufferReadPointer = m_bufferReadPointer+off; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } return true; @@ -257,10 +255,11 @@ int TDEKerberosServerSocket::ungetch(int ch) { int ret; if (kerberosStatus() == KerberosInUse) { - ret = m_buffer->ungetch(ch); - if (ret >= 0) { - m_bufferLength++; - } + // FIXME + // UNIMPLEMENTED + // This feature, if supported, will be very expensive, requiring a full allocation+copy/shift+deallocation of the buffer array, + // followed by insertion of the new character to the head of the array + ret = -1; } else { ret = TQSocket::ungetch(ch); @@ -294,7 +293,7 @@ int TDEKerberosServerSocket::processPendingData() { return -1; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -363,7 +362,7 @@ TQ_LONG TDEKerberosServerSocket::readBlock(char *data, TQ_ULONG maxlen) { return -1; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -376,19 +375,17 @@ TQ_LONG TDEKerberosServerSocket::readBlock(char *data, TQ_ULONG maxlen) { if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; } - m_buffer->at(0); + m_buffer->at(m_bufferReadPointer); ret = m_buffer->readBlock(data, maxlen); if (ret > 0) { // Remove the read bytes from the buffer m_bufferLength = m_bufferLength-ret; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+ret]; - } + m_bufferReadPointer = m_bufferReadPointer+ret; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } } @@ -427,7 +424,7 @@ TQ_LONG TDEKerberosServerSocket::readLine(char *data, TQ_ULONG maxlen) { return -1; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -440,19 +437,17 @@ TQ_LONG TDEKerberosServerSocket::readLine(char *data, TQ_ULONG maxlen) { if (maxlen > (unsigned int)m_bufferLength) { maxlen = m_bufferLength; } - m_buffer->at(0); + m_buffer->at(m_bufferReadPointer); ret = m_buffer->readLine(data, maxlen); if (ret > 0) { // Remove the read bytes from the buffer m_bufferLength = m_bufferLength-ret; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+ret]; - } + m_bufferReadPointer = m_bufferReadPointer+ret; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } } @@ -482,7 +477,7 @@ TQString TDEKerberosServerSocket::readLine() { return TQString::null; } if (reclen > 0) { - m_buffer->at(m_bufferLength); + m_buffer->at(m_bufferLength+m_bufferReadPointer); wrlen = m_buffer->writeBlock(buf, reclen); if (wrlen > 0) { m_bufferLength = m_bufferLength + wrlen; @@ -495,20 +490,18 @@ TQString TDEKerberosServerSocket::readLine() { if (maxlen > m_bufferLength) { maxlen = m_bufferLength; } - m_buffer->at(0); + m_buffer->at(m_bufferReadPointer); buf = (char*)malloc(maxlen); readlen = m_buffer->readLine(buf, maxlen); if (readlen > 0) { // Remove the read bytes from the buffer m_bufferLength = m_bufferLength-readlen; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+readlen]; - } + m_bufferReadPointer = m_bufferReadPointer+readlen; if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } ret = TQString(buf); } @@ -735,8 +728,13 @@ int TDEKerberosServerSocket::writeEndOfFrame() { bool TDEKerberosServerSocket::canReadFrame() { processPendingData(); - if (m_buffer->buffer().contains(255) > 0) { - return true; + if (m_bufferLength > 0) { + if (m_buffer->buffer().find(255, m_bufferReadPointer) >= 0) { + return true; + } + else { + return false; + } } else { return false; @@ -747,18 +745,16 @@ void TDEKerberosServerSocket::clearFrameTail() { int i; int eofLoc; if (m_bufferLength > 0) { - eofLoc = m_buffer->buffer().find(255, 0) + 1; - if ((eofLoc > 0) && (eofLoc <= m_bufferLength)) { + eofLoc = m_buffer->buffer().find(255, m_bufferReadPointer) + 1; + if ((eofLoc > 0) && (eofLoc <= (m_bufferLength+m_bufferReadPointer))) { // Remove the remaining frame bytes (including the End of Frame marker) from the buffer - m_bufferLength = m_bufferLength-eofLoc; - TQByteArray ba = m_buffer->buffer(); - for (i=0; i<m_bufferLength;i++) { - ba[i] = ba[i+eofLoc]; - } + m_bufferLength = m_bufferLength-(eofLoc-m_bufferReadPointer); + m_bufferReadPointer = m_bufferReadPointer+(eofLoc-m_bufferReadPointer); if (m_bufferLength < 1) { // Clear the buffer from memory m_buffer->close(); m_buffer->open(IO_ReadWrite|IO_Truncate); + m_bufferReadPointer = 0; } } } diff --git a/lib/libtdekrb/src/tdekrbserversocket.h b/lib/libtdekrb/src/tdekrbserversocket.h index 1f4b4ff..3bd0bd2 100644 --- a/lib/libtdekrb/src/tdekrbserversocket.h +++ b/lib/libtdekrb/src/tdekrbserversocket.h @@ -107,6 +107,7 @@ class TDEKerberosServerSocket : public TQSocket int m_criticalSection; TQBuffer* m_buffer; long m_bufferLength; + long m_bufferReadPointer; bool m_krbInitRunning; int m_krbInitState; TQString m_prevStatusMessage; |