Re: Non blocking socket query.

From: Lawrie (stroker_ace_at_hotmail.com)
Date: 04/08/05


Date: 8 Apr 2005 02:01:26 -0700


> I had a similar problem. The solution was to create a separate
persistent
> send
> data buffer for each socket connection. I would then use select to
> determine
> if any socket was ready to accept send data and then send as much as
I
> could.
> This solution requires that you do your own housekeeping on send
buffers,
> and
> you must periodically check (using select) to see if any more data
can be
> sent.

Okay, let me see If I have got this.

Inside my main loop I am doing two things:

1. Reading messages from input queue and adding them to each sockets
output buffer (Each socket instance is wrapped in a structure with
containing output buffer, status info etc).

2. Call select() with a short timeout. If any sockets are writeable
write as much data as possible to the socket.

Or in pseudo code:

do {

   check_input_queue;

   if (message arrived) {
      add_message_to each_sockets_output_buffer;
   }

   call select() with small timout.

   if (any socket is writeable)
   {
      write_as_much_data_as_possible_to_socket;
   )

} while (!fatal error)

I have one additional question:

I have set my sockets to write only using the shut function because I
want to prevent remote applications sending data to me. Is there any
way using select of detecting a remote disconnect?

Many thanks

Lawrie



Relevant Pages

  • Re: Communication speed between blocking call and non blocking cal
    ... You could use event based notification, ... When you use nonblocking I/O, the system may have to perform extra buffering ... data buffer until you say that you are done with it. ... I checked default socket buffer ...
    (microsoft.public.win32.programmer.networks)
  • Re: strange select() behavior
    ... sharing descriptors, might fill that interface buffer. ... What do you do when a blocking socket operation returns ENOBUFS? ... because it's a semantic change. ...
    (comp.unix.programmer)
  • Re: Can someone help me
    ... // contents from the server to the client public class AsynchNetworkFileServer {class ClientHandler {// constructor public ClientHandler(Socket socketForClient) {// initialize member variable socket = socketForClient; // initialize buffer to hold ... // contents of file buffer = new byte; // create the network stream networkStream = new NetworkStream; // set the file callback for reading ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH] CONFIG_PACKET_MMAP should depend on MMU
    ... The entire data buffer is allocated as one contiguous lump in NOMMU-mode. ... +#ifndef CONFIG_MMU ... * find out where the socket buffers are so that NOMMU mmap can return the ...
    (Linux-Kernel)
  • Re: Socket stuck with puts over ADSL line
    ... gets stuck with the puts command within the filevent writeable ... Is the socket configured as -blocking 1? ... local buffer would fill rapidly, ... buffered portion across the WAN as its own TCP packet, ...
    (comp.lang.tcl)