From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28835 invoked by alias); 25 Sep 2003 13:36:50 -0000 Mailing-List: contact ecos-discuss-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@sources.redhat.com Received: (qmail 28680 invoked from network); 25 Sep 2003 13:36:34 -0000 Received: from unknown (HELO mail.frequentis.com) (213.47.210.148) by sources.redhat.com with SMTP; 25 Sep 2003 13:36:34 -0000 Received: from mail.frequentis.frq ([172.16.0.30]) by mail.frequentis.com; Thu, 25 Sep 2003 15:36:31 +0200 Received: from frqwol6ux.frequentis.frq by mail.frequentis.frq; Thu, 25 Sep 2003 15:36:00 +0200 Received: from frqvie9ux.frequentis.frq (really [172.16.2.9]) by frequentis.com via smail with esmtp (ident mail using rfc1413) id (Debian Smail3.2.0.102) for ; Thu, 25 Sep 2003 15:34:06 +0200 (CEST) Received: from ccsebits by frqvie9ux.frequentis.frq with local (Exim 3.12 #1 (Debian)) id 1A2WFy-0004Qq-00 for ; Thu, 25 Sep 2003 15:34:06 +0200 Date: Thu, 25 Sep 2003 13:36:00 -0000 From: Christoph Csebits To: ecos discuss list Message-ID: <20030925153406.A17009@frequentis.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Subject: [ECOS] accept() behaviour (out of file descriptors) X-SW-Source: 2003-09/txt/msg00464.txt.bz2 hi, i am a bit confused about how accept() works in eCos. In eCos: accept() when called directly allocates a file descriptor (with a new file pointer) and then blocks until a connection was established. When a client connects, a new socket is allocated and somehow related to the previously allocated file descriptor (and file pointer). The socket is returned and when calling accept() again it gets a new file descriptor and then blocks again. Now let us assume there are no file descriptors available. What happens is, that accept() does not block and returns -1 (errno=EMFILE) immediately. accept() "returns" EMFILE even though no client had connected. Using accept() like below, results in an endless loop (busy waiting!) (until a file descriptor is freed). for (;;) { int s; if ((s = accept(...)) < 0 ) { perror("accept"); } else { // handle connection } } In linux accept() does allocate a new file descriptor _only_after_ a connection has established. If a client connects and no file descriptor is available the connection is aborted. ("Connection closed by foreign host.") And accept() returns -1 (errno=EMFILE) and when called again it blocks until the next client wants to connect. I think this is the right way to handle such a situation. What do you think about how accept() should behave? Note that we implemented a linux-like accept() for eCos (only FreeBSD). I can send a patch if someone is interested. regards, Christoph -- -- Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos and search the list archive: http://sources.redhat.com/ml/ecos-discuss