From: Simon Wright <simon@pushface.org>
Subject: Re: Reading a C record from socket - chicken / egg problem - now complete
Date: 23 Nov 2002 17:31:21 +0000
Date: 2002-11-23T17:31:21+00:00 [thread overview]
Message-ID: <x7v7kf4kxau.fsf@smaug.pushface.org> (raw)
In-Reply-To: 5ad0dd8a.0211230443.4b476252@posting.google.com
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.
next prev parent reply other threads:[~2002-11-23 17:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-23 12:43 Reading a C record from socket - chicken / egg problem - now complete Wojtek Narczynski
2002-11-23 14:54 ` Robert A Duff
2002-11-23 17:31 ` Simon Wright [this message]
2002-12-05 16:54 ` Reading a C record from socket - chicken / egg problem Wojtek Narczynski
2002-11-23 18:55 ` Reading a C record from socket - chicken / egg problem - now complete SteveD
2002-11-28 21:33 ` Craig Carey
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox