[Qt-interest] socketDescriptor in MacOSX with libssh2
Thiago Macieira
thiago at kde.org
Fri Nov 27 08:57:18 CET 2009
Em Sexta-feira 27. Novembro 2009, às 00.22.14, Filipe Maia escreveu:
> Hi,
>
> I'm trying to use libssh2 with QTcpSocket.
> libssh2 requires a socket as returned by the socket(2) function.
>
> I'm trying to replace:
>
> sock = socket(AF_INET, SOCK_STREAM, 0);
>
> ...
>
> session = libssh2_session_init();
> if (libssh2_session_startup(session, sock)) {
> fprintf(stderr, "Failure establishing SSH session\n");
> return -1;
> }
>
> where sock is a socket connected to the ssh server
>
> by:
>
> m_session = libssh2_session_init();
> libssh2_session_startup(m_session, m_socket->socketDescriptor());
>
> where m_socket is a QTcpSocket connected to the ssh server.
>
> But this doesn't seem to work (I get session failed).
> Is there a fundamental difference between socketDescriptor() and
> what's returned by socket() in MacOSX?
No, there's no fundamental difference. socketDescriptor() returns a socket
created by a call to socket(2). Note that you must connect first before it
creates the socket.
The problem, however, is that QTcpSocket will try to read from the socket. You
cannot stop it from doing that. That means it will interfere with libssh2.
I recommend you do the following:
int tmpsocket = m_socket->socketDescriptor();
m_session = libssh2_session_init();
libssh2_session_startup(m_session, dup(tmpsocket));
m_socket->abort();
This will cause a new file descriptor to be created (by dup(2)) and will make
QTcpSocket close its copy.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091127/a16a11d4/attachment.bin
More information about the Qt-interest-old
mailing list