Re: FILE* behaviour over BSD sockets - how?

From: Jem Berkes (jb_at_users.pc9.org)
Date: 05/13/04


Date: 13 May 2004 15:37:27 GMT


>> The problem: I have to use a library (which I cannot modify) with an
>> API reading/writing records to FILE*. The data I have to read comes
>> through a socket. The socket has been set to blocking and I
>> successfully fdopen(socket). However, the API reads once in a while
>> incomplete records because the underlying socket calls seem to return
>> as soon as there is a packet to read but not when the whole requested
>> number of bytes has been read.
>
> I've never tried using it on sockets, but perhaps fdopen() will do the
> trick?

I had meant to try this myself on an earlier project. I just tried it now
under FreeBSD and it worked... fdopen on the socket with "r+" followed by
fgets and fprintf all worked as intended.

-- 
Jem Berkes
http://www.sysdesign.ca/


Relevant Pages

  • Re: recv blocks although socket is ready
    ... of the members of the interface in my network layer have blocking ... Only one has non-blocking semantics. ... call any socket operation and rely on the socket to block. ... Now I have to implement blocking myself in all other ...
    (microsoft.public.win32.programmer.networks)
  • Re: Async socket & active connections
    ... The "blocking = true" in the disconnect phase seems to solve the ... Socket and TcpClient, ... blocking connection somewhere down the line. ... 300K connections, enough to start worrying... ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: recv blocks although socket is ready
    ... The problem is, that in blocking mode ... select sometimes reports the socket readable and then the following ... following call to recv() blocks. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Non-blocking and semi-blocking Sockets class.
    ... There is an issues with sockets blocking and how to handle it. ... that could mean the server closed a connection for whatever reason. ... The loop uses a separate timer from the socket timeout timer. ... Anyone can suggest a good state machine design in Java? ...
    (comp.lang.java.programmer)
  • Re: Non-blocking and semi-blocking Sockets class.
    ... There is an issues with sockets blocking and how to handle it. ... that could mean the server closed a connection for whatever reason. ... The loop uses a separate timer from the socket timeout timer. ... Anyone can suggest a good state machine design in Java? ...
    (comp.lang.java.programmer)