home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / sun / misc / 6076 < prev    next >
Encoding:
Text File  |  1992-12-30  |  4.7 KB  |  157 lines

  1. Xref: sparky comp.sys.sun.misc:6076 comp.unix.bsd:10777 comp.unix.programmer:5802 comp.unix.questions:15068 comp.unix.wizards:5348
  2. Newsgroups: comp.sys.sun.misc,comp.unix.bsd,comp.unix.programmer,comp.unix.questions,comp.unix.wizards
  3. Path: sparky!uunet!spool.mu.edu!yale.edu!ira.uka.de!Sirius.dfn.de!rrz.uni-koeln.de!unidui!uniol!Torge.Schmidt
  4. From: Torge.Schmidt@arbi.informatik.uni-oldenburg.de (Torge Schmidt)
  5. Subject: asynchronous socket i/o doesn't work
  6. Organization: University of Oldenburg, Germany
  7. Date: Wed, 30 Dec 1992 23:08:18 GMT
  8. Message-ID: <1992Dec30.230633.18551@arbi.Informatik.Uni-Oldenburg.DE>
  9. Sender: news@arbi.Informatik.Uni-Oldenburg.DE
  10. Lines: 145
  11.  
  12.  
  13. Hi there!
  14.  
  15. I'm trying to program an application using asynchronous socket
  16. i/o. I do the work on an ODT 1.1 (= SCO Unix SysV R3.2.2) PC
  17. simultanously to a SPARC 1+ running SunOS 4.1.2. 
  18.  
  19. A data server waits for connections (accept()). If it gets one,
  20. about 4400 byte of data is sent to the data client in one
  21. message. (I tried write()/read() and send()/recv(), both yield
  22. the same result). The data client will be a X-Application, so it
  23. will loop in XNextEvent(). But in regular intervalls, the data
  24. server sends updated infos, which should be received and
  25. processed by the client immediately, hence asynchronous i/o. I
  26. followed the procedure described in 'Network Programmers Guide'
  27. from AT&T (actually, the title is german, so don't be confused, if
  28. you never heard about) and the SunOS-Answerbook (which shows the
  29. same info as given by AT&T). The problem is, the client never
  30. receives the SIGIO (on SunOS) / SIGPOLL (on ODT) signal. If I send the
  31. signal manually to the client, it works for this instance. 
  32.  
  33. Here is an excerpt of the code of the client.
  34. main () {
  35.     ...
  36.     establish_connection(...);    /* sets up socket an signal handler
  37.                                 (see below) */
  38.     pause();                    /* wait for signal */
  39.     display_received_data();
  40.     ...
  41. }
  42.  
  43.  
  44.  
  45. now the interesting part, the socket-initializing-routine:
  46.  
  47.  
  48. /*
  49. **    Verbindung aufbauen
  50. */
  51. void
  52. establish_connection (
  53.     ...
  54.     )
  55. {
  56.     ...
  57.  
  58.     /* Socket bereitstellen */
  59.     sock    =  socket (hostp->h_addrtype, SOCK_STREAM, 0);
  60.     if (sock < 0)
  61.         FATAL ("establish_connection", "socket", "");
  62.  
  63.  
  64. /* i suspected connect() and the first recv() being processed
  65. before the signal handler was set up, so I moved connect() behind
  66. the initialization. no success */
  67.  
  68.     /* Socket non-blocking machen */
  69.  
  70. /* this should not be necessary, as the client gets informed, when we get
  71. data. Nevertheless, if I remove it, it won't work either */
  72.  
  73.     if (fcntl (sock, F_SETFL, (fcntl (sock, F_GETFL, 0) | O_NDELAY)) == -1)
  74.         FATAL ("establish_connection", "fcntl", "setting socket non-blocking");
  75.  
  76.     /* Das Erscheinen von Nachrichten auf dem Socket erkennen */
  77.     TESTLOG ("establish_connection", "setting signal handler for asynchronous socket i/o");
  78.  
  79.     signal (
  80. #ifdef    sun
  81.         SIGIO
  82. #else
  83.         SIGPOLL
  84. #endif
  85.         , data_arrived        /* Handler */
  86.         );
  87.     
  88. /* neither process id (positive pid) nor process group id
  89. (negative pid) worked in the following */
  90.  
  91.  
  92.     {    int p    =  - getpid ();
  93.         char    t [1000];
  94.  
  95.  
  96. /* yeah, fcntl (sock, F_SETOWN, p) is the normal way (with
  97. SunOS), but it didn't do it either */
  98.  
  99.  
  100.         if (ioctl (sock, SIOCSPGRP, (char *) &p) < 0)
  101.             FATAL ("establish_connection", "ioctl (SIOCSPGRP)"
  102.                 , "setting process group id for asynchronous socket i/o");
  103.  
  104.         if (ioctl (sock, SIOCGPGRP, &p))
  105.             FATAL ("establish_connection", "ioctl(SIOCGPGRP)"
  106.                 , "getting process group id for asynchronous socket i/o");
  107.  
  108.         sprintf (t, "process id of socket %d: %d"
  109.             , sock, p
  110.             );
  111.         
  112.         TESTLOG ("establish_connection()", t);
  113.     }
  114.  
  115.     
  116. #ifdef    sun
  117.     
  118.     if (fcntl (sock, F_SETFL, fcntl (sock, F_GETFL, 0) | FASYNC) < 0)
  119.         FATAL ("establish_connection", "fcntl", "enabling asynchronous socket i/o");
  120.  
  121. #else
  122.  
  123.     {    int    on    =  1;
  124.  
  125.         if (ioctl (sock, FIOASYNC, &on) < 0)
  126.             FATAL ("establish_connection", "ioctl (FIOASYNC)", "enabling asynchronous socket i/o");
  127.  
  128.  
  129. /* desperation: trying STREAMS-ioctl()
  130. */
  131.  
  132.         if (ioctl (sock, I_SETSIG, S_INPUT) < 0)
  133.             FATAL ("establish_connection", "ioctl (I_SETSIG)", "enabling asynchronous socket i/o");
  134.     }
  135.  
  136. #endif
  137.  
  138.     /* Verbindung aufbauen */
  139.     if (connect(sock, &sock_addr, sizeof (sock_addr)) < 0)
  140.         FATAL ("establish_connection", "connect", "");
  141. }
  142.  
  143.  
  144. Well, that's it. Any ideas what I am doing wrong? If so, please
  145. reply via email, as I haven't much time these days (guess why).
  146.  
  147. Thanx and a happy new year,
  148. -- 
  149. Torge
  150.  
  151. -----------------------------------------------------------------------------
  152. Torge  Schmidt,  FB  10   Informatik,    Uni  Oldenburg,    D-2900  Oldenburg
  153. Privat  : Stadskanaal 3,  D-2804 Lilienthal,  04298/55 33 (Anrufbeantworter!)
  154. InterNet: Torge.Schmidt@arbi.informatik.uni-oldenburg.de IRC/Nightfall: Moram
  155. -----------------------------------------------------------------------------
  156. A signature ny is a projection from a set I into the set N.
  157.