Re: Network programming

From: Steve Horsley (shoot_at_the.moon)
Date: 01/16/04


Date: Fri, 16 Jan 2004 20:11:12 +0000

SS wrote:

>
>
> Ok, so this leads me to another problem then.
> Basically I need write() to be non-blocking. You can make read()
> non-blocking using setSoTimeout(), but it doesn't seem to affect
> write().
>
> For example, suppose I am streaming data from a server to a client,
> and the client for some reason stops reading, but leaves the socket
> open.
> The server eventually fills the write buffers, then gets stuck in
> write().
> I would want to be able to throw away any data that could not be
> written and timeout the server if write failure occurs for some period
> of time.
> However, as long as the client is alive, this is impossible because
> control of the server is never passed back from write().
>
> Anyone have any ideas on this?
>
> Thanks a lot.

Implement your own FIFO with a size limit that throws and Exception or
just discards the excess (your choice). The FIFO needs to be
synchronized and needs to block read() calls when empty.

Start a thread that loops reading the FIFO and writing the socket. It
will spend most of its time blocked in either read() or write().

Now just write to the FIFO rather than direct to the socket.

Steve



Relevant Pages

  • About zero-byte receive (IOCP server)
    ... My new issue is about zero-byte receives. ... "...once the zero-byte receive operation completes, the server ... can simply perform a non-blocking receive to retrieve all the data buffered ... As far as understand the excerpt, I should make the socket non-blocking ...
    (microsoft.public.win32.programmer.networks)
  • Re: select() indicates writability before a non-blocking TCP socket has actually connected
    ... notifications while the server is unavailable. ... the socket is closed and a new socket along with a new call to ... it's indicating that a writecall will not block. ... because it's a non-blocking socket. ...
    (comp.os.linux.development.apps)
  • Re: How to change connect() timeout
    ... Theres a flag for NON_BLOCK ... The problem is that when the server ... > I've tried setting the socket to be non-blocking but without success (it ...
    (comp.os.vxworks)
  • Re: RealThinClient SDK 1.8q > GPL Open Source with Demos
    ... Ok, from the client perspective it is non-blocking, but the server is still ... So, to fetch more data and/or to commit changes on the Server, you do ...
    (borland.public.delphi.thirdpartytools.general)
  • FIFO synchronization problem
    ... server gets unblocked and reads the messages sent by clients... ... first reply by the server to the client is that the command is wrong. ... int main(int argc, char *argv) ... //makes client fifo for server replies. ...
    (comp.unix.programmer)