17 #include "connectiontcpserver.h"
18 #include "connectiontcpclient.h"
19 #include "connectionhandler.h"
23 #include "mutexguard.h"
30 #if ( !defined( _WIN32 ) && !defined( _WIN32_WCE ) ) || defined( __SYMBIAN32__ )
31 # include <netinet/in.h>
32 # include <arpa/nameser.h>
35 # include <arpa/inet.h>
36 # include <sys/socket.h>
38 # include <sys/select.h>
43 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
45 #elif defined( _WIN32_WCE )
46 # include <winsock2.h>
53 # include <sys/types.h>
60 const std::string& ip,
int port )
62 m_connectionHandler( ch )
90 struct sockaddr_in local;
91 local.sin_family = AF_INET;
92 local.sin_port =
static_cast<unsigned short int>( htons(
m_port ) );
93 local.sin_addr.s_addr =
m_server.empty() ? INADDR_ANY : inet_addr(
m_server.c_str() );
94 memset( local.sin_zero,
'\0', 8 );
96 if( bind( m_socket, (
struct sockaddr*)&local,
sizeof(
struct sockaddr ) ) < 0 )
98 std::string message =
"bind() to " + (
m_server.empty() ? std::string(
"*" ) :
m_server )
99 +
" (" + inet_ntoa( local.sin_addr ) +
":" + util::int2string(
m_port ) +
") failed. "
100 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
101 "WSAGetLastError: " + util::int2string( ::WSAGetLastError() );
103 "errno: " + util::int2string( errno );
110 if( listen( m_socket, 10 ) < 0 )
112 std::string message =
"listen on " + (
m_server.empty() ? std::string(
"*" ) :
m_server )
113 +
" (" + inet_ntoa( local.sin_addr ) +
":" + util::int2string(
m_port ) +
") failed. "
114 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
115 "WSAGetLastError: " + util::int2string( ::WSAGetLastError() );
117 "errno: " + util::int2string( errno );
132 if( m_cancel || m_socket < 0 || !m_connectionHandler )
138 if( !dataAvailable( timeout ) )
144 struct sockaddr_in they;
145 int sin_size =
sizeof(
struct sockaddr_in );
146 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
147 int newfd =
static_cast<int>( accept( static_cast<SOCKET>( m_socket ), (
struct sockaddr*)&they, &sin_size ) );
149 int newfd = accept( m_socket, (
struct sockaddr*)&they, (socklen_t*)&sin_size );
155 ntohs( they.sin_port ) );