Re: Updating display while blocked on "socket-accept-connection"

From: Lars Thomas Hansen <lth_at_cs.uoregon.edu>
Date: Thu, 13 Jun 1996 08:58:17 -0700

>I am currently writing a small STk program which acts like a server,
>that is it waits for connections on a socket and process them. The
>problem is that while this server is blocked on a
>"socket-accept-connection" call, its display isn't updated. This is
>annoying because it means that as soon as I resize the window, or
>switch to another virtual screen and come back, my server's display
>looks like garbage.
>
>So I'm looking for a nice and easy solution to this problem. Maybe
>something could be done with multiple processes but that looks like a
>very complicated solution to me.

The "easy" solution is to hack the code for accept like shown below (the
socket code is from 2.1.7, I doubt it changed much). My tasking system
for STk (see ftp://ftp.cs.uoregon/edu/pub/lth/stk-tasking-beta1.tar.Z)
does it roughly this way; you may find that code instructive, though
somewhat involved.

The following code has not been debugged, but the principle is sound.

--lars


static PRIMITIVE socket_accept_connection(SCM sock)
{
  char str[]= "socket-accept-connection";
  int s;
  int fd = SOCKET(sock)->descr;

  if (NSOCKETP(sock)) Err("socket-accept-connection: Bad socket", sock);
#ifdef NONBLOCKING_ACCEPT
  input_setup( fd );
  /* Accept I/O events until an accept() will succeed */
  while (!input_readyp()) Tk_DoOneEvent(0);
#endif
  if ((s = accept( fd, NULL, NULL)) < 0)
    system_error(str);

  set_socket_io_ports(s, sock, str);
  return UNDEFINED;
}

#ifdef NONBLOCKING_ACCEPT
static int input_flag = 0;

void io_proc( ClientData cd, int mask )
{
  input_flag = 1;
  /* Mayhap we should takedown the handler here? */
}

void input_setup( int fd )
{
  input_flag = 0;
  Tk_CreateFileHandler( fd, TK_READABLE, io_proc, (ClientData)fd );
}

int input_readyp( void )
{
  return input_flag;
}
#endif
Received on Thu Jun 13 1996 - 18:00:19 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST