Re: [gtk-list] gdk_add_input() Question



> G'Day,
Hi

> I've come across a small hurdle with the use of gdk_add_input().
> 
> To simplify the whole problem I wrote an application which shows the
> behaviour and it is available at:
> 	http://www.uq.net.au/~zzcprows/development/

  I haven't tested it exactly in your program but I have very bad
experience with using real PIPES and do non-blockng I/O on them. Facts:

1) You NEED non-blocking I/O. Otherwise you would have to rely on GTK's
   select()/poll() behaviour and do kernel read() of 1 (only 1!) byte
   and thats' overkill - it would need userlevel/supervisor kernel switch
   on each byte of input/output data. Otherwise when there is ready only
   1 byte ready in the queue and you would do a read of 2, it simply blocks.

2) Turning PIPE to non-blocking mode:

----------------------------------------------------------------------------
void nonblock(int fd,const char *name)
{
  if (fcntl(fd,F_SETFL,O_NONBLOCK))
    FATAL(ERR,"fcntl(%s,non-blocking): %m",name);
}
----------------------------------------------------------------------------

   will cause to turn to non-blocking mode even the other side of the
   pipe. Normal applications are simply not ready for non-blocking
   behaviour of their stdio (and aren't expected/shouldn't be prepared
   for that, that's OK).
   This both-side non-blocking switch behaviour was seen on some Linux
   at least.

3) Using UNIX domain socketpair() works as expected for me. Drop that
   pipes, they're useless. I just hope that my employer doesn't kick
   me for revealing a part of non-GPLed code :-) :

----------------------------------------------------------------------------
int upsetupconn(const char *host,const char *userorport)
{
int sock;

  if (1) {
#if 0
/* hasn't worked */
int pair[2][2],i;
    for (i=0;i<2;i++)
      if (pipe(pair[i]))
        FATAL(CRIT,"pipe(): %m");
#endif
int socks[2],rc;
    if (socketpair(AF_UNIX,SOCK_STREAM,0,socks))
      FATAL(CRIT,"socketpair(AF_UNIX,SOCK_STREAM,0): %m");
    assert(!upsc_sshchildpid);
    if (!(upsc_sshchildpid=fork())) { /* SSH client */
      if (dup2(socks[1],STDIN_FILENO)!=STDIN_FILENO)
        FATAL(CRIT,"In ssh-client process dup2(sock,STD%s): %m","IN");
      if (dup2(socks[1],STDOUT_FILENO)!=STDOUT_FILENO)
        FATAL(CRIT,"In ssh-client process dup2(sock,STD%s): %m","OUT");
      if (close(socks[1]))
        FATAL(CRIT,"In ssh-client process close(sock): %m");
#define SSHARGS upsc_sshpath,upsc_sshpath,"-l",userorport, \
  "-o","BatchMode yes", \
  "-o","EscapeChar none", \
  "-o","FallBackToRsh no", \
  "-o","StrictHostKeyChecking yes", \
  "-o","UseRsh no", \
  host,M1D_BOGUS_SSH_ARG
#define SSHARGF "execl(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")"

      dbg("client: executing " SSHARGF,SSHARGS);
      rc=execl(SSHARGS,NULL);
      FATAL(ERR,"In ssh-client process " SSHARGF " returned %d: %m",SSHARGS,rc);
      }
    sshchildfd=sock=socks[0];
#if 0
    write(socks[0],"blabol\n",7);
    read(socks[0],buf,7);
    printf("got:%s\n",buf);
    FATAL(DEBUG,"DEBUG finish");
#endif
    }
  nonblock(sock,"sock");
  return(sock);
}
----------------------------------------------------------------------------



						Lace



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]