Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, May 2007
Receive QTcpSocket::bytesWritten on Windows but not on Linux


Message 1 in thread

I'm using Qt 4.3rc1.

I've been unable to duplicate this with a simple application yet and
cannot post the whole application where the problem occurs.  But the
code should be the same on the two platforms.  Basically I've done the
following and see the OnBytesWritten messages on Windows but not on
Unix.

Any tips on what could cause OnBytesWritten() not to get called on Linux?

-----
VQtSocket::VQtSoocket(char* szAddress, uint uwPort)
{
  m_pSocket = new QTcpSocket(this);

  connect(m_pSocket, SIGNAL(connected()),
    this, SLOT(OnConnected()));

  connect(m_pSocket, SIGNAL(bytesWritten(qint64)),
    this, SLOT(OnBytesWritten(qint64)));

  connect(m_pSocket, SIGNAL(readyRead()),
    this, SLOT(OnReadyRead()));

  m_pSocket->connectToHost(QString(szAddress), uwPort);
}

void VQtSocket::OnConnected()
{
  qDebug() << "VQtSocket::OnConnected()";
  m_pSocketSink->OnConnect();  // the sink will kick off a send and other stuff
}

void VQtSocket::Write(QByteArray& data)
{
  qDebug << "VQtSocket::Write " << data.toHex();
  m_pSocket->write(data);
}

void VQtSocket::OnBytesWritten(qint64 bytes)
{
  qDebug() << "OnBytesWritten = " << bytes;  // I never see this on Linux
  ProcessWriteComplete(request, ERROR_SUCCESS);
  m_pSocketSink->OnWrite(bytes);  // this may do any number of things
}

----------
Thanks,
Robert

--
 [ signature omitted ] 

Message 2 in thread

Robert Stehwien wrote:
> I'm using Qt 4.3rc1.
> I've been unable to duplicate this with a simple application yet and
> cannot post the whole application where the problem occurs.  But the
> code should be the same on the two platforms.  Basically I've done the
> following and see the OnBytesWritten messages on Windows but not on
> Unix.
> Any tips on what could cause OnBytesWritten() not to get called on Linux?

Can you show a compilable example, please?

-- 
 [ signature omitted ] 

Message 3 in thread

Sometimes I don't catch that gmail isn't replying to
qt0interest@xxxxxxxxxxxxx and is instead replying to the poster.

---------- Forwarded message ----------
From: Robert Stehwien <rstehwien@xxxxxxxxx>
Date: May 18, 2007 4:10 PM
Subject: Re: Receive QTcpSocket::bytesWritten on Windows but not on Linux
To: Andreas Aardal Hanssen <ahanssen@xxxxxxxxxxxxx>


> > I'm using Qt 4.3rc1.
> > I've been unable to duplicate this with a simple application yet and
> > cannot post the whole application where the problem occurs.  But the
> > code should be the same on the two platforms.  Basically I've done the
> > following and see the OnBytesWritten messages on Windows but not on
> > Unix.
> > Any tips on what could cause OnBytesWritten() not to get called on Linux?
>
> Can you show a compilable example, please?
>

I'm trying to pull enough of our codebase into an example to reproduce
the problem.  I've written a tracing proxy server (just connects two
sockets and shows the traffic in hex).  The trace program doesn't have
trouble on unix (I see the bytesWritten() signal) but does show my
application isn't putting data on the wire.

The only thing I can think of that might be unusual is that write
calls are being made during connected() and readyRead() signals.
Could that cause trouble?

More as soon as I can provide it.

--
 [ signature omitted ] 

Message 4 in thread

It turns out my problem writing data on Linux using QTcpSocket wasn't
the write() call but getting data out of my IBuffer (an interface in
our code) into either a QByteArray or sending directly with write.

Below is some common code:
----------
  QTcpSocket* m_pSocket; // created and signals hooked up elsewhere
  ...
  char* pSend = reinterpret_cast<char*> pBuffer->GetPointer(); // retuns a BYTE*
  qint64 bytes = pBuffer->GetDataLength(); // returns the number of bytes
----------

This code worked on Windows, but did not work on Linux:
----------
  QByteArray send(pSend, bytes);
  m_pSocket->write(send);  // works on windows but not on Linux
  // also tried what is below as an alternative
  // m_pSocket->write(pSend, bytes); // works on windows but not on Linux
----------

Here is the code that works on Linux and Windows:
----------
  m_pSocket->write(QByteArray::fromRawData(pSend, bytes));
----------

pSend may be deleted after the write() call and before bytesWritten(),
but I expected the QByteArray constructor to do a deep copy as stated
in doc and seems to happen on Windows.

--Robert


On 5/21/07, Andreas Aardal Hanssen <ahanssen@xxxxxxxxxxxxx> wrote:
> On Saturday 19 May 2007 00:10, you wrote:
> > > Can you show a compilable example, please?
> > I'm trying to pull enough of our codebase into an example to reproduce
> > the problem.  I've written a tracing proxy server (just connects two
> > sockets and shows the traffic in hex).  The trace program doesn't have
> > trouble on unix (I see the bytesWritten() signal) but does show my
> > application isn't putting data on the wire.
> > The only thing I can think of that might be unusual is that write
> > calls are being made during connected() and readyRead() signals.
> > Could that cause trouble?
>
> No, that shouldn't cause trouble.
>
> Andreas
>
> --
> Andreas Aardal Hanssen - andreas . hanssen @ trolltech.com
> Trolltech ASA - Sandakerveien 116, NO-0484 Oslo, Norway
>

--
 [ signature omitted ]