master
Denes Matetelki 12 years ago
commit 91a1193543

@ -3,6 +3,7 @@ project (CPP_UTILS_LIB)
add_subdirectory (build)
add_subdirectory (test EXCLUDE_FROM_ALL)
add_subdirectory (other EXCLUDE_FROM_ALL)
find_package(Doxygen)
if(DOXYGEN_FOUND)

@ -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();

@ -101,6 +101,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))
@ -125,7 +126,7 @@ bool Socket::listen(const int maxPendingQueueLen)
}
bool Socket::accept(int client_socket)
bool Socket::accept(int& client_socket)
{
TRACE;
sockaddr clientAddr;

@ -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;

@ -0,0 +1,28 @@
set (CXX_FLAGS "-Wall -Wextra -pedantic -Weffc++ -Wshadow "
"-Wpointer-arith -Wcast-qual "
"-ggdb -fprofile-arcs -ftest-coverage --std=c++0x " )
add_definitions( ${CXX_FLAGS} )
include_directories (. ../lib)
add_executable ( tcpserver tcpserver_main.cpp )
target_link_libraries ( tcpserver CppUtils )
add_executable ( tcpclient tcpclient_main.cpp )
target_link_libraries ( tcpclient CppUtils )
add_executable ( sslserver sslserver_main.cpp )
target_link_libraries ( sslserver CppUtils ssl pthread rt )
add_executable ( sslclient sslclient_main.cpp )
target_link_libraries ( sslclient CppUtils ssl pthread rt )
add_executable ( mysqlclient mysqlclient_main.cpp )
add_library ( lib_mysql_client SHARED IMPORTED )
# TODO use find_library
set_target_properties ( lib_mysql_client PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libmysqlclient.so )
target_link_libraries ( mysqlclient CppUtils lib_mysql_client )
add_custom_target( other DEPENDS tcpserver tcpclient sslserver sslclient mysqlclient )

@ -1,12 +1,15 @@
#!/bin/bash
INCLUDE_DIR="../include"
WORKING_DIR=`pwd`
INCLUDE_DIR="$WORKING_DIR/../lib"
LIB_DIR=/home/denes/projects/cpp_utils/cpp_utils/build
GCC_OPTIONS="-Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-qual -ggdb -Weffc++ -std=c++0x"
GCC="/usr/lib/colorgcc/bin/g++"
GCC="g++"
BUILD_DIR="tmp/"
BUILD_DIR="$WORKING_DIR/tmp"
for SRC_FILE in $(ls ../src/*.cpp)
for SRC_FILE in $(ls $INCLUDE_DIR/cpp_utils/*.cpp)
do
echo "Compiling $SRC_FILE"
$GCC -c $SRC_FILE -I$INCLUDE_DIR $GCC_OPTIONS
@ -25,16 +28,16 @@ cd $BUILD_DIR
echo "Linking tcpclient_main.o"
$GCC tcpclient_main.o Logger.o SocketClient.o TcpConnection.o Socket.o AddrInfo.o Connection.o Thread.o Poll.o -lpthread -o tcpclient
$GCC tcpclient_main.o -L$LIB_DIR -lCppUtils -lpthread -o tcpclient
echo "Linking tcpserver_main.o"
$GCC tcpserver_main.o Logger.o SocketServer.o TcpConnection.o Socket.o AddrInfo.o Connection.o Thread.o Poll.o -lpthread -o tcpserver
$GCC tcpserver_main.o -L$LIB_DIR -lCppUtils -lpthread -o tcpserver
echo "Linking sslclient_main.o"
$GCC sslclient_main.o Logger.o SocketClient.o TimerUser.o Timer.o TimedTcpConnection.o TcpConnection.o Socket.o AddrInfo.o Connection.o Thread.o Poll.o SslConnection.o -lpthread -lssl -lrt -o sslclient
$GCC sslclient_main.o -L$LIB_DIR -lCppUtils -lpthread -lssl -lrt -o sslclient
echo "Linking sslserver_main.o"
$GCC sslserver_main.o Logger.o SocketServer.o TimerUser.o Timer.o TimedTcpConnection.o TcpConnection.o Socket.o AddrInfo.o Connection.o Thread.o Poll.o SslConnection.o -lpthread -lssl -lrt -o sslserver
$GCC sslserver_main.o -L$LIB_DIR -lCppUtils -lpthread -lssl -lrt -o sslserver
echo "Linking mysqlclient_main.o"
$GCC mysqlclient_main.o Logger.o ArgParse.o ConditionVariable.o ScopedLock.o MysqlClient.o Mutex.o MysqlConnectionPool.o -lrt -lpthread -L/usr/lib/mysql -lmysqlclient -o mysqlclient
$GCC mysqlclient_main.o -L$LIB_DIR -lCppUtils -lrt -lpthread -L/usr/lib/mysql -lmysqlclient -o mysqlclient

@ -1,12 +1,12 @@
// g++ mysqlclient_main.cpp src/Logger.cpp src/MysqlClient.cpp src/ArgParse.cpp -I./include -lmysqlclient
#include "Logger.hpp"
#include "Common.hpp"
#include <cpp_utils/Logger.hpp>
#include <cpp_utils/Common.hpp>
#include "ArgParse.hpp"
#include "MysqlClient.hpp"
#include "MysqlConnectionPool.hpp"
#include <cpp_utils/ArgParse.hpp>
#include <cpp_utils/MysqlClient.hpp>
#include <cpp_utils/MysqlConnectionPool.hpp>
#include <string>
#include <list>

@ -1,10 +1,10 @@
#include "Logger.hpp"
#include <cpp_utils/Logger.hpp>
#include "Message.hpp"
#include "SslConnection.hpp"
#include "SocketClient.hpp"
#include <cpp_utils/Message.hpp>
#include <cpp_utils/SslConnection.hpp>
#include <cpp_utils/SocketClient.hpp>
#include "../test/SimpleMessage.hpp"
#include "../test/cpp_utils/SimpleMessage.hpp"
#include <unistd.h>
@ -12,7 +12,8 @@
#include <string>
#include <time.h> // nanosleep
#include <Common.hpp>
// #include <Common.hpp>
int main(int argc, char* argv[] )

@ -1,11 +1,11 @@
// gpp sslserver_main.cpp -o sslserver -I../include ../src/Logger.cpp ../src/Socket.cpp -ggdb ../src/SocketServer.cpp ../src/Connection.cpp ../src/Poll.cpp ../src/TcpConnection.cpp ../src/SslConnection.cpp -lssl -lcrypto ../src/Addrinfo.cpp
#include "Logger.hpp"
#include "Common.hpp"
#include <cpp_utils/Logger.hpp>
#include <cpp_utils/Common.hpp>
#include "Message.hpp"
#include "SslConnection.hpp"
#include "SocketServer.hpp"
#include <cpp_utils/Message.hpp>
#include <cpp_utils/SslConnection.hpp>
#include <cpp_utils/SocketServer.hpp>
#include <iostream>

@ -1,9 +1,9 @@
#include "Logger.hpp"
#include "Common.hpp"
#include <cpp_utils/Logger.hpp>
#include <cpp_utils/Common.hpp>
#include "Message.hpp"
#include "TcpConnection.hpp"
#include "SocketClient.hpp"
#include <cpp_utils/Message.hpp>
#include <cpp_utils/TcpConnection.hpp>
#include <cpp_utils/SocketClient.hpp>
#include <iostream>

@ -1,9 +1,9 @@
#include "Logger.hpp"
#include "Common.hpp"
#include <cpp_utils/Logger.hpp>
#include <cpp_utils/Common.hpp>
#include "Message.hpp"
#include "TcpConnection.hpp"
#include "SocketServer.hpp"
#include <cpp_utils/Message.hpp>
#include <cpp_utils/TcpConnection.hpp>
#include <cpp_utils/SocketServer.hpp>
#include <iostream>

Loading…
Cancel
Save