Fwd: [Help-gnutls] GnuTLS and Qt

Ian Cullinan cibyr at cibyr.com
Mon Nov 5 09:13:15 CET 2007


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.





More information about the Gnutls-help mailing list