master
Denes Matetelki 12 years ago
commit 91a1193543

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

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

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

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

@ -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 #!/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_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 do
echo "Compiling $SRC_FILE" echo "Compiling $SRC_FILE"
$GCC -c $SRC_FILE -I$INCLUDE_DIR $GCC_OPTIONS $GCC -c $SRC_FILE -I$INCLUDE_DIR $GCC_OPTIONS
@ -25,16 +28,16 @@ cd $BUILD_DIR
echo "Linking tcpclient_main.o" 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" 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" 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" 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" 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 // g++ mysqlclient_main.cpp src/Logger.cpp src/MysqlClient.cpp src/ArgParse.cpp -I./include -lmysqlclient
#include "Logger.hpp" #include <cpp_utils/Logger.hpp>
#include "Common.hpp" #include <cpp_utils/Common.hpp>
#include "ArgParse.hpp" #include <cpp_utils/ArgParse.hpp>
#include "MysqlClient.hpp" #include <cpp_utils/MysqlClient.hpp>
#include "MysqlConnectionPool.hpp" #include <cpp_utils/MysqlConnectionPool.hpp>
#include <string> #include <string>
#include <list> #include <list>

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

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

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

Loading…
Cancel
Save