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()
{
TRACE;
if (m_connections.empty())
return;
ConnectionMap::iterator it;
for (it = m_connections.begin(); it != m_connections.end(); )
if (it->second->disconnect()) {
it = removeConnection(it->second->getSocket(), it++);
} else {
++it;
}
// TRACE;
//
// if (m_connections.empty())
// return;
//
// ConnectionMap::iterator it;
// for (it = m_connections.begin(); it != m_connections.end(); )
//
// /// @bug pull up closed() from TcpConnection to StreamConnection?
// if (it->second->closed()) {
// 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;
ConnectionMap::iterator next = it;
next++;
removeFd(socket);
delete it->second;
return m_connections.erase(it);
m_connections.erase(it);
return next;
}

@ -38,7 +38,7 @@ private:
Poll(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
virtual void removeTimeoutedConnections();

@ -108,6 +108,7 @@ bool Socket::bind(struct addrinfo *servinfo )
if (servinfo == 0)
return false;
/// @bug Not error message on quick re-bind error.
if (::bind(m_socket, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
LOG_BEGIN(Logger::ERR)
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;
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)

@ -25,7 +25,7 @@ public:
bool connect(addrinfo *servinfo);
bool bind(addrinfo *servinfo);
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 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;

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

@ -19,7 +19,7 @@ public:
virtual bool listen( const int maxPendingQueueLen = 64 ) = 0;
/// @todo move accept and poll here
virtual bool accept(int socket) = 0;
virtual bool accept(int& socket) = 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;
return m_socket.accept(client_socket);

@ -36,7 +36,7 @@ public:
bool bind();
bool listen( const int maxPendingQueueLen = 64 );
bool accept(int client_socket);
bool accept(int& client_socket);
int getSocket() const;
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;
return m_tcpConnection->accept(client_socket);

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

Loading…
Cancel
Save