mirror of
https://github.com/znc/znc.git
synced 2026-05-03 20:12:29 +02:00
Update to latest Csocket
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1766 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
48
Csocket.cpp
48
Csocket.cpp
@@ -28,7 +28,7 @@
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* $Revision: 1.123 $
|
||||
* $Revision: 1.131 $
|
||||
*/
|
||||
|
||||
#include "Csocket.h"
|
||||
@@ -965,9 +965,17 @@ bool Csock::Listen( u_short iPort, int iMaxConns, const CS_STRING & sBindHost, u
|
||||
if ( m_iReadSock == CS_INVALID_SOCK )
|
||||
return( false );
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
#ifdef IPV6_V6ONLY
|
||||
// per RFC3493#5.3
|
||||
const int on = ( m_address.GetAFRequire() == CSSockAddr::RAF_INET6 ? 1 : 0 );
|
||||
if( setsockopt( m_iReadSock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&on, sizeof( on ) ) != 0 )
|
||||
PERROR( "IPV6_V6ONLY" );
|
||||
#endif /* IPV6_V6ONLY */
|
||||
#endif /* HAVE_IPV6 */
|
||||
|
||||
m_address.SinFamily();
|
||||
m_address.SinPort( iPort );
|
||||
|
||||
if( !GetIPv6() )
|
||||
{
|
||||
if ( bind( m_iReadSock, (struct sockaddr *) m_address.GetSockAddr(), m_address.GetSockAddrLen() ) == -1 )
|
||||
@@ -1352,7 +1360,7 @@ bool Csock::AllowWrite( unsigned long long & iNOW ) const
|
||||
return( true );
|
||||
}
|
||||
|
||||
bool Csock::Write( const char *data, int len )
|
||||
bool Csock::Write( const char *data, size_t len )
|
||||
{
|
||||
m_sSend.append( data, len );
|
||||
|
||||
@@ -1369,7 +1377,7 @@ bool Csock::Write( const char *data, int len )
|
||||
|
||||
}
|
||||
// rate shaping
|
||||
u_int iBytesToSend = 0;
|
||||
u_long iBytesToSend = 0;
|
||||
|
||||
#ifdef HAVE_LIBSSL
|
||||
if( m_bssl && m_sSSLBuffer.empty() && !m_bsslEstablished )
|
||||
@@ -1414,7 +1422,7 @@ bool Csock::Write( const char *data, int len )
|
||||
if ( m_sSSLBuffer.empty() ) // on retrying to write data, ssl wants the data in the SAME spot and the SAME size
|
||||
m_sSSLBuffer.append( m_sSend.data(), iBytesToSend );
|
||||
|
||||
int iErr = SSL_write( m_ssl, m_sSSLBuffer.data(), m_sSSLBuffer.length() );
|
||||
int iErr = SSL_write( m_ssl, m_sSSLBuffer.data(), (int)m_sSSLBuffer.length() );
|
||||
|
||||
if ( ( iErr < 0 ) && ( GetSockError() == ECONNREFUSED ) )
|
||||
{
|
||||
@@ -1467,9 +1475,9 @@ bool Csock::Write( const char *data, int len )
|
||||
}
|
||||
#endif /* HAVE_LIBSSL */
|
||||
#ifdef _WIN32
|
||||
int bytes = send( m_iWriteSock, m_sSend.data(), iBytesToSend, 0 );
|
||||
ssize_t bytes = send( m_iWriteSock, m_sSend.data(), iBytesToSend, 0 );
|
||||
#else
|
||||
int bytes = write( m_iWriteSock, m_sSend.data(), iBytesToSend );
|
||||
ssize_t bytes = write( m_iWriteSock, m_sSend.data(), iBytesToSend );
|
||||
#endif /* _WIN32 */
|
||||
|
||||
if ( ( bytes == -1 ) && ( GetSockError() == ECONNREFUSED ) )
|
||||
@@ -1503,9 +1511,9 @@ bool Csock::Write( const CS_STRING & sData )
|
||||
return( Write( sData.c_str(), sData.length() ) );
|
||||
}
|
||||
|
||||
int Csock::Read( char *data, int len )
|
||||
ssize_t Csock::Read( char *data, size_t len )
|
||||
{
|
||||
int bytes = 0;
|
||||
ssize_t bytes = 0;
|
||||
|
||||
if ( ( IsReadPaused() ) && ( SslIsEstablished() ) )
|
||||
return( READ_EAGAIN ); // allow the handshake to complete first
|
||||
@@ -1525,7 +1533,7 @@ int Csock::Read( char *data, int len )
|
||||
|
||||
#ifdef HAVE_LIBSSL
|
||||
if ( m_bssl )
|
||||
bytes = SSL_read( m_ssl, data, len );
|
||||
bytes = SSL_read( m_ssl, data, (int)len );
|
||||
else
|
||||
#endif /* HAVE_LIBSSL */
|
||||
#ifdef _WIN32
|
||||
@@ -1552,7 +1560,7 @@ int Csock::Read( char *data, int len )
|
||||
#ifdef HAVE_LIBSSL
|
||||
if ( m_bssl )
|
||||
{
|
||||
int iErr = SSL_get_error( m_ssl, bytes );
|
||||
int iErr = SSL_get_error( m_ssl, (int)bytes );
|
||||
if ( ( iErr != SSL_ERROR_WANT_READ ) && ( iErr != SSL_ERROR_WANT_WRITE ) )
|
||||
return( READ_ERR );
|
||||
else
|
||||
@@ -1712,12 +1720,12 @@ bool Csock::CheckTimeout( time_t iNow )
|
||||
return( false );
|
||||
}
|
||||
|
||||
void Csock::PushBuff( const char *data, int len, bool bStartAtZero )
|
||||
void Csock::PushBuff( const char *data, size_t len, bool bStartAtZero )
|
||||
{
|
||||
if ( !m_bEnableReadLine )
|
||||
return; // If the ReadLine event is disabled, just ditch here
|
||||
|
||||
u_int iStartPos = ( m_sbuffer.empty() || bStartAtZero ? 0 : m_sbuffer.length() - 1 );
|
||||
size_t iStartPos = ( m_sbuffer.empty() || bStartAtZero ? 0 : m_sbuffer.length() - 1 );
|
||||
|
||||
if ( data )
|
||||
m_sbuffer.append( data, len );
|
||||
@@ -2334,17 +2342,19 @@ cs_sock_t Csock::CreateSocket( bool bListen )
|
||||
cs_sock_t iRet = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
#endif /* HAVE_IPV6 */
|
||||
|
||||
if ( iRet != CS_INVALID_SOCK ) {
|
||||
if ( iRet != CS_INVALID_SOCK )
|
||||
{
|
||||
set_close_on_exec( iRet );
|
||||
|
||||
if ( bListen ) {
|
||||
if ( bListen )
|
||||
{
|
||||
const int on = 1;
|
||||
|
||||
if ( setsockopt( iRet, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *)&on, sizeof( on ) ) != 0 )
|
||||
PERROR( "setsockopt" );
|
||||
if ( setsockopt( iRet, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof( on ) ) != 0 )
|
||||
PERROR( "SO_REUSEADDR" );
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
PERROR( "socket" );
|
||||
|
||||
return( iRet );
|
||||
|
||||
Reference in New Issue
Block a user