All of lore.kernel.org
 help / color / mirror / Atom feed
* select() stress
@ 2003-03-17 15:28 Sparks, Jamie
  2003-03-17 15:43 ` Matti Aarnio
  2003-03-17 16:15 ` Richard B. Johnson
  0 siblings, 2 replies; 13+ messages in thread
From: Sparks, Jamie @ 2003-03-17 15:28 UTC (permalink / raw)
  To: linux-kernel


Hello,

  I'm running some code ported from an sgi running Irix 6.5 on a
  redhat 7.1 box: 2.4.7-10, i686.  Control hangs on a select()
  statement forever.  The select is never completed, so I can't
  check errno.

  Please reply to me personally as I'm not currently subscribed:
  jamie.sparks@cubic.com

  on sgi, the call is:

  select(getdtablehi(), &socklist, NULL, NULL, NULL);

  where socklist is declared as:  FD_SET socklist;

  on linux, there is no getdtablehi() equivalent, so I use
  getdtablesize() in its place.  getdtablehi() returns the
  number of fd's currently open and getdtablesize() returns
  the number of fd's that *can* be open.

  here's the code:

  for (;;)
  {
    printf("CLEARING sockets\n");
    FD_ZERO(&socklist); /* Always clear the structure first. */
    FD_SET(Sockfd[0], &socklist);
    FD_SET(Sockfd[1], &socklist);

    int len = -1;
    bool wasDequeued =false;
    if (!StateManager::getSaveInProgress()&& StateManager::hasQueuedPdus())
    {
      FD_ZERO(&socklist); /* Always clear the structure first. */
      pdu = StateManager::dequeuePostPduProcess();
      len = sizeof(pdu);
      wasDequeued = true;
      printf("PDU DEqueued from StateManager since Save has completed\n");
    }
    else
    {
      printf("prior to select\n");
      // orig sgi if (select(getdtablehi(), &socklist, NULL, NULL, NULL) < 0)

      /*  ****************************** */
      /*  THIS select() STATEMENT NEVER COMPLETES */
      /*  ****************************** */
      if (select(getdtablesize(), &socklist, NULL, NULL, NULL) < 0)
      {
        if (errno != EINTR) perror("WeapTerrain");
	continue;
      }

      printf("after select\n");
			}
      printf("Prior to finding which socket\n");

      for (ii=0;ii<2;ii++)
      {
        len = -1;
        if (FD_ISSET(Sockfd[ii],&socklist))
	{
          if (!ii)
	  {
            len = waitForSocketMessage(Sockfd[ii],&pdu,
	    sizeof(pdu));
	  } else if (ii)
	  {
	    len = 0;
	  }
	}

	if (wasDequeued){len = sizeof(pdu);wasDequeued=false;}

        if (len == sizeof(pdu) && StateManager::getSaveInProgress())
	{
          StateManager::queuePostPduProcess(pdu);
          printf("incoming PDU queued in StateManager since SaveInProgress\n");
	  continue;
        }

        if (len >= 0)
	{
	  printf("LEN?TYPE = %d %d\n",len, pdu.dpdu.detonation_header.type);
        }

        .
        .
        .

  Please reply to me personally as I'm not currently subscribed:
  jamie.sparks@cubic.com

  thanks,

  Jamie

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: select() stress
@ 2003-03-18 14:49 Sparks, Jamie
  2003-03-18 15:05 ` Richard B. Johnson
  0 siblings, 1 reply; 13+ messages in thread
From: Sparks, Jamie @ 2003-03-18 14:49 UTC (permalink / raw)
  To: DervishD; +Cc: Richard B. Johnson, Linux kernel

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

This message uses a character set that is not supported by the Internet
Service.  To view the original message content,  open the attached message.
If the text doesn't display correctly, save the attachment to disk, and then
open it using a viewer that can display the original character set. 
<<message.txt>> 

[-- Attachment #2: message.txt --]
[-- Type: text/plain, Size: 2010 bytes --]

Received: from GOLDENEAGLE.gameday2000 (GOLDENEAGLE [149.63.50.78]) by CURLY.ds.cubic.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
	id CTBWS181; Tue, 18 Mar 2003 06:35:50 -0800
Date: Tue, 18 Mar 2003 09:49:31 -0500 (Eastern Standard Time)
From: Jamie Sparks <jamie.sparks@cubic.com>
To: DervishD <raul@pleyades.net>
cc: "Richard B. Johnson" <root@chaos.analogic.com>, 
    Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: select() stress
In-Reply-To: <20030318144632.GB1438@DervishD>
Message-ID: <Pine.WNT.4.44.0303180946120.1424-100000@GOLDENEAGLE.gameday2000>
X-X-Sender: sparksj@curly.ds.cubic.com
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
Content-Transfer-Encoding: QUOTED-PRINTABLE


I cannot find a posix nor linux implementation of getdtablehi().

To get around it, I do the following:

int a =3D open("some_file_I_know_exists",O_RDWR);
close(a);

then use a as the 1st param to select().

perhaps it ought to be a+1?

Jamie

On Tue, 18 Mar 2003, DervishD wrote:

>       Hi Richard, again :)
>
>       In my last message I told you that getdtablesize() is not
>   reliable for closing all file descriptors, that its return value is
>   not necessarily related to the file descriptor index. Well, I forgot
>   to say that getdtablehi() effectively returns the index for the
>   largest file descriptor available to the process plus one, that is,
>   perfect for using with 'select()' and for closing all open files:
>
>       for(i=3D0; i<getdtablehi(); i++) close(i);
>
>       Is this implemented under Linux? I have a piece of software that
>   relies on the above (now it's written using getdtablesize(), which is
>   non-correct as you noted) for closing all file descriptors...
>
>       Thanks again for noting this, Richard :)
>
>       Ra=FAl N=FA=F1ez de Arenas Coronado
>
>   --
>   Linux Registered User 88736
>   http://www.pleyades.net & http://www.pleyades.net/~raulnac
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2003-03-19  4:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-17 15:28 select() stress Sparks, Jamie
2003-03-17 15:43 ` Matti Aarnio
2003-03-17 16:15 ` Richard B. Johnson
2003-03-17 18:00   ` Miquel van Smoorenburg
2003-03-17 18:24   ` Olaf Titz
2003-03-18 10:28   ` DervishD
2003-03-18 13:06     ` Richard B. Johnson
2003-03-18 14:42       ` DervishD
2003-03-18 14:46       ` DervishD
  -- strict thread matches above, loose matches on Subject: below --
2003-03-18 14:49 Sparks, Jamie
2003-03-18 15:05 ` Richard B. Johnson
2003-03-18 15:05   ` Sparks, Jamie
2003-03-19  4:18     ` Chris Friesen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.