glib problem



hi guys, i have the following problem:

i want to create a socket and call a function whenever there is something
to read, using glib. When GIOFunc is set to return FALSE, there is no
problem with the code, but i don't want the event source to be removed.
So, i set myfunc to return TRUE but when there is something to read,
GIOFunc is called once and then i get a segmentation fault.
Can you help me with this, or suggest something else?

Here is a part of my code:
after the creation of the socket i use the following code:
--------------------------------------------------------
  myloop=g_main_new(FALSE);
  mychannel=g_io_channel_unix_new(sockfd);
  buff="something";
  g_io_channel_write(mychannel,buff,9,written);
  eventid=g_io_add_watch(mychannel,G_IO_IN,&myfunc,NULL);
  g_main_run(myloop);
  g_io_channel_close(mychannel);
---------------------------------------------------------
gboolean myfunc(GIOChannel *source, GIOCondition condition, gpointer data)
{
  gchar *buff;
  guint *readden;

  buff=g_malloc(512);
  if (g_io_channel_read(source,buff,100,readden)!=G_IO_ERROR_NONE) g_print("failed to read\n");
  g_print("read : %s\n",buff);
  if (buff=="something") g_main_quit(myloop);
  return TRUE;
}


Thanx in advance



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