Article View: comp.unix.programmer
Article #66Re: fdclose function? Or something like it?
From: Uwe Doering
Date: Tue, 21 Jul 1992 06:54
Date: Tue, 21 Jul 1992 06:54
33 lines
2101 bytes
2101 bytes
volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe) writes:
>Folks-
> I'm looking for advice on the following scenario:
>
> My routine is handed a file descriptor opened and managed by some
>calling routine. (The descriptor actually corresponds to a connected
>internet-domain socket, but hopefully that will not be relevant.) In my
>routine, I would like to do some stdio-type operations (e.g. fprintf) on
>the descriptor, so I open a stream with `stream=fdopen(fd,"w");'. Now,
>before I return to the caller, I want to free up the stream since I no
>longer need it, and since this routine may be called may times with
>the same descriptor or different descriptors, and I don't want to
>run out of streams after doing too many fdopens. However, I don't want
>to disturb the underlying descriptor, so I can't do a "fclose(stream)".
>Is there some way to "undo" an fdopen call? Something like an "fdclose"
>call that might close the stream without closing the descriptor?
You could dup() the file descriptor at the beginning of your routine,
then associate this duplicated fd with a stream via fdopen(). At the
end of your routine you can fclose() this stream without closing the
socket connection because the original fd still holds it open. So
after this you can continue to write to the socket from elsewhere
in your program via the original fd that was before passed to your
routine.
Hope that helps.
Uwe
--
Uwe Doering | INET : gemini@geminix.in-berlin.de
Berlin |----------------------------------------------------------------
Germany | UUCP : ...!unido!fub!geminix.in-berlin.de!gemini
Technical Details
Message-ID:
<JWA5Y3@geminix.in-berlin.de>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!fub!geminix.in-berlin.de!geminiReferences:
<1992Jul20.201947.21749@crd.ge.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.unix.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!fub!geminix.in-berlin.de!gemini From: gemini@geminix.in-berlin.de (Uwe Doering) Subject: Re: fdclose function? Or something like it? References: <1992Jul20.201947.21749@crd.ge.com> Organization: Private UNIX Site Date: Tue, 21 Jul 1992 06:54:46 GMT Message-ID: <JWA5Y3@geminix.in-berlin.de> Lines: 33