RE: [gtk-list] glib problem



Hi Giaslas...
I'm using myself sockets about the way you do...
i didn't look so much at your code, but as it is an extract, I'm pretty sure
the error
you're talking about actually happens somewhere else...
I see Erik already fixed the errors of the extract, but I suppose you're
walking on a memory area
that doesn't belong to you in another part of the program...
The thing is, if you do things correctly, you will have no problem to return
TRUE.. it works perfectly fine. As weonly see an extract of the program, all
I can do is a "guess" but...
(maybe you just put an example this way and that's all.. but still (just in
case))
it seems in the logic of your extract, you're trying to send the string
"something", in the freshly open socket,
and then you're trying to read the same "something" from it, in which case
you stop the program..
Erik already told you how to do that correctly, so I won't repeat, but i'm
afraid there could be, another "level" of mistake (though correctly writen
then).
It seems you are trying to write and to read what you just wrote from the
socket... that is not what is goping to happen, unless you wrote a server
(where you connect with your socket) that actually sends you "something", or
you will never see "anything" :) not even "something"...
I'm terribly sorry if you already knew that, I certainly don't underestimate
nor anything like that.. as I said.. "just in case" now if it is the case,
there is a good chance the rest of the program logic leads you to a
segmentation fault. but it must happen somewhere else in the code. Something
you could do to accelerate your bug track is set ulimit infinite so that the
segmentation fault will let you a core to examine with gdb. (compile
with -g)
cheers..

Olivier.

-----Mensaje original-----
De: Giaslas Georgios <giaslas@ceid.upatras.gr>
Para: gtk-list@redhat.com <gtk-list@redhat.com>
Fecha: Martes, 15 de Febrero de 2000 05:16 a.m.
Asunto: [gtk-list] 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
>
>--
>To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null



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