🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3297

Re: C structs in heterogenous environments

#3297
From: Marko Asplund
Date: Thu, 01 Oct 1998 00:00
45 lines
2135 bytes
Barry Margolin wrote:
> 
> 
> You can't really assume anything.  Besides the issues you raised, there's
> also the problem of byte order within the integers.

originally i planned on solving this with htonl and ntohl functions.

> You should use a standard encoding mechanism.  Most Unix systems include
> the XDR library routines, which implement the encoding mechanism used by
> ONC RPC protocols (e.g. NFS).

yes, the XDR library routines seem suitable for my purposes. but a few
things about using the XDR routines are a bit unclear to me. for example
if i want to both send and receive data through a socket connection
using the XDR routines, the code probably looks something like this:

	...

	/* establishing the socket connection, error handling and XDR
filter 		           definition for struct netdata have been omitted */

	fp = fdopen(fd, "r+");

	xdrstdio_create(&xdrs, fp, XDR_DECODE);

	xdr_netdata(&xdrs, &data);

	xdrstdio_create(&xdrs, fp, XDR_ENCODE);

	xdr_netdata(&xdrs, &data);
	...


- do i have to fflush() the stream on the write end before trying to
read from it?

- do the xdr-routines e.g. xdrstdio_create() reserve resources (apart
from the stream allocated with fdopen()) that need to be freed? 

- when closing the connection are fclose() and close() equivalent?


--
	marko asplund
Technical Details
Message-ID: <36133D88.C0927691@mail.cern.ch>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3610F74A.A7A6BECD@mail.cern.ch> <jj7Q1.15$WG.127219@burlma1-snr1.gtei.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc89c,e19b5afbbfd1f181
X-Google-Attributes: gidfc89c,public
X-Google-Thread: 1132ff,e19b5afbbfd1f181
X-Google-Attributes: gid1132ff,public
From: Marko Asplund <aspa@mail.cern.ch>
Subject: Re: C structs in heterogenous environments
Date: 1998/10/01
Message-ID: <36133D88.C0927691@mail.cern.ch>
X-Deja-AN: 396631566
Content-Transfer-Encoding: 7bit
References: <3610F74A.A7A6BECD@mail.cern.ch> <jj7Q1.15$WG.127219@burlma1-snr1.gtei.net>
To: Barry Margolin <barmar@bbnplanet.com>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@sunnews.cern.ch
X-Trace: sunnews.cern.ch 907230846 24739 (None) 137.138.98.87
Organization: HIP
Mime-Version: 1.0
Newsgroups: comp.unix.programmer,cern.unix