1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: GTK part
5 * Licence: The wxWindows licence
7 * -------------------------------------------------------------------------
20 #include "wx/gsocket.h"
21 #include "wx/unix/gsockunx.h"
24 void _GSocket_GDK_Input(gpointer data
,
26 GdkInputCondition condition
)
28 GSocket
*socket
= (GSocket
*)data
;
30 if (condition
& GDK_INPUT_READ
)
31 socket
->m_functions
->Detected_Read(socket
);
32 if (condition
& GDK_INPUT_WRITE
)
33 socket
->m_functions
->Detected_Write(socket
);
36 int _GSocket_GUI_Init(void)
41 void _GSocket_GUI_Cleanup(void)
45 int _GSocket_GUI_Init_Socket(GSocket
*socket
)
49 socket
->m_gui_dependent
= (char *)malloc(sizeof(gint
)*2);
50 m_id
= (gint
*)(socket
->m_gui_dependent
);
58 void _GSocket_GUI_Destroy_Socket(GSocket
*socket
)
60 free(socket
->m_gui_dependent
);
63 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
65 gint
*m_id
= (gint
*)(socket
->m_gui_dependent
);
68 if (socket
->m_fd
== -1)
73 case GSOCK_LOST
: /* fall-through */
74 case GSOCK_INPUT
: c
= 0; break;
75 case GSOCK_OUTPUT
: c
= 1; break;
76 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
81 gdk_input_remove(m_id
[c
]);
83 m_id
[c
] = gdk_input_add(socket
->m_fd
,
84 (c
? GDK_INPUT_WRITE
: GDK_INPUT_READ
),
89 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
91 gint
*m_id
= (gint
*)(socket
->m_gui_dependent
);
94 assert( m_id
!= NULL
);
98 case GSOCK_LOST
: /* fall-through */
99 case GSOCK_INPUT
: c
= 0; break;
100 case GSOCK_OUTPUT
: c
= 1; break;
101 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
106 gdk_input_remove(m_id
[c
]);
111 void _GSocket_Enable_Events(GSocket
*socket
)
113 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
114 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
117 void _GSocket_Disable_Events(GSocket
*socket
)
119 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
120 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
123 #else /* !wxUSE_SOCKETS */
125 /* some compilers don't like having empty source files */
126 static int wxDummyGsockVar
= 0;
128 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */