File: socket.h

package info (click to toggle)
libwx-perl 1%3A0.9932-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,300 kB
  • sloc: cpp: 11,064; perl: 8,603; ansic: 711; makefile: 53
file content (135 lines) | stat: -rw-r--r-- 5,286 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
///////////////////////////////////////////////////////////////////////////////
// Name:        ext/socket/cpp/socket.h
// Purpose:     c++ wrapper for wxSocket*
// Author:      Graciliano M. P.
// Modified by:
// Created:     06/03/2003
// RCS-ID:      $Id: socket.h 2057 2007-06-18 23:03:00Z mbarbon $
// Copyright:   (c) 2003-2004 Graciliano M. P.
// Licence:     This program is free software; you can redistribute it and/or
//              modify it under the same terms as Perl itself
///////////////////////////////////////////////////////////////////////////////

#include "wx/socket.h"
#include "cpp/v_cback.h"

#define DO_WRITE(CODE, sv, size)                                             \
    if ( size == 0 ) size = SvCUR(sv) ;                                      \
    char* buffer = SvPV_nolen(sv);                                           \
    CODE ;                                                                   \
    RETVAL = THIS->LastCount() ;

#define DO_READ(CODE, sv, size, offset)                                      \
    /* Upgrade the SV to scalar if needed. If the scalar is undef */         \
    /* can't use SvGROW. */                                                  \
    SvUPGRADE(sv , SVt_PV) ;                                                 \
    /* Tell that the scalar is string only (not integer, float, utf8...): */ \
    SvPOK_only(sv) ;                                                         \
    /* Grow the scalar to receive the data and return a char* point: */      \
    char* buffer = SvGROW( sv , offset + size + 2 ) ;                        \
    /* To read at the offset the user specified */                           \
    if ( offset > 0 ) buffer += offset ;                                     \
                                                                             \
    CODE ;                                                                   \
    int nread = THIS->LastCount() ;                                          \
                                                                             \
    /* Null-terminate the buffer, not necessary, but does not hurt: */       \
    buffer[nread] = 0 ;                                                      \
    /* Tell Perl how long the string is: */                                  \
    SvCUR_set( sv , offset + nread ) ;                                       \
    /* Undef on read error: */                                               \
    if( THIS->Error() ) XSRETURN_UNDEF ;                                     \
    /* Return the amount of data read, like Perl read(). */                  \
    RETVAL = nread ;

class wxPlSocketBase:public wxSocketBase
{
    WXPLI_DECLARE_DYNAMIC_CLASS( wxPlSocketBase );
    WXPLI_DECLARE_V_CBACK();
public:
    wxPlSocketBase( const char* package )
        : m_callback( "Wx::SocketBase" )
    {
        m_callback.SetSelf( wxPli_make_object( this, package ), true );
    }
};

WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPlSocketBase , wxSocketBase );

///////////////////////////////////////////////////////////////////////////////

class wxPliSocketClient:public wxSocketClient
{
    WXPLI_DECLARE_DYNAMIC_CLASS( wxPliSocketClient );
    WXPLI_DECLARE_V_CBACK();
public:
    WXPLI_DEFAULT_CONSTRUCTOR( wxPliSocketClient, "Wx::SocketClient", true );

    // this fixes the crashes, for some reason
    wxPliSocketClient( const char* package, long _arg1 )
        : wxSocketClient( _arg1 ),
          m_callback( "Wx::SocketClient" )
    {
        m_callback.SetSelf( wxPli_make_object( this, package ), true );
    }
};

WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPliSocketClient , wxSocketClient );

///////////////////////////////////////////////////////////////////////////////

class wxPlSocketServer:public wxSocketServer
{
    WXPLI_DECLARE_DYNAMIC_CLASS( wxPlSocketServer );
    WXPLI_DECLARE_V_CBACK();
public:
    wxPlSocketServer( const char* package , wxIPV4address _arg1 , long _arg2 )
        : wxSocketServer( _arg1 , _arg2 ),
          m_callback( "Wx::SocketServer" )
    {
        m_callback.SetSelf( wxPli_make_object( this, package ), true );
    }

    wxSocketBase* Accept(bool wait)
    {
        wxSocketBase* sock = new wxPlSocketBase( "Wx::SocketBase" );

        sock->SetFlags(GetFlags());

        if (!AcceptWith(*sock, wait))
        {
            sock->Destroy();
            sock = NULL;
        }

        return sock;
    }
};

WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPlSocketServer , wxSocketServer );

///////////////////////////////////////////////////////////////////////////////

class wxPliDatagramSocket : public wxDatagramSocket
{
    WXPLI_DECLARE_DYNAMIC_CLASS( wxPliDatagramSocket );
    WXPLI_DECLARE_V_CBACK();
public:
//    WXPLI_DEFAULT_CONSTRUCTOR( wxPliDatagramSocket,
//                               "Wx::DatagramSocket", true );

    // this fixes the crashes, for some reason
    wxPliDatagramSocket( const char* package, wxSockAddress& _arg1,
                         wxSocketFlags _arg2 )
        : wxDatagramSocket( _arg1, _arg2 ),
          m_callback( "Wx::SocketClient" )
    {
        m_callback.SetSelf( wxPli_make_object( this, package ), true );
    }
};

WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPliDatagramSocket , wxDatagramSocket );

// local variables:
// mode: c++
// end: