]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gsockgtk.c
added wsock32.lib (patch 880683)
[wxWidgets.git] / src / gtk1 / gsockgtk.c
CommitLineData
dbd300df
GL
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockgtk.c
4 * Purpose: GSocket: GTK part
84969af7 5 * Licence: The wxWindows licence
dbd300df
GL
6 * CVSID: $Id$
7 * -------------------------------------------------------------------------
8 */
3646fd68
VZ
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
007c77ab 13#include <assert.h>
a324a7bc 14#include <stdlib.h>
483249fc 15#include <stdio.h>
16c1f79c
RR
16
17#include <gdk/gdk.h>
18#include <glib.h>
19
d422d01e 20#include "wx/gsocket.h"
1a9469d7 21#include "wx/unix/gsockunx.h"
a324a7bc 22
483249fc
GRG
23
24void _GSocket_GDK_Input(gpointer data,
25 gint source,
26 GdkInputCondition condition)
a324a7bc
GL
27{
28 GSocket *socket = (GSocket *)data;
29
aa8fb7a0 30 if (condition & GDK_INPUT_READ)
38bb138f 31 socket->m_functions->Detected_Read(socket);
aa8fb7a0 32 if (condition & GDK_INPUT_WRITE)
38bb138f 33 socket->m_functions->Detected_Write(socket);
a324a7bc
GL
34}
35
38bb138f
VS
36int _GSocket_GUI_Init(void)
37{
38 return 1;
39}
40
41void _GSocket_GUI_Cleanup(void)
42{
43}
44
45int _GSocket_GUI_Init_Socket(GSocket *socket)
a324a7bc 46{
a324a7bc
GL
47 gint *m_id;
48
483249fc 49 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
a324a7bc
GL
50 m_id = (gint *)(socket->m_gui_dependent);
51
483249fc
GRG
52 m_id[0] = -1;
53 m_id[1] = -1;
5ff86996
GRG
54
55 return TRUE;
a324a7bc
GL
56}
57
38bb138f 58void _GSocket_GUI_Destroy_Socket(GSocket *socket)
a324a7bc 59{
a324a7bc
GL
60 free(socket->m_gui_dependent);
61}
62
39b91eca 63void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 64{
483249fc 65 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 66 int c;
a324a7bc 67
483249fc
GRG
68 if (socket->m_fd == -1)
69 return;
a324a7bc 70
483249fc
GRG
71 switch (event)
72 {
73 case GSOCK_LOST: /* fall-through */
06b466c7 74 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
75 case GSOCK_OUTPUT: c = 1; break;
76 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
77 default: return;
a324a7bc
GL
78 }
79
80 if (m_id[c] != -1)
81 gdk_input_remove(m_id[c]);
82
483249fc
GRG
83 m_id[c] = gdk_input_add(socket->m_fd,
84 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
85 _GSocket_GDK_Input,
86 (gpointer)socket);
a324a7bc
GL
87}
88
39b91eca 89void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 90{
483249fc 91 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 92 int c;
a324a7bc 93
007c77ab
RL
94 assert( m_id != NULL );
95
483249fc
GRG
96 switch (event)
97 {
98 case GSOCK_LOST: /* fall-through */
06b466c7 99 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
100 case GSOCK_OUTPUT: c = 1; break;
101 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
102 default: return;
a324a7bc
GL
103 }
104
105 if (m_id[c] != -1)
106 gdk_input_remove(m_id[c]);
107
108 m_id[c] = -1;
109}
110
483249fc 111void _GSocket_Enable_Events(GSocket *socket)
a324a7bc 112{
483249fc
GRG
113 _GSocket_Install_Callback(socket, GSOCK_INPUT);
114 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
a324a7bc
GL
115}
116
483249fc 117void _GSocket_Disable_Events(GSocket *socket)
a324a7bc 118{
483249fc
GRG
119 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
120 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
a324a7bc 121}
3646fd68 122
06b466c7
VZ
123#else /* !wxUSE_SOCKETS */
124
125/* some compilers don't like having empty source files */
126static int wxDummyGsockVar = 0;
127
128#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */