Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / ext / socket / XS / SocketBase.xs
1 #############################################################################
2 ## Name:        ext/socket/XS/SocketBase.xs
3 ## Purpose:     XS for Wx::SocketBase
4 ## Author:      Graciliano M. P.
5 ## Created:     27/02/2003
6 ## RCS-ID:      $Id: SocketBase.xs 2057 2007-06-18 23:03:00Z mbarbon $
7 ## Copyright:   (c) 2003-2004, 2006-2007 Graciliano M. P.
8 ## Licence:     This program is free software; you can redistribute it and/or
9 ##              modify it under the same terms as Perl itself
10 #############################################################################
11
12
13 MODULE=Wx PACKAGE=Wx::SocketBase
14
15 #if 0
16
17 wxSocketBase*
18 wxSocketBase::new()
19   CODE:
20     RETVAL = new wxPlSocketBase( CLASS ) ;
21   OUTPUT: RETVAL
22
23 #endif
24
25 void
26 wxSocketBase::Destroy()
27
28 bool
29 wxSocketBase::Ok()
30
31 bool
32 wxSocketBase::IsConnected()
33
34 bool
35 wxSocketBase::IsDisconnected()
36
37 bool
38 wxSocketBase::IsData()
39
40 long
41 wxSocketBase::LastCount()
42
43 void
44 wxSocketBase::Notify( notify )
45     bool notify
46     
47 void 
48 wxSocketBase::SetTimeout( seconds )
49     int seconds
50     
51 bool
52 wxSocketBase::Wait( seconds = -1 , millisecond = 0 )
53     long seconds
54     long millisecond
55
56 bool
57 wxSocketBase::WaitForRead( seconds = -1 , millisecond = 0 )
58     long seconds
59     long millisecond
60     
61 bool
62 wxSocketBase::WaitForWrite( seconds = -1 , millisecond = 0 )
63     long seconds
64     long millisecond
65     
66 long
67 wxSocketBase::Read( buf , size , leng = 0 )
68     SV* buf
69     size_t size
70     size_t leng
71   CODE:
72     // Upgrade the SV to scalar if needed. If the scalar is undef
73     // can't use SvGROW.
74     SvUPGRADE(buf , SVt_PV) ;
75     // Tell that the scalar is string only (not integer, double, utf8...):
76     SvPOK_only(buf) ;
77     
78     // Grow the scalar to receive the data and return a char* point:
79     char* buffer = SvGROW( buf , leng + size + 2 ) ;
80
81     // To read at the offset the user specified (works even if offset = 0):
82     if ( leng > 0 ) buffer += leng ;
83
84     THIS->Read( buffer , size ) ;
85     int nread = THIS->LastCount() ;
86
87     // Null-terminate the buffer, not necessary, but does not hurt:
88     buffer[nread] = 0 ;
89     // Tell Perl how long the string is:
90     SvCUR_set( buf , leng + nread ) ;
91     // Undef on read error:
92     if( THIS->Error() ) XSRETURN_UNDEF ;
93     // Return the amount of data read, like Perl read().
94     RETVAL = nread ;
95   OUTPUT: RETVAL
96
97 void
98 wxSocketBase::Close()
99
100 void
101 wxSocketBase::Discard()
102
103 bool
104 wxSocketBase::Error()
105
106 long
107 wxSocketBase::GetFlags()
108
109
110 void
111 wxSocketBase::GetLocal()
112   PPCODE:
113     wxIPV4address addr ;
114     THIS->GetLocal( addr ) ;
115     XPUSHs( sv_2mortal( newSVpv( addr.Hostname().mb_str(), 0 ) ) );
116     XPUSHs( sv_2mortal( newSViv( addr.Service() ) ) );
117
118
119 void
120 wxSocketBase::GetPeer()
121   PPCODE:
122     wxIPV4address addr ;
123     THIS->GetPeer( addr ) ;
124     XPUSHs( sv_2mortal( newSVpv( addr.Hostname().mb_str(), 0 ) ) );
125     XPUSHs( sv_2mortal( newSViv( addr.Service() ) ) );
126
127
128 void
129 wxSocketBase::InterruptWait()
130
131 long
132 wxSocketBase::LastError()
133
134 long
135 wxSocketBase::Peek(buf , size , leng = 0 )
136     SV* buf
137     size_t size
138     size_t leng
139   CODE:
140     SvUPGRADE(buf , SVt_PV) ;
141     SvPOK_only(buf) ;
142     char* buffer = SvGROW( buf , leng + size + 2 ) ;
143     if ( leng > 0 ) { buffer += leng ;}
144
145     THIS->Peek( buffer , size ) ;
146     int nread = THIS->LastCount() ;
147
148     buffer[nread] = 0 ;
149     SvCUR_set( buf , leng + nread ) ;
150     if( THIS->Error() ) XSRETURN_UNDEF ;
151     RETVAL = nread ;
152   OUTPUT: RETVAL
153
154
155 long
156 wxSocketBase::ReadMsg(buf , size , leng = 0 )
157     SV* buf
158     size_t size
159     size_t leng
160   CODE:
161     SvUPGRADE(buf , SVt_PV) ;
162     SvPOK_only(buf) ;
163     char* buffer = SvGROW( buf , leng + size + 2 ) ;
164     if ( leng > 0 ) { buffer += leng ;}
165
166     THIS->ReadMsg( buffer , size ) ;
167     int nread = THIS->LastCount() ;
168
169     buffer[nread] = 0 ;
170     SvCUR_set( buf , leng + nread ) ;
171     if( THIS->Error() ) XSRETURN_UNDEF ;
172     RETVAL = nread ;
173   OUTPUT: RETVAL
174
175
176 void
177 wxSocketBase::RestoreState()
178
179 void
180 wxSocketBase::SaveState()
181
182 void
183 wxSocketBase::SetFlags(flags)
184     long flags
185
186 void
187 wxSocketBase::SetNotify(flags)
188     long flags
189
190
191 long
192 wxSocketBase::Unread(buf , size = 0)
193     SV* buf
194     long size
195   CODE:
196     // Upgrade the SV to scalar if needed. If the scalar is undef 
197     // can't use SvGROW.
198     SvUPGRADE(buf , SVt_PV) ;
199     
200     if ( size == 0 ) { size = SvCUR(buf) ;}
201     THIS->Unread( SvPV_nolen(buf) , size ) ;
202     RETVAL = THIS->LastCount() ;
203   OUTPUT: RETVAL
204
205 bool
206 wxSocketBase::WaitForLost( seconds = -1 , millisecond = 0 )
207     long seconds
208     long millisecond
209
210 long
211 wxSocketBase::Write(buf , size = 0)
212     SV* buf
213     long size
214   CODE:
215     if ( size == 0 ) { size = SvCUR(buf) ;}
216     THIS->Write( SvPV_nolen(buf) , size ) ;
217     RETVAL = THIS->LastCount() ;
218   OUTPUT: RETVAL
219
220 long
221 wxSocketBase::WriteMsg(buf , size = 0)
222     SV* buf
223     long size
224   CODE:
225     if ( size == 0 ) { size = SvCUR(buf) ;}
226     THIS->WriteMsg( SvPV_nolen(buf) , size ) ;
227     RETVAL = THIS->LastCount() ;
228   OUTPUT: RETVAL
229
230
231 void
232 wxSocketBase::SetEventHandler( evthnd , id = wxID_ANY )
233     wxEvtHandler* evthnd
234     int id
235   CODE:
236     THIS->SetEventHandler( *evthnd , id );
237
238