From owner-freebsd-questions@FreeBSD.ORG Thu Nov 15 02:26:07 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 71A0816A419 for ; Thu, 15 Nov 2007 02:26:07 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.179]) by mx1.freebsd.org (Postfix) with ESMTP id 477FC13C43E for ; Thu, 15 Nov 2007 02:26:07 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: by wa-out-1112.google.com with SMTP id k17so492461waf for ; Wed, 14 Nov 2007 18:26:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=vCHxk++jC/p8OR4uDVZjEdaOQ0KFQtt3G/3zc7HPK9k=; b=CVOCBVlPeQVFC8JC8y0CWLTrNkdg6WsmMhIzAnmqrCl7XlyTl76rZ0Z6QeqeLh/qi1wocwkwXySpgkL+Yx82i9SNMAOQQB11D0bWlvj2hi4OVZFLVpO8oGsuEyolHPMItp4+sT769ddHHnzgxgya2EKFJyeg+TdZ1tXgYyaoiJk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=kyE4iUgEDs1BmvaYOhjNsr61N1pVOpPALIhzMIqq4fe3uhKN83cmeVOwBW4zF7C1wnaUbLUOEwNakchZN20j1aE8Px9rPY16musO9BrtKSWl7Kr3RBSdOdlwY3gMWdoXm5D3L6b55PmideTTVJePX0EFNZ0R6aN5UdzXm+CUJC0= Received: by 10.114.27.20 with SMTP id a20mr153157waa.1195093566379; Wed, 14 Nov 2007 18:26:06 -0800 (PST) Received: by 10.114.254.9 with HTTP; Wed, 14 Nov 2007 18:26:06 -0800 (PST) Message-ID: <340a29540711141826u6c4e1c36h3baaea0e079a46da@mail.gmail.com> Date: Wed, 14 Nov 2007 19:26:06 -0700 From: "Andrew Falanga" To: "Heiko Wundram (Beenic)" In-Reply-To: <200711150055.27132.wundram@beenic.net> MIME-Version: 1.0 References: <340a29540711141421tda33970q79f85533fb5ba725@mail.gmail.com> <200711150055.27132.wundram@beenic.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-questions@freebsd.org Subject: Re: Socket programming question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2007 02:26:07 -0000 On Nov 14, 2007 4:55 PM, Heiko Wundram (Beenic) wrote: > > Sorry to say that, but it doesn't make sense as it's worded. The > descriptor > returned by socket(2) is valid if it's >= 0 (that's the API contract for > the > socket(2) C function), and remains valid until the program ends (unless > you > close the descriptor with close(2) before your program terminates, in > which > case the descriptor first becomes invalid [i.e. EBADF], but might be > reused > later by another call to socket(2) or open(2), in which case the > descriptor > again becomes valid but is associated with another object and possibly > also > with another type of object [file/pipe vs. socket]). > > That's the API-contract that's specified in POSIX, and to which FreeBSD > sticks. As an application programmer, you can (and have to) rely on this > behaviour; any derivation from this is a kernel bug, and should be posted > as > a PR. > > Generally, the easy way to query whether a descriptor is valid is by > simply > calling the respective function you want to execute on it, and if that > returns errno = EBADF, then you know that the descriptor is invalid. In > case > it returns something else, it just tells you that the descriptor is valid, > but doesn't tell you whether the descriptor is really associated with what > you think it is. But if you follow the flow of control in the program, you > should be able to make out where the descriptor is created and how it's > modified, and thus be able to deduce (under the condition that the kernel > sticks to POSIX specifications) what the state of the descriptor is at the > time of usage. > Thanks. Actually, this suggestion of yours I think does answer my question. I was thinking that in my testing program, I would be using something like that after thinking things through. Thanks again. Andy