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 _GSocket_Detected_Read(socket
);
32 if (condition
& GDK_INPUT_WRITE
)
33 _GSocket_Detected_Write(socket
);
36 int _GSocket_GUI_Init(GSocket
*socket
)
40 socket
->m_gui_dependent
= (char *)malloc(sizeof(gint
)*2);
41 m_id
= (gint
*)(socket
->m_gui_dependent
);
49 void _GSocket_GUI_Destroy(GSocket
*socket
)
51 free(socket
->m_gui_dependent
);
54 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
56 gint
*m_id
= (gint
*)(socket
->m_gui_dependent
);
59 if (socket
->m_fd
== -1)
64 case GSOCK_LOST
: /* fall-through */
65 case GSOCK_INPUT
: c
= 0; break;
66 case GSOCK_OUTPUT
: c
= 1; break;
67 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
72 gdk_input_remove(m_id
[c
]);
74 m_id
[c
] = gdk_input_add(socket
->m_fd
,
75 (c
? GDK_INPUT_WRITE
: GDK_INPUT_READ
),
80 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
82 gint
*m_id
= (gint
*)(socket
->m_gui_dependent
);
85 assert( m_id
!= NULL
);
89 case GSOCK_LOST
: /* fall-through */
90 case GSOCK_INPUT
: c
= 0; break;
91 case GSOCK_OUTPUT
: c
= 1; break;
92 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
97 gdk_input_remove(m_id
[c
]);
102 void _GSocket_Enable_Events(GSocket
*socket
)
104 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
105 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
108 void _GSocket_Disable_Events(GSocket
*socket
)
110 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
111 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
114 #else /* !wxUSE_SOCKETS */
116 /* some compilers don't like having empty source files */
117 static int wxDummyGsockVar
= 0;
119 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */