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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,56e5e06428166864 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!news3.google.com!fu-berlin.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: problems with interfacing c Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8b6a5b24-5ab0-4d38-9be8-86911aba7fcf@k22g2000yqh.googlegroups.com> <13d5wy5ni51xh$.xnhoi3uhm9ql.dlg@40tude.net> Date: Fri, 21 Jan 2011 00:03:22 +0100 Message-ID: <10wpqz6h1md5o.1gxwql45phwmt.dlg@40tude.net> NNTP-Posting-Date: 21 Jan 2011 00:03:22 CET NNTP-Posting-Host: 11de20e8.newsspool1.arcor-online.net X-Trace: DXC=f9;9HVK5EWZ5TOT9_N5i3=`J`S[6LHn;2LCV^[];O6;fHD5cTU X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:16592 Date: 2011-01-21T00:03:22+01:00 List-Id: On Thu, 20 Jan 2011 22:31:47 +0100, Yannick Duch�ne (Hibou57) wrote: > Le Thu, 20 Jan 2011 21:56:52 +0100, Dmitry A. Kazakov > a �crit: > >> On Thu, 20 Jan 2011 12:21:08 -0800 (PST), Stoik wrote: >> >>> I need your help in finding a proper Ada code to simulate the behaviour >>> of the >>> following lines in C: >>> char *bufor = (char*)malloc(100000); >>> fread(bufor, 1, 100000, stdin); >> >> That depends on what are going to achieve. Translating the above >> literally: >> >> [ with Ada.Text_IO.Text_Streams; >> use Ada.Text_IO, Ada.Text_IO.Text_Streams; ] >> >> >> Buffer : String (1..100_000); >> begin >> String'Read (Stream (Standard_Input), Buffer); >> >> [ Which certainly nobody would do, but you didn't provide any information >> about the actual problem. ] > > Some body do, for some kind of raw IO. Just that this may be more oftenly > something like > Character'Read (Standard_Input), C); That the point, when reading characters that suggests some character stream oriented protocol. Dealing with such protocols one would never read 100K in one chunk. Because if the client does something wrong that would deadlock forever. > in a loop instead (always wondered if there is a more efficient way, I do > not know one), because most of time the buffer size may vary in 1..n (I > suppose it may vary for the OP matter too). The best way is full duplex I/O. You should always be prepared to read at least one character, so that the client is never blocked when it writes anything out. P.S. It would be nice if Ada standard library provided asynchronous in-place I/O facilities (like overlapped I/O). Ada's protected objects are perfect candidates for this abstraction (as it was done with interrupts handlers). But I doubt that would ever happen. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de