accept takes a int& since it _modifies_ it

master
Denes Matetelki 12 years ago
parent 88dec03423
commit f5dbb22807

@ -117,28 +117,35 @@ void Poll::handleClient( const int socket )
void Poll::removeTimeoutedConnections() void Poll::removeTimeoutedConnections()
{ {
TRACE; // TRACE;
//
if (m_connections.empty()) // if (m_connections.empty())
return; // return;
//
ConnectionMap::iterator it; // ConnectionMap::iterator it;
for (it = m_connections.begin(); it != m_connections.end(); ) // for (it = m_connections.begin(); it != m_connections.end(); )
if (it->second->disconnect()) { //
it = removeConnection(it->second->getSocket(), it++); // /// @bug pull up closed() from TcpConnection to StreamConnection?
} else { // if (it->second->closed()) {
++it; // it = removeConnection(it->second->getSocket(), it);
} // } else {
// ++it;
// }
} }
Poll::ConnectionMap::iterator Poll::removeConnection(int socket, ConnectionMap::iterator it) Poll::ConnectionMap::iterator Poll::removeConnection(int socket, std::map< int, StreamConnection* >::iterator it)
{ {
TRACE; TRACE;
ConnectionMap::iterator next = it;
next++;
removeFd(socket); removeFd(socket);
delete it->second; delete it->second;
return m_connections.erase(it); m_connections.erase(it);
return next;
} }

@ -38,7 +38,7 @@ private:
Poll(const Poll&); Poll(const Poll&);
Poll& operator=(const Poll&); Poll& operator=(const Poll&);
typedef typename std::map< int, StreamConnection* > ConnectionMap; typedef std::map< int, StreamConnection* > ConnectionMap;
// can be overriden: behaviour alters in server/client // can be overriden: behaviour alters in server/client
virtual void removeTimeoutedConnections(); virtual void removeTimeoutedConnections();

@ -108,6 +108,7 @@ bool Socket::bind(struct addrinfo *servinfo )
if (servinfo == 0) if (servinfo == 0)
return false; return false;
/// @bug Not error message on quick re-bind error.
if (::bind(m_socket, servinfo->ai_addr, servinfo->ai_addrlen) == -1) { if (::bind(m_socket, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
LOG_BEGIN(Logger::ERR) LOG_BEGIN(Logger::ERR)
LOG_PROP("Error message", strerror(errno)) LOG_PROP("Error message", strerror(errno))
@ -132,17 +133,12 @@ bool Socket::listen(const int maxPendingQueueLen)
} }
bool Socket::accept(int client_socket) bool Socket::accept(int& client_socket)
{ {
TRACE; TRACE;
sockaddr clientAddr; sockaddr clientAddr;
socklen_t clientAddrLen; 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 ) ; client_socket = ::accept( m_socket, &clientAddr, &clientAddrLen ) ;
if ( client_socket == -1 ) { if ( client_socket == -1 ) {
LOG_BEGIN(Logger::ERR) LOG_BEGIN(Logger::ERR)

@ -25,7 +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 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 );

@ -106,7 +106,7 @@ bool SslConnection::listen( const int maxPendingQueueLen )
} }
bool SslConnection::accept(int client_socket) bool SslConnection::accept( int& client_socket )
{ {
TRACE; TRACE;

@ -39,7 +39,7 @@ public:
bool bind(); bool bind();
bool listen( const int maxPendingQueueLen = 64 ); bool listen( const int maxPendingQueueLen = 64 );
bool accept(int client_socket); bool accept( int& client_socket );
bool closed() const; bool closed() const;
int getSocket() const; int getSocket() const;

@ -19,7 +19,7 @@ public:
virtual bool listen( const int maxPendingQueueLen = 64 ) = 0; virtual bool listen( const int maxPendingQueueLen = 64 ) = 0;
/// @todo move accept and poll here /// @todo move accept and poll here
virtual bool accept(int socket) = 0; virtual bool accept(int& socket) = 0;
// virtual bool poll() = 0; // virtual bool poll() = 0;

@ -109,7 +109,7 @@ bool TcpConnection::listen( const int maxPendingQueueLen )
} }
bool TcpConnection::accept(int client_socket) bool TcpConnection::accept(int& client_socket)
{ {
TRACE; TRACE;
return m_socket.accept(client_socket); return m_socket.accept(client_socket);

@ -36,7 +36,7 @@ public:
bool bind(); bool bind();
bool listen( const int maxPendingQueueLen = 64 ); bool listen( const int maxPendingQueueLen = 64 );
bool accept(int client_socket); bool accept(int& client_socket);
int getSocket() const; int getSocket() const;
void setState(const State state); void setState(const State state);

@ -66,7 +66,7 @@ bool TimedTcpConnection::listen( const int maxPendingQueueLen )
} }
bool TimedTcpConnection::accept(int client_socket) bool TimedTcpConnection::accept(int& client_socket)
{ {
TRACE; TRACE;
return m_tcpConnection->accept(client_socket); return m_tcpConnection->accept(client_socket);

@ -48,7 +48,7 @@ public:
bool bind(); bool bind();
bool listen( const int maxPendingQueueLen = 64 ); bool listen( const int maxPendingQueueLen = 64 );
bool accept(int client_socket); bool accept(int& client_socket);
bool closed() const; bool closed() const;

Loading…
Cancel
Save