moving accept to Socket

master
Denes Matetelki 12 years ago
parent 3bdf10fe7a
commit 3e48d5323c

@ -25,6 +25,7 @@ public:
bool connect(addrinfo *servinfo); bool connect(addrinfo *servinfo);
bool bind(addrinfo *servinfo); bool bind(addrinfo *servinfo);
bool listen( const int maxPendingQueueLen = 64 ); bool listen( const int maxPendingQueueLen = 64 );
bool accept( int &client_socket );
bool send( const void *message, const int lenght ); bool send( const void *message, const int lenght );
bool receive ( void* buffer, const int bufferLen, ssize_t *msgLen ); bool receive ( void* buffer, const int bufferLen, ssize_t *msgLen );

Binary file not shown.

@ -27,16 +27,19 @@ private:
protected: protected:
// overridig poll's behaviour // overridig poll's behaviour
virtual void acceptClient(); void acceptClient();
// overridig poll's behaviour // overridig poll's behaviour
virtual void handleClient( const int ); void handleClient( const int );
private: private:
PollerThread(const PollerThread&); PollerThread(const PollerThread&);
PollerThread& operator=(const PollerThread&); PollerThread& operator=(const PollerThread&);
// overridig poll's behaviour
void removeTimeoutedConnections();
void* run(); void* run();
SocketClient *m_tcpClient; SocketClient *m_tcpClient;

@ -10,6 +10,8 @@
#include <arpa/inet.h> // inet_ntop #include <arpa/inet.h> // inet_ntop
#include <sys/select.h> #include <sys/select.h>
#include <unistd.h>
#include <string.h> // strerror #include <string.h> // strerror
#include <errno.h> // errno #include <errno.h> // errno
@ -63,11 +65,21 @@ bool Socket::closeSocket()
{ {
TRACE; TRACE;
/// @note are the return values of shutdown and close meaningful? if (shutdown(m_socket, SHUT_RDWR) == -1) {
shutdown(m_socket, SHUT_RDWR); LOG_BEGIN(Logger::ERR)
close(m_socket); LOG_PROP("Error message", strerror(errno))
m_socket = -1; LOG_END("Could not shutdown socket.");
return false;
}
if (close(m_socket) == -1) {
LOG_BEGIN(Logger::ERR)
LOG_PROP("Error message", strerror(errno))
LOG_END("Could not close socket.");
return false;
}
m_socket = -1;
return true; return true;
} }
@ -85,14 +97,6 @@ bool Socket::connect(struct addrinfo *servinfo)
LOG_END("Could not connect to peer."); LOG_END("Could not connect to peer.");
return false; return false;
} }
std::string address, service;
if ( AddrInfo::convertNameInfo( servinfo, address, service) ) {
LOG_BEGIN(Logger::INFO)
LOG_PROP("Host", address)
LOG_PROP("Port", service)
LOG_END("Connected to peer.");
}
return true; return true;
} }
@ -110,14 +114,6 @@ bool Socket::bind(struct addrinfo *servinfo )
LOG_END("Could not bind name to socket."); LOG_END("Could not bind name to socket.");
return false; return false;
} }
std::string address, service;
if ( AddrInfo::convertNameInfo( servinfo, address, service) ) {
LOG_BEGIN(Logger::INFO)
LOG_PROP("Host", address)
LOG_PROP("Port", service)
LOG_END("Binded to socket.");
}
return true; return true;
} }
@ -136,6 +132,28 @@ bool Socket::listen ( const int maxPendingQueueLen )
} }
bool Socket::accept(int &client_socket)
{
TRACE;
sockaddr clientAddr;
socklen_t clientAddrLen;
/// @bug This needs to be investigated ASAP: if the m_socket is not used before accept, it fails.
LOG_BEGIN(Logger::INFO)
LOG_SPROP(m_socket)
LOG_END("Accept mystery.");
client_socket = ::accept( m_socket, &clientAddr, &clientAddrLen ) ;
if ( client_socket == -1 ) {
LOG_BEGIN(Logger::ERR)
LOG_PROP("Error message", strerror(errno))
LOG_END("Could not accept connection on socket.");
return false;
}
return true;
}
bool Socket::send ( const void *message, const int length ) bool Socket::send ( const void *message, const int length )
{ {
TRACE; TRACE;

@ -38,6 +38,11 @@ void SocketClient::PollerThread::handleClient( const int )
} }
void SocketClient::PollerThread::removeTimeoutedConnections()
{
}
void* SocketClient::PollerThread::run() void* SocketClient::PollerThread::run()
{ {
TRACE; TRACE;

Loading…
Cancel
Save