1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: ext/socket/cpp/socket.h
3 // Purpose: c++ wrapper for wxSocket*
4 // Author: Graciliano M. P.
7 // RCS-ID: $Id: socket.h 2057 2007-06-18 23:03:00Z mbarbon $
8 // Copyright: (c) 2003-2004 Graciliano M. P.
9 // Licence: This program is free software; you can redistribute it and/or
10 // modify it under the same terms as Perl itself
11 ///////////////////////////////////////////////////////////////////////////////
13 #include "wx/socket.h"
14 #include "cpp/v_cback.h"
16 #define DO_WRITE(CODE, sv, size) \
17 if ( size == 0 ) size = SvCUR(sv) ; \
18 char* buffer = SvPV_nolen(sv); \
20 RETVAL = THIS->LastCount() ;
22 #define DO_READ(CODE, sv, size, offset) \
23 /* Upgrade the SV to scalar if needed. If the scalar is undef */ \
24 /* can't use SvGROW. */ \
25 SvUPGRADE(sv , SVt_PV) ; \
26 /* Tell that the scalar is string only (not integer, float, utf8...): */ \
28 /* Grow the scalar to receive the data and return a char* point: */ \
29 char* buffer = SvGROW( sv , offset + size + 2 ) ; \
30 /* To read at the offset the user specified */ \
31 if ( offset > 0 ) buffer += offset ; \
34 int nread = THIS->LastCount() ; \
36 /* Null-terminate the buffer, not necessary, but does not hurt: */ \
38 /* Tell Perl how long the string is: */ \
39 SvCUR_set( sv , offset + nread ) ; \
40 /* Undef on read error: */ \
41 if( THIS->Error() ) XSRETURN_UNDEF ; \
42 /* Return the amount of data read, like Perl read(). */ \
45 class wxPlSocketBase:public wxSocketBase
47 WXPLI_DECLARE_DYNAMIC_CLASS( wxPlSocketBase );
48 WXPLI_DECLARE_V_CBACK();
50 wxPlSocketBase( const char* package )
51 : m_callback( "Wx::SocketBase" )
53 m_callback.SetSelf( wxPli_make_object( this, package ), true );
57 WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPlSocketBase , wxSocketBase );
59 ///////////////////////////////////////////////////////////////////////////////
61 class wxPliSocketClient:public wxSocketClient
63 WXPLI_DECLARE_DYNAMIC_CLASS( wxPliSocketClient );
64 WXPLI_DECLARE_V_CBACK();
66 WXPLI_DEFAULT_CONSTRUCTOR( wxPliSocketClient, "Wx::SocketClient", true );
68 // this fixes the crashes, for some reason
69 wxPliSocketClient( const char* package, long _arg1 )
70 : wxSocketClient( _arg1 ),
71 m_callback( "Wx::SocketClient" )
73 m_callback.SetSelf( wxPli_make_object( this, package ), true );
77 WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPliSocketClient , wxSocketClient );
79 ///////////////////////////////////////////////////////////////////////////////
81 class wxPlSocketServer:public wxSocketServer
83 WXPLI_DECLARE_DYNAMIC_CLASS( wxPlSocketServer );
84 WXPLI_DECLARE_V_CBACK();
86 wxPlSocketServer( const char* package , wxIPV4address _arg1 , long _arg2 )
87 : wxSocketServer( _arg1 , _arg2 ),
88 m_callback( "Wx::SocketServer" )
90 m_callback.SetSelf( wxPli_make_object( this, package ), true );
93 wxSocketBase* Accept(bool wait)
95 wxSocketBase* sock = new wxPlSocketBase( "Wx::SocketBase" );
97 sock->SetFlags(GetFlags());
99 if (!AcceptWith(*sock, wait))
109 WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPlSocketServer , wxSocketServer );
111 ///////////////////////////////////////////////////////////////////////////////
113 class wxPliDatagramSocket : public wxDatagramSocket
115 WXPLI_DECLARE_DYNAMIC_CLASS( wxPliDatagramSocket );
116 WXPLI_DECLARE_V_CBACK();
118 // WXPLI_DEFAULT_CONSTRUCTOR( wxPliDatagramSocket,
119 // "Wx::DatagramSocket", true );
121 // this fixes the crashes, for some reason
122 wxPliDatagramSocket( const char* package, wxSockAddress& _arg1,
123 wxSocketFlags _arg2 )
124 : wxDatagramSocket( _arg1, _arg2 ),
125 m_callback( "Wx::SocketClient" )
127 m_callback.SetSelf( wxPli_make_object( this, package ), true );
131 WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPliDatagramSocket , wxDatagramSocket );