~ubuntu-branches/ubuntu/raring/znc/raring

« back to all changes in this revision

Viewing changes to Csocket.h

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2010-05-24 18:05:44 UTC
  • mfrom: (1.3.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100524180544-8e4s3f4nj0lhyw7n
Tags: 0.090~rc1-1
* New upstream release candidate.
  - Drop znc-webadmin package. It is now provided in the core source code.
  - Rename discon_kick module to disconkick.
  - Add charset and notes module.
* Add missing dependency on libc-ares-dev to znc-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
*
30
30
*
31
 
* $Revision: 1.222 $
 
31
* $Revision: 1.230 $
32
32
*/
33
33
 
34
34
// note to compile with win32 need to link to winsock2, using gcc its -lws2_32
119
119
 
120
120
#ifdef _WIN32
121
121
typedef SOCKET cs_sock_t;
 
122
#ifdef _WIN64
 
123
typedef signed __int64 cs_ssize_t;
 
124
#else
 
125
typedef signed int cs_ssize_t;
 
126
#endif  /* _WIN64 */
122
127
#define CS_INVALID_SOCK INVALID_SOCKET
123
128
#else
124
129
typedef int cs_sock_t;
 
130
typedef ssize_t cs_ssize_t;
125
131
#define CS_INVALID_SOCK -1
126
132
#endif /* _WIN32 */
127
133
 
 
134
 
128
135
#ifndef _NO_CSOCKET_NS // some people may not want to use a namespace
129
136
namespace Csocket
130
137
{
565
572
        * @param len the length of data
566
573
        *
567
574
        */
568
 
        virtual bool Write( const char *data, int len );
 
575
        virtual bool Write( const char *data, size_t len );
569
576
 
570
577
        /**
571
578
        * convience function
588
595
        * Returns READ_TIMEDOUT for a connection that timed out at the TCP level
589
596
        * Otherwise returns the bytes read into data
590
597
        */
591
 
        virtual int Read( char *data, int len );
 
598
        virtual cs_ssize_t Read( char *data, size_t len );
592
599
        CS_STRING GetLocalIP();
593
600
        CS_STRING GetRemoteIP();
594
601
 
 
602
        virtual CS_STRING ConvertAddress( void *addr, bool bIPv6 = false );
 
603
 
595
604
        //! Tells you if the socket is connected
596
605
        virtual bool IsConnected();
597
606
        //! Sets the sock, telling it its connected (internal use only)
641
650
        * pushes data up on the buffer, if a line is ready
642
651
        * it calls the ReadLine event
643
652
        */
644
 
        virtual void PushBuff( const char *data, int len, bool bStartAtZero = false );
 
653
        virtual void PushBuff( const char *data, size_t len, bool bStartAtZero = false );
645
654
 
646
655
        //! This gives access to the internal read buffer, if your
647
656
        //! not going to use ReadLine(), then you may want to clear this out
758
767
#ifdef HAVE_LIBSSL
759
768
        X509 *getX509();
760
769
 
761
 
        //! Returns The Peers Public Key
 
770
        //! Returns the peer's public key
762
771
        CS_STRING GetPeerPubKey();
 
772
        //! Returns the peer's certificate finger print
 
773
        int GetPeerFingerprint( CS_STRING & sFP);
 
774
 
763
775
        unsigned int GetRequireClientCertFlags();
764
776
        //! legacy, deprecated @see SetRequireClientCertFlags
765
777
        void SetRequiresClientCert( bool bRequiresCert );
829
841
        *
830
842
        * Ready to read data event
831
843
        */
832
 
        virtual void ReadData( const char *data, int len ) {}
 
844
        virtual void ReadData( const char *data, size_t len ) {}
833
845
        /**
834
846
        * Override these functions for an easy interface when using the Socket Manager
835
847
        * Don't bother using these callbacks if you are using this class directly (without Socket Manager)
898
910
 
899
911
 
900
912
        //! return how long it has been (in seconds) since the last read or successful write
901
 
        int GetTimeSinceLastDataTransaction( time_t iNow = 0 )
 
913
        time_t GetTimeSinceLastDataTransaction( time_t iNow = 0 )
902
914
        {
903
915
                if( m_iLastCheckTimeoutTime == 0 )
904
916
                        return( 0 );
1004
1016
        ECloseType      m_eCloseType;
1005
1017
 
1006
1018
        unsigned long long      m_iMaxMilliSeconds, m_iLastSendTime, m_iBytesRead, m_iBytesWritten, m_iStartTime;
1007
 
        unsigned int            m_iMaxBytes, m_iLastSend, m_iMaxStoredBufferLength, m_iTimeoutType;
 
1019
        unsigned int            m_iMaxBytes, m_iMaxStoredBufferLength, m_iTimeoutType;
 
1020
        size_t                          m_iLastSend;
1008
1021
 
1009
1022
        CSSockAddr              m_address, m_bindhost;
1010
1023
        bool                    m_bIsIPv6, m_bSkipConnect;
1346
1359
                                pcSock->SetIPv6( true );
1347
1360
#endif /* HAVE_IPV6 */
1348
1361
                }
 
1362
#ifdef HAVE_IPV6
 
1363
                else
 
1364
                {
 
1365
                                pcSock->SetIPv6( true );
 
1366
                }
 
1367
#endif /* HAVE_IPV6 */
1349
1368
#ifdef HAVE_LIBSSL
1350
1369
                pcSock->SetSSL( cListen.GetIsSSL() );
1351
1370
                if( ( cListen.GetIsSSL() ) && ( !cListen.GetPemLocation().empty() ) )
1487
1506
 
1488
1507
                                                CSCharBuffer cBuff( iLen );
1489
1508
 
1490
 
                                                int bytes = pcSock->Read( cBuff(), iLen );
 
1509
                                                cs_ssize_t bytes = pcSock->Read( cBuff(), iLen );
1491
1510
 
1492
1511
                                                if ( ( bytes != T::READ_TIMEDOUT ) && ( bytes != T::READ_CONNREFUSED )
1493
1512
                                                        && ( !pcSock->IsConnected() ) )
1948
1967
                                        {
1949
1968
                                                pcSock->Close();
1950
1969
                                        }
1951
 
                                        if( pcSock->GetWriteBuffer().size() )
 
1970
                                        if( !pcSock->GetWriteBuffer().empty() )
1952
1971
                                        { // this means we need to write again, not everything got knocked out
1953
1972
                                                TFD_SET( iWSock, &wfds );
1954
1973
                                                bHasWriteable = true;