RE: resetting timeout source
thank you very much! very useful!! Date: Tue, 4 Jan 2011 22:48:26 +0100 From: jardas...@gmail.com To: jpablolorenze...@hotmail.com CC: gtk-app-devel-list@gnome.org Subject: Re: resetting timeout source Well, I cannot find anything in glib. If you use linux, you can use timerfd_create() to create pollable timer, create new GSource, attach the descriptor and you got your timer. Set intervals to zero to stop it, descriptor will get no more read events, and you don't even need to detach the source from event loop. You can 'reset' the timer without stopping it first. On 12/25/2010 12:48 AM, Juan Pablo L. wrote: Hi, i m making an application which needs to perform a small task evey X secs, it will disconnect from a server if X seconds have passed without the aplication sending anything to the server, but if before completing the X secs i send something to the server i have to reset the timer for another X secs and so on like that all the time but my problem is that i can not find a way of resetting the timer without destroying and recreating the time again and again and again . which i find it too much for just the small task of resetting the timer, in other words i do not want to be freeing and getting new memory all the time i find that to be very inefficient and there should not be any need for it, so is there anyway to reset the timer without releasing its memory and getting memory all the time ? i know that if the callback function returns FALSE the source will not be added in the loop again so i guess i can just attach it again but that will only work when the time r ex pires so that will not help when the timer has not yet expired and i need to reset it for another X secs. So should know that i m attaching the timer to a non default main loop (it is a main loop inside a thread). any ideas will be very helpful. thanks!!! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: resetting timeout source
thank you very much!!! i m having a look right ! From: smspil...@gmail.com Date: Wed, 5 Jan 2011 10:33:08 +0800 Subject: Re: resetting timeout source To: jardas...@gmail.com CC: jpablolorenze...@hotmail.com; gtk-app-devel-list@gnome.org On Wed, Jan 5, 2011 at 5:48 AM, Jaroslav Šmíd jardas...@gmail.com wrote: Well, I cannot find anything in glib. If you use linux, you can use timerfd_create() to create pollable timer, create new GSource, attach the descriptor and you got your timer. Set intervals to zero to stop it, descriptor will get no more read events, and you don't even need to detach the source from event loop. You can 'reset' the timer without stopping it first. In fact, I just had to write something similar the other day - have a look at http://git.compiz.org/~dbo/compiz-with-glib-mainloop/tree/src/timer.cpp?h=glibmm-experimental#n30 (albeit it is glibmm, but you should be able to get the idea and translate it to regular glib, this is essentially what I did in reverse) On 12/25/2010 12:48 AM, Juan Pablo L. wrote: Hi, i m making an application which needs to perform a small task evey X secs, it will disconnect from a server if X seconds have passed without the aplication sending anything to the server, but if before completing the X secs i send something to the server i have to reset the timer for another X secs and so on like that all the time but my problem is that i can not find a way of resetting the timer without destroying and recreating the time again and again and again . which i find it too much for just the small task of resetting the timer, in other words i do not want to be freeing and getting new memory all the time i find that to be very inefficient and there should not be any need for it, so is there anyway to reset the timer without releasing its memory and getting memory all the time ? i know that if the callback function returns FALSE the source will not be added in the loop again so i guess i can just attach it again but that will only work when the timer ex pires so that will not help when the timer has not yet expired and i need to reset it for another X secs. So should know that i m attaching the timer to a non default main loop (it is a main loop inside a thread). any ideas will be very helpful. thanks!!! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- Sam Spilsbury ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
resetting timeout source
Hi, i m making an application which needs to perform a small task evey X secs, it will disconnect from a server if X seconds have passed without the aplication sending anything to the server, but if before completing the X secs i send something to the server i have to reset the timer for another X secs and so on like that all the time but my problem is that i can not find a way of resetting the timer without destroying and recreating the time again and again and again . which i find it too much for just the small task of resetting the timer, in other words i do not want to be freeing and getting new memory all the time i find that to be very inefficient and there should not be any need for it, so is there anyway to reset the timer without releasing its memory and getting memory all the time ? i know that if the callback function returns FALSE the source will not be added in the loop again so i guess i can just attach it again but that will only work when the timer ex pires so that will not help when the timer has not yet expired and i need to reset it for another X secs. So should know that i m attaching the timer to a non default main loop (it is a main loop inside a thread). any ideas will be very helpful. thanks!!! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
resetting timeout source
Hi, i m making an application which needs to perform a small task evey X secs, it will disconnect from a server if X seconds have passed without the aplication sending anything to the server, but if before completing the X secs i send something to the server i have to reset the timer for another X secs and so on like that all the time but my problem is that i can not find a way of resetting the timer without destroying and recreating the time again and again and again . which i find it too much for just the small task of resetting the timer, in other words i do not want to be freeing and getting new memory all the time i find that to be very inefficient and there should not be any need for it, so is there anyway to reset the timer without releasing its memory and getting memory all the time ? i know that if the callback function returns FALSE the source will not be added in the loop again so i guess i can just attach it again but that will only work when the timer ex pires so that will not help when the timer has not yet expired and i need to reset it for another X secs. So should know that i m attaching the timer to a non default main loop (it is a main loop inside a thread). any ideas will be very helpful. thanks!!! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: Is there any method to create a web interface from GTK+?
you can use Wt which is a c++ framework that lets you make web pages like coding GUI interfaces. have a look at it. http://www.webtoolkit.eu/wt From: monch...@hotmail.com To: gtk-app-devel-list@gnome.org Subject: Is there any method to create a web interface from GTK+? Date: Tue, 9 Nov 2010 17:24:56 -0600 Hi All, I have created the GUI with GTK+ in C. However, what I want is to have a web interface by embedding the GUI into an html file. In this case, I can access the GUI via a web browser from anywhere. (1) Can I do that? If yes, how? Giving me the link or example of codes would be very helpful. (2) Otherwise, do you know how to use a click button in an html file to call a C function? Now GTK+ doesn't meet what I need. I have no experience with script on an html file as well. Regards, Mike ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
gthreads vs pthread
Hello, i m using threads in a glib-only project, a service daemon, i have implemented them using GThreads, but i see now that GThreads is only a wrapper around pthreads (with the corresponding overhead from doing so) and does not provide any additional benefit (if i dont mistake the only real benefit is the cross platform feature). My application uses threads heavily, so i m not sure if i should go with pthreads or Gthread, just to clarify, i m hesitating because of the overhead of wrapping pthreads and also a more generic code, i m also 100% sure that the daemon will always run on linux or unix with a pthread implementation, regarding this, i have a few questions, i m just recently using Glib so i have no experience in other projects with glib, so i would like to know: 1. if i dont issue the g_thread_init, at the beginning of my application, will there be any problem in glib itself? some functions or functionality willl cease to work or work incorrectly ? 2. Can i just use Glib with pthread instead of GThread ? i know that the main loop and GAsyncQueue will work out of the box. 3. The documentation says that by issuing g_thread_init Glib will become thread safe, i dont understand this, if i dont issue the command Glib will not work in a multithreated environment ? 4. If in the future i use glib in another project and decided to use pthread in my code but i know GTK uses GThread inside, will this be a problem? will it be overhead because i would be using pthreads and GThread together ? 5. What would you use? why? thanks! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: poll with timeout 0 in main loop
this is almost the complete code. you can see all the flow here. basically, the main.c starts the server thread (gm_tcp_server), inside the server thread the application sits waiting for new connection, just sitting waiting consumes 100% of the CPU (without accepting any connection yet), the code of the server is in file gm_tcp_server.c. the rest of the code is just in case you need it for reference. thanks! Date: Fri, 22 Oct 2010 10:17:30 +0100 From: ch...@cvine.freeserve.co.uk To: jpablolorenze...@hotmail.com CC: maginot.jun...@gmail.com; gtk-app-devel-list@gnome.org Subject: Re: poll with timeout 0 in main loop On Fri, 22 Oct 2010 02:57:59 + Juan Pablo L. jpablolorenze...@hotmail.com wrote: hi, this is the code that makes the server socket [snip] There doesn't seem anything especially wrong with this but you have a lot of code missing. In particular, what does your tcp_server_handle_connection_events() callback do, such as when it encounters errors (you specify that the callback is to be entered in a case of G_IO_NVAL and G_IO_ERR), and how do you disconnect sources from the main loop when they are finished with (I notice also you don't unref the sources after attaching them to the main loop). Quite possibly you are looping in a case of errors or defunct sources. Probably the best thing you can do is come up with the smallest test case which demonstrates the error (with say just one socket worker thread) and post it here. This is off topic, but glib's gio makes it trivial to construct new server threads and it does all the hard stuff for you, but you need glib version 2.22 for gio's socket API. Glib's gio has no relationship with GIOChannels, despite the similar names. Chris ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: poll with timeout 0 in main loop
; } gboolean tcp_server_handle_connection_events(GIOChannel *p_source,GIOCondition p_condition,GMTCPServer *p_server) { TCPClientConnection *client = NULL; struct sockaddr_in sockaddr; socklen_t client_fd_len; int client_fd; //GError *error = NULL; int set_option = 1; if(p_condition (G_IO_IN|G_IO_PRI)) { // accept the connection now client_fd_len = sizeof(sockaddr); if((client_fd = accept(g_io_channel_unix_get_fd(p_server-socket),(struct sockaddr*)sockaddr,client_fd_len)) 0) { g_error(Could not accept new connection: %s,strerror(errno)); return TRUE; } fcntl(client_fd,F_SETFL,O_NONBLOCK);// set the socket non-blocking setsockopt(client_fd,SOL_SOCKET,SO_KEEPALIVE,set_option,sizeof(set_option));// send keep alive messages g_message(New connection attempt); // create a client connection client = gm_connection_new(client_fd,p_server); // get the address for this client if (inet_ntop(AF_INET,sockaddr.sin_addr.s_addr,client-ip,sizeof(client-ip)) != NULL) { client-port = ntohs(sockaddr.sin_port); g_message(Successfully accepted new client connection from %s:%d,client-ip,client-port); } else { client-ip[0] = 0; client-port = -1; g_message(Successfully accepted new client connection from an unknown location); } // run the connection thread client-connection_thread = g_thread_create((GThreadFunc)gm_connection_run,client,TRUE,/*error*/NULL); if(client-connection_thread == NULL) { g_error(Could not start new connection for client: %s:%d, will end this connection,client-ip,client-port); gm_connection_destroy(client); } else { // push it into the client array g_ptr_array_add(p_server-clients_list,client); g_message(Successfully started new connection); } return TRUE; } // an error happened // show an error message and try to get a description from errno g_warning(An error occurred on the server socket: %s,strerror(errno)); return TRUE; } gboolean tcp_server_remove_connection(TCPClientConnection *p_client) { // remove a client g_ptr_array_remove(p_client-my_server-clients_list,p_client); return TRUE; } and the server is astarted only once from the main thread. regarding GIO, i like to have like control of things so i m just sticking with glib, what i need from glib are the special structucures like array pointers, sometimes the strings as containers and of course, the mail loop :) Date: Fri, 22 Oct 2010 10:17:30 +0100 From: ch...@cvine.freeserve.co.uk To: jpablolorenze...@hotmail.com CC: maginot.jun...@gmail.com; gtk-app-devel-list@gnome.org Subject: Re: poll with timeout 0 in main loop On Fri, 22 Oct 2010 02:57:59 + Juan Pablo L. jpablolorenze...@hotmail.com wrote: hi, this is the code that makes the server socket [snip] There doesn't seem anything especially wrong with this but you have a lot of code missing. In particular, what does your tcp_server_handle_connection_events() callback do, such as when it encounters errors (you specify that the callback is to be entered in a case of G_IO_NVAL and G_IO_ERR), and how do you disconnect sources from the main loop when they are finished with (I notice also you don't unref the sources after attaching them to the main loop). Quite possibly you are looping in a case of errors or defunct sources. Probably the best thing you can do is come up with the smallest test case which demonstrates the error (with say just one socket worker thread) and post it here. This is off topic, but glib's gio makes it trivial to construct new server threads and it does all the hard stuff for you, but you need glib version 2.22 for gio's socket API. Glib's gio has no relationship with GIOChannels, despite the similar names. Chris ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: poll with timeout 0 in main loop
Hi Chris, yes it works without setting it as non-blocking so i decided to leave none blocking just in case .. :) anyways i was preparing the test code to send to you guys but i discovered that in the test code the cpu usage is 0% (as i would expect in the real application) ... the code i was going to send was a stripped version of the original code so that ... but there is something that might be very important but have not mention yet . i also created a GSource to run functions in other main loops (for example i use this to fire the connection cleaning code in the server when a connection dies) asynchronously, anyways, this is makes me very suspicious now: static gboolean async_callback_prepare(GSource *p_source,int *p_timeout) { AsyncCallbackSource *async_source = (AsyncCallbackSource *)p_source; gboolean ret; *p_timeout = 0; g_mutex_lock(async_source-mutex1); ret = g_queue_is_empty(async_source-callback_list); g_mutex_unlock(async_source-mutex1); return !ret; } i think i misunderstood the documentation here and maybe this is the 0 being passed to poll ??? i think i will test this in the real code and let you know asap Date: Fri, 22 Oct 2010 14:27:54 +0100 From: ch...@cvine.freeserve.co.uk To: ch...@cvine.freeserve.co.uk CC: jpablolorenze...@hotmail.com; gtk-app-devel-list@gnome.org Subject: Re: poll with timeout 0 in main loop On Fri, 22 Oct 2010 13:53:55 +0100 Chris Vine ch...@cvine.freeserve.co.uk wrote: On Fri, 22 Oct 2010 10:37:01 + Juan Pablo L. jpablolorenze...@hotmail.com wrote: i attached the code but did not make thru, here is the server code: Something odd is going on. I see you are using GIOChannel not to do any reading, but in order to notify you that a connection is available. poll()/select() of course support this in unix-like systems, but I don't know if GIOChannel does (I have never tried). Possibly it only works if you set the channel as non-blocking with g_io_channel_set_flags() rather than by manipulating the file descriptor directly, which you have done. Again, I don't know. Actually, in this usage (attaching the file descriptor of a listening socket to a main loop) there is no need to make the file descriptor non-blocking since you will not make any blocking calls on it until you actually get to call accept() to establish the connection, and you may get undefined behaviour if you do - I don't know what POSIX says about that when you attempt to use poll() with it. Once poll() indicates that a connection is available, accept() can't block anyway. Does it work if you omit your call to fctl()? Chris ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
poll with timeout 0 in main loop
Hi, i have a problem with an application i m building with glib-2.24.2 on linux, i create a server socket which i use to create a GIOChannel and add it to a main loop, everything was fine until i found that the application consumes 99.8% of the CPU while waiting for connections (doing nothing else just sitting there waiting for connections) and it gets even worse as new connections come in because i create a new loop in each connection (i create a thread for each connection) to deal with the incoming packages and each connection has N handlers to process the requests, each handler has its main loop for asynchronous communication between them and the connection thread that owns the handlers, so i did a strace and found out that the time out being passed to poll is 0 so for each iteration the poll returns inmediatly therefore i m stuck with a busy wait in all main loops, so i have read the documentation trying to find out how to modify this bahaviour but i could find nothing ab out it, can you please tell me why this is happenning ?? thanks! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list