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

Qt-interest Archive, March 2002
Problems with QSocketNotifier


Message 1 in thread

I use a QSocketNotifier but use the socket directly to read and write to TCP 
(performance problems with QSocket).

Problem:
I want to receive a file from a socket (see below). When I comment out the 
file operations it works fine. When I put in the file operations, the file is 
transferred correcly but the GUI application terminates without any message 
after it goes to the event loop again.

What's the problem ?
Is there any conflict with the file handles or is it a timing problem ?

Please help:
Rainer Lehrig

void ProcessView::downloadFile(const char *file)
{
  int   ret;
  short len;
  static char buf[4096];
  QString filename = temp + file;

  sn->setEnabled(false); // disable socket notifier
/*
#ifdef unix
  int fhdl = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP);
#endif
#ifdef _WIN32
  int fhdl = open(filename, _O_CREAT | _O_WRONLY | _O_BINARY);
#endif
  if(fhdl <= 0)
  {
    sn->setEnabled(true);
    QMessageBox::warning(this, "ProcessViewBrowser",
                 "Could not open: " + filename);
    return;
  }
*/

  while(1)
  {
    ret = tcp_rec_binary(s, (char *) &len, 2);
    if(ret == -1) break;
    len = ntohs(len);
    if(len <= 0)  break;
    if(len > (short) sizeof(buf))
    {
      QMessageBox::warning(this, "ProcessViewBrowser",
                 "buffer too small in downloadFile: " + filename);
      break;
    }
    ret = tcp_rec_binary(s, buf, len);
    if(ret == -1) break;
    //ret = write(fhdl,buf,ret);
    //if(ret == -1) break;
  }
  //close(fhdl);
  sn->setEnabled(true); // enable socket notifier again
}