[gnet-dev] Re: Gnet work with GTK-1.3



Anthony,

Replace in gnet-private.c:

int
gnet_MainCallBack(GIOChannel *iochannel, GIOCondition condition, void
*nodata)
{
 MSG msg;

 gpointer data;
 GInetAddrAsyncState *IAstate;
 GInetAddrReverseAsyncState *IARstate;
 GTcpSocketAsyncState *TCPNEWstate;
 SocketWatchAsyncState *WatchState;

 /*Take the msg off the message queue */
 GetMessage (&msg, NULL, 0, 0);
?

With:

int
gnet_MainCallBack(GIOChannel *iochannel, GIOCondition condition, void
*nodata)
{
 MSG msg;

 gpointer data;
 GInetAddrAsyncState *IAstate;
 GInetAddrReverseAsyncState *IARstate;
 GTcpSocketAsyncState *TCPNEWstate;
 SocketWatchAsyncState *WatchState;

 /*Take the msg off the message queue */
 GetMessage (&msg, gnet_hWnd, 0, 0);
?

This will make sure that GNet will only grab it's own messages, which
should be happing anyway... I have also made the change in CVS. Please tell me if this solves your problem or not.
Thanks,

Andy
PS. Starting Wednesday I am away from my computer/email for about a
two-week vacation.


--On Monday, April 23, 2001 9:22 PM +0800 Anthony Lee
<anthonylee eLong com> wrote:

>From Anthony Lee Apr 23 2001

Dear Andrew Lanoix:

	 I have found that why the Gnet(using glib-1.3) can't work with
GTK-1.3.

	 Because of the "gnet_MainCallBack" function always try to get the
message each time
(which till message has been got). It prevents the GTK main loop.

	 So I try to use the Thread to resolve this problem.
	 The code below I have changed, but I still have a problem which I
can't get it to be passed.
If you know it, tell me how to do it please!
	 The Problem is: Before the "GetMessage" function, how can I know
"Is here message to be got?".




The gnet-private.c: (link with -lpthread)
================================


/* Thread */
GThread *gnet_message_thread = NULL;

/* Add the Mutex to protect each thread and the sign which decide whether
to run the thread */
GMutex *gnet_message_mutex = NULL;
gboolean GNet_Run_Thread_Sign = TRUE;

#if 0
int
gnet_MainCallBack(GIOChannel *iochannel, GIOCondition condition, void
*nodata)
{
#endif

void gnet_MainCallBack(gpointer data)
{
while(GNet_Run_Thread_Sign)
{
   MSG msg;

   gpointer data;
   GInetAddrAsyncState *IAstate;
   GInetAddrReverseAsyncState *IARstate;
   GTcpSocketAsyncState *TCPNEWstate;
   SocketWatchAsyncState *WatchState;

   /* Is it needed? */
   g_mutex_lock(gnet_message_mutex);


   /*

       My IDEA:
		 Before Get the Message, It must try to know " Is here
message to be got? "
		 So it will resolve the problem.
		 But I am not a window programmer. I don't know whether the
Win32 API
		 have a function to do it like the GNet function
"gnet_udp_socket_has_packet"?

      My IDEA LIKE THIS:
		 if(HaveMessageToGet())
		 {
			 GetMessage(&msg, NULL, 0, 0);
			 switch(msg.message)
			 ....
			 ....
		 }

   */

   /* Problem: ============= This still wait till it have got the Message
============ */
   /*Take the msg off the message queue */
   GetMessage (&msg, NULL, 0, 0);

   switch (msg.message)
     {
...
...
     }

     /* Is it needed ? */
     g_mutex_unlock(gnet_message_mutex);
}


#if 0
     return 1;
#endif
}

BOOL WINAPI
DllMain(HINSTANCE hinstDLL,  /* handle to DLL module */
         DWORD fdwReason,     /* reason for calling functionm */
         LPVOID lpvReserved   /* reserved */)
{
   switch(fdwReason)
     {
     case DLL_PROCESS_ATTACH:
     {
     .....
     .....
          gnet_hostent_Mutex = CreateMutex(
                                          NULL,                       /*
                                          no
security attributes */
                                          FALSE,                      /*
initially not owned */
                                          "gnet_hostent_Mutex");  /* name
                                          of
mutex */

         if (gnet_hostent_Mutex == NULL)
           {
             return FALSE;
           }

         /* GLIB Thread initalize */
         if(!g_thread_supported()) g_thread_init();

         /* create the message mutex */
	 if(!gnet_message_mutex) gnet_message_mutex = g_mutex_new();

	 /* create a new thread to pickup the WinSock Message */
         if(!gnet_message_thread)
	 {
        	 gnet_message_thread = g_thread_create(gnet_MainCallBack, 0,
0,

   TRUE, TRUE, G_THREAD_PRIORITY_NORMAL, NULL);
	 }

#if 0
         gnet_io_watch_ID = g_io_add_watch(gnet_iochannel,

(GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL),
                                           gnet_MainCallBack,
                                           NULL);
#endif

         break;
       }
     case DLL_THREAD_ATTACH:
...
     case DLL_PROCESS_DETACH:
       /* The DLL unmapped from process's address space. Do necessary
cleanup */
       {

#if 0
         g_source_remove(gnet_io_watch_ID);
#endif

	 /* To stop the thread that have been created */
	 GNet_Run_Thread_Sign = FALSE;
	 g_thread_join(gnet_message_thread);


         g_free(gnet_iochannel);
         DestroyWindow(gnet_hWnd);

         /*CleanUp WinSock 2 */
         WSACleanup();

         break;
       }
}

return TRUE;
}








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