Results 1 to 3 of 3

Thread: How to free for re-using a socketDescriptor

  1. #1
    Join Date
    Jun 2010
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows

    Default How to free for re-using a socketDescriptor

    Hello,

    OK, title was hard to find, but here is my problem:
    I'm using QTcpServer and QTcpSocket for creating higher-level classes.
    When a connection is etablished, I need to send the socketDescriptor of a connected QTcpSocket (gived by the nextPendingConnection function of QTcpServer) to another class for creating a new socket instance.
    I have no problems under windows, but I encounter some problems under Linux and I can't receive any data. I think the problem is from this:
    We can read this in the Qt Documentation: Note: It is not possible to initialize two abstract sockets with the same native socket descriptor.
    But nothing about how to "free" a socketDescriptor for using it in another class (or thread).
    Last edited by erqsor; 27th December 2011 at 17:46.

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to free for re-using a socketDescriptor

    That if to transfer not a socket descriptor but pointer to QTcpSocket?

  3. #3
    Join Date
    Jun 2010
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to free for re-using a socketDescriptor

    Yes, but that's not thread-safe.
    You can read this in the Qt documentation:
    Note: If you want to handle an incoming connection as a new QTcpSocket object in another thread you have to pass the socketDescriptor to the other thread and create the QTcpSocket object there and use its setSocketDescriptor() method.
    My class is using a QTcpServer, and I need to override the QTcpServer::incomingConnexion function with a socketDesecriptor of a socket that is already connected. But what I do on the socket is disconnecting it (delete, deleteLater, close, abort, ...). When we created a QTcpSocket and set to it a socketDescriptor, the socketDescriptor is becoming useless ?

Similar Threads

  1. Replies: 8
    Last Post: 11th September 2010, 10:41
  2. Same port when you pass socketDescriptor?
    By Dumbledore in forum Qt Programming
    Replies: 3
    Last Post: 11th December 2007, 22:03
  3. Free()
    By AnithaRagupathy in forum Newbie
    Replies: 1
    Last Post: 14th October 2007, 09:17
  4. What to free or not to free, that is the question
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2007, 05:04
  5. to free or not to free
    By masoroso in forum Newbie
    Replies: 1
    Last Post: 17th April 2006, 18:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.