1 #############################################################################
2 ## Name: ext/socket/XS/SocketBase.xs
3 ## Purpose: XS for Wx::SocketBase
4 ## Author: Graciliano M. P.
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 #############################################################################
13 MODULE=Wx PACKAGE=Wx::SocketBase
20 RETVAL = new wxPlSocketBase( CLASS ) ;
26 wxSocketBase::Destroy()
32 wxSocketBase::IsConnected()
35 wxSocketBase::IsDisconnected()
38 wxSocketBase::IsData()
41 wxSocketBase::LastCount()
44 wxSocketBase::Notify( notify )
48 wxSocketBase::SetTimeout( seconds )
52 wxSocketBase::Wait( seconds = -1 , millisecond = 0 )
57 wxSocketBase::WaitForRead( seconds = -1 , millisecond = 0 )
62 wxSocketBase::WaitForWrite( seconds = -1 , millisecond = 0 )
67 wxSocketBase::Read( buf , size , leng = 0 )
72 // Upgrade the SV to scalar if needed. If the scalar is undef
74 SvUPGRADE(buf , SVt_PV) ;
75 // Tell that the scalar is string only (not integer, double, utf8...):
78 // Grow the scalar to receive the data and return a char* point:
79 char* buffer = SvGROW( buf , leng + size + 2 ) ;
81 // To read at the offset the user specified (works even if offset = 0):
82 if ( leng > 0 ) buffer += leng ;
84 THIS->Read( buffer , size ) ;
85 int nread = THIS->LastCount() ;
87 // Null-terminate the buffer, not necessary, but does not hurt:
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().
101 wxSocketBase::Discard()
104 wxSocketBase::Error()
107 wxSocketBase::GetFlags()
111 wxSocketBase::GetLocal()
114 THIS->GetLocal( addr ) ;
115 XPUSHs( sv_2mortal( newSVpv( addr.Hostname().mb_str(), 0 ) ) );
116 XPUSHs( sv_2mortal( newSViv( addr.Service() ) ) );
120 wxSocketBase::GetPeer()
123 THIS->GetPeer( addr ) ;
124 XPUSHs( sv_2mortal( newSVpv( addr.Hostname().mb_str(), 0 ) ) );
125 XPUSHs( sv_2mortal( newSViv( addr.Service() ) ) );
129 wxSocketBase::InterruptWait()
132 wxSocketBase::LastError()
135 wxSocketBase::Peek(buf , size , leng = 0 )
140 SvUPGRADE(buf , SVt_PV) ;
142 char* buffer = SvGROW( buf , leng + size + 2 ) ;
143 if ( leng > 0 ) { buffer += leng ;}
145 THIS->Peek( buffer , size ) ;
146 int nread = THIS->LastCount() ;
149 SvCUR_set( buf , leng + nread ) ;
150 if( THIS->Error() ) XSRETURN_UNDEF ;
156 wxSocketBase::ReadMsg(buf , size , leng = 0 )
161 SvUPGRADE(buf , SVt_PV) ;
163 char* buffer = SvGROW( buf , leng + size + 2 ) ;
164 if ( leng > 0 ) { buffer += leng ;}
166 THIS->ReadMsg( buffer , size ) ;
167 int nread = THIS->LastCount() ;
170 SvCUR_set( buf , leng + nread ) ;
171 if( THIS->Error() ) XSRETURN_UNDEF ;
177 wxSocketBase::RestoreState()
180 wxSocketBase::SaveState()
183 wxSocketBase::SetFlags(flags)
187 wxSocketBase::SetNotify(flags)
192 wxSocketBase::Unread(buf , size = 0)
196 // Upgrade the SV to scalar if needed. If the scalar is undef
198 SvUPGRADE(buf , SVt_PV) ;
200 if ( size == 0 ) { size = SvCUR(buf) ;}
201 THIS->Unread( SvPV_nolen(buf) , size ) ;
202 RETVAL = THIS->LastCount() ;
206 wxSocketBase::WaitForLost( seconds = -1 , millisecond = 0 )
211 wxSocketBase::Write(buf , size = 0)
215 if ( size == 0 ) { size = SvCUR(buf) ;}
216 THIS->Write( SvPV_nolen(buf) , size ) ;
217 RETVAL = THIS->LastCount() ;
221 wxSocketBase::WriteMsg(buf , size = 0)
225 if ( size == 0 ) { size = SvCUR(buf) ;}
226 THIS->WriteMsg( SvPV_nolen(buf) , size ) ;
227 RETVAL = THIS->LastCount() ;
232 wxSocketBase::SetEventHandler( evthnd , id = wxID_ANY )
236 THIS->SetEventHandler( *evthnd , id );