sockets and signals

1 post / 0 new
alfkil
alfkil's picture
Offline
Last seen: 4 months 1 week ago
Joined: 2011-05-10 22:02
sockets and signals

I am trying to make the libQtNetwork.so work with signals. Because I am using the newlib socket etc functions, I cannot use ISocket->WaitSelect(). So instead I am trying to get a signal via

ISocket->SocketBaseTags (SBTM_SETVAL(SBTC_SIGEVENTMASK), socketSignalMask, TAG_END);

and

ULONG temp = FD_ACCEPT | FD_CONNECT | FD_READ | FD_WRITE | FD_ERROR;
status = setsockopt(sockfd, SOL_SOCKET, SO_EVENTMASK, &temp, sizeof(temp));

The problem is, I am not getting any signals when doing this in certain places in the code.
I have constructed a subrouting that looks like this:

  1. void readsocket()
  2. {
  3. BYTE socketSignal = IExec->AllocSignal(-1);
  4. printf("[readsocket] socketSignal = %d\n", (int)socketSignal);
  5. uint32 socketSignalMask = 1 << socketSignal;
  6. //qt_socketSignalMask = socketSignalMask;
  7.  
  8. ISocket->SocketBaseTags (SBTM_SETVAL(SBTC_SIGEVENTMASK), socketSignalMask, TAG_END);
  9.  
  10. int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  11.  
  12. #define MAX_BUF 1024
  13.  
  14. int count;
  15. char buf[MAX_BUF];
  16.  
  17. int status;
  18.  
  19. struct sockaddr_in my_addr;
  20. memset(&my_addr, 0, sizeof(my_addr));
  21. my_addr.sin_family = AF_INET;
  22. my_addr.sin_port = htons(80);
  23.  
  24. #if 1
  25. struct hostent *hent = gethostbyname("www.google.com");
  26. if (!hent)
  27. printf ("gethostbyname failed!\n");
  28. memcpy(&my_addr.sin_addr, hent->h_addr_list[0], hent->h_length);
  29. #endif
  30.  
  31. status = connect(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr));
  32. if (status == -1)
  33. {
  34. perror("Connection error");
  35. printf("errno = %d\n", errno);
  36. exit(1);
  37. }
  38. printf("Connected\n");
  39.  
  40. ULONG temp = FD_ACCEPT | FD_CONNECT | FD_READ | FD_WRITE | FD_ERROR;
  41. status = setsockopt(sockfd, SOL_SOCKET, SO_EVENTMASK, &temp, sizeof(temp));
  42.  
  43. status = safewrite(sockfd, "GET www.google.com HTTP/1.0\nAccept: */*\r\n\r\n");
  44. printf("written %d bytes to socket %d\n", status, sockfd);
  45.  
  46. printf("waiting for signal 0x%x\n", socketSignalMask);
  47.  
  48. unsigned int signal = IExec->Wait(socketSignalMask);
  49. if (signal & socketSignalMask)
  50. printf("Got a SOCKET signal!\n");
  51.  
  52. count = read(sockfd, buf, MAX_BUF);
  53. printf("read %d bytes from socket %d\n", count, sockfd);
  54.  
  55. close(sockfd);
  56.  
  57. IExec->FreeSignal(socketSignal);
  58. }

And then I am placing a call to this function in various places. Strange thing is, that when placing this in some place, it reads flawlessly, but when placed in other places it fails to get the signal. Example:

bool QEventDispatcherAmiga::processEvents(QEventLoop::ProcessEventsFlags flags)
{
readsocket();
//bla-bla
}

works. But:

bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &addr, quint16 port)
{
//bla-bla
#if defined(Q_OS_SYMBIAN) || defined(Q_OS_AMIGA)
readsocket();
int connectResult = ::connect(socketDescriptor, sockAddrPtr, sockAddrSize);
//blabla
}

doesn't work. What in the world could I be doing wrong??