From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,95cb9cc00d809d62 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-23 09:31:26 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!colt.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Reading a C record from socket - chicken / egg problem - now complete Date: 23 Nov 2002 17:31:21 +0000 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: <5ad0dd8a.0211230443.4b476252@posting.google.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1038072685 25239 62.49.19.209 (23 Nov 2002 17:31:25 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Sat, 23 Nov 2002 17:31:25 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:31182 Date: 2002-11-23T17:31:21+00:00 List-Id: wojtek@power.com.pl (Wojtek Narczynski) writes: > I want to read a record like this: > > typedef struct { > unsigned char version; > unsigned char type; > unsigned char requestIdB1; > unsigned char requestIdB0; > unsigned char contentLengthB1; > unsigned char contentLengthB0; > unsigned char paddingLength; > unsigned char reserved; > unsigned char contentData[contentLength]; > unsigned char paddingData[paddingLength]; > } FCGI_Record; > > from socket. The 'type' field indicates different record type, so I > could declare different record types in Ada, but when I know 'type' > the record is already in memory. How should I approach this: 1. use > Unchecked_Conversion to convert to appropriate type? 2. Copy data into > a new record of appropriate type? 3. Just live with the structure C > imposes? Declare a structure corresponding to the fields version .. reserved inclusive (use Interfaces.C.unsigned_char). and read it from the socket. Calculate the actual contentLength and paddingLength. Use a declare block: declare type content is array (1 .. contentLength) of Interfaces.C.unsigned_char; type padding is array (1 .. paddingLength) of Interfaces.C.unsigned_char; type remainder is record c : content; p : padding; end record; r : remainder; begin -- read r from the socket and process it end; I know this means doing 2 reads but that's the minimum.