Reading input from a file or socket



Hello all.  I've just joined the GNOME GUI bandwagon
and am working on getting my feet wet with a simple
chat client.  After a couple of nights of research
(and failed attempts with threads) I found that there
is a facility in the GDK library that can be used to
generate a callback whenever input becomes avaliable
at a socket or in a file.  Thats great but I have been
having a real hard time getting it to work.  Below is
a code snippet from an example program contained in
the GNOME/GTK+ Programming Bible that is supposed to
read in from the keyboard.  It compiles and runs just
fine but I have added checking statements (couts) to
make sure the callback is being called.  However, I
never see any terminal output or confirmation that the
callback is indeed being called.  

Here is the code snippet:  


This function is called before gtk_main
---------------------------------------
void inputSetup()
{
   int fd;
   fd=0;
   fcntl(fd,F_SETFL,0_NONBLOCK);
  
gdk_input_add(fd,GDK_INPUT_READ,(GdkInputFunction)inputCallback,NULL);

}

----------------------------------------

void inputCallback(gpointer data,gint fd,
GdkInputCondition in)
{
   cout << "Hello World";
   int i;
   gint count;
   gchar string[20];

   while((count = read(fd,string,20))>0){
        for(i=0;i<count;i++)
             putchar(string[i]);
   }

   cout << "Hello World";
}




I never see the hello world msg.  I am guessing I
should, correct?  If anyone can tell me what is going
wrong or if I am making incorrect assumptions, please
let me know.  Also, if anyone has some simple examples
I would be thrilled.

Thanks everybody.



----------------
Dave Swiston 

__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com



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