[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fwd: [Help-gnutls] GnuTLS and Qt
From: |
Ian Cullinan |
Subject: |
Fwd: [Help-gnutls] GnuTLS and Qt |
Date: |
Mon, 5 Nov 2007 18:13:15 +1000 |
Thank you very much, that helped a lot.
The fix:
extern "C" ssize_t gnutls_qt_pull(gnutls_transport_ptr_t transPtr,
void* buf, size_t len) {
QTcpSocket* sock = (QTcpSocket*)transPtr;
if (!sock->bytesAvailable()) {
if (!sock->waitForReadyRead(-1)) {
cerr << "PULL ERROR: (waiting for read) "
<<
sock->errorString().toStdString() << endl;
}
}
int ret = sock->read((char*)buf, (qint64)len);
if (ret == -1) {
cerr << "PULL ERROR: " <<
sock->errorString().toStdString() << endl;
}
return ret;
}
extern "C" ssize_t gnutls_qt_push(gnutls_transport_ptr_t transPtr,
const void* data, size_t len) {
QTcpSocket* sock = (QTcpSocket*)transPtr;
int ret = sock->write((const char*)data, (qint64)len);
if (ret == -1 || (sock->bytesToWrite() &&
!sock->waitForBytesWritten(-1))) {
cerr << "PUSH ERROR: " <<
sock->errorString().toStdString() << endl;
}
return ret;
}
Having non-infinite timeouts, and modular error reporting/logging
would probably be a good idea as well, but I'll probably write a class
that actually does things properly later on. The cool thing is this
should work that Qt and GnuTLS do, without any #ifdef messiness :)
Cheers,
Ian
PS. And here's me silly enough not to send this to the group.