1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: GTK part
6 * -------------------------------------------------------------------------
19 #include "wx/gsocket.h"
20 #include "wx/unix/gsockunx.h"
23 void _GSocket_GDK_Input(gpointer data
,
25 GdkInputCondition condition
)
27 GSocket
*socket
= (GSocket
*)data
;
29 if (condition
& GDK_INPUT_READ
)
30 _GSocket_Detected_Read(socket
);
31 if (condition
& GDK_INPUT_WRITE
)
32 _GSocket_Detected_Write(socket
);
35 int _GSocket_GUI_Init(GSocket
*socket
)
39 socket
->m_gui_dependent
= (char *)malloc(sizeof(gint
)*2);
40 m_id
= (gint
*)(socket
->m_gui_dependent
);
48 void _GSocket_GUI_Destroy(GSocket
*socket
)
50 free(socket
->m_gui_dependent
);
53 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
55 gint
*m_id
= (gint
*)(socket
->m_gui_dependent
);
58 if (socket
->m_fd
== -1)
63 case GSOCK_LOST
: /* fall-through */
64 case GSOCK_INPUT
: c
= 0; break;
65 case GSOCK_OUTPUT
: c
= 1; break;
66 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
71 gdk_input_remove(m_id
[c
]);
73 m_id
[c
] = gdk_input_add(socket
->m_fd
,
74 (c
? GDK_INPUT_WRITE
: GDK_INPUT_READ
),
79 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
81 gint
*m_id
= (gint
*)(socket
->m_gui_dependent
);
84 assert( m_id
!= NULL
);
88 case GSOCK_LOST
: /* fall-through */
89 case GSOCK_INPUT
: c
= 0; break;
90 case GSOCK_OUTPUT
: c
= 1; break;
91 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
96 gdk_input_remove(m_id
[c
]);
101 void _GSocket_Enable_Events(GSocket
*socket
)
103 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
104 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
107 void _GSocket_Disable_Events(GSocket
*socket
)
109 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
110 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
113 #else /* !wxUSE_SOCKETS */
115 /* some compilers don't like having empty source files */
116 static int wxDummyGsockVar
= 0;
118 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */