Re: gdk_input_add ?
- From: Havoc Pennington <hp redhat com>
- To: Ken Steen <ksteen earthlink net>
- Cc: gtk list <gtk-app-devel-list gnome org>
- Subject: Re: gdk_input_add ?
- Date: 04 Sep 2000 23:31:28 -0400
Ken Steen <ksteen earthlink net> writes:
I have a program that starts a server then forks off the client program.
Everything works fine except once the client program is executed my main
Gtk+ program freezes until it finishes the read from the client program.
I obviously am missing something. The start server function is called
from the main Gtk+ program by the user. I thought the gdk_input_add
function would only call the read_from_client function when there is
data ready to be read which in this case is only just before the client
program exits. Does anyone have any ideas on what I am missing?
read_from_client() will be called anytime there's data on the file
descriptor, so as soon as your client provides some data.
void
read_from_client(gpointer data, gint from, GdkInputCondition
condition)
{
int i;
gchar buf[1024];
struct sockaddr_un addr;
int sin_size, new_fd;
memset(&addr, '\0', sizeof(addr));
sin_size = sizeof(addr);
new_fd = accept(from, (struct sockaddr *) &addr,
&sin_size);
i = read(new_fd, buf, sizeof(buf));
I think read_from_client() is called as soon as the socket has
incoming connections; you then accept() to get a handle to read data
from, but this new_fd doesn't necessarily have data available yet.
So you need to have two input functions, one accept_client() installed
on the socket and the other read_from_client() that you attach to
new_fd after you accept().
if(i >=1)
{
if(!strcmp(buf, "SESSION OVER\n"))
{
buf isn't nul-terminated, unless the other end of the socket sent you
a nul byte.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]