From: Gerd v. Egidy Date: Fri, 6 Oct 2006 16:06:28 +0000 (+0000) Subject: libt2n: (gerd) small improvements, resolve doxygen conflicts X-Git-Tag: v0.2~151 X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=commitdiff_plain;h=04e6b2712bf0fdfdb6a74cf6d26f02e6a8d37ae2 libt2n: (gerd) small improvements, resolve doxygen conflicts --- diff --git a/src/server.cpp b/src/server.cpp index 2e2b337..c8255ee 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -60,6 +60,12 @@ server::~server() delete i->second; } +int server::add_connection(connection* newconn) +{ + connections[next_id]=newconn; + return next_id++; +} + /** Gets a connection by id diff --git a/src/server.hxx b/src/server.hxx index 8d2db8e..c93e43b 100644 --- a/src/server.hxx +++ b/src/server.hxx @@ -90,11 +90,15 @@ class server next_id=0; } + int add_connection(connection* newconn); + public: virtual ~server(); void set_default_timeout(int _default_timeout) { default_timeout=_default_timeout; } + int get_default_timeout(void) + { return default_timeout; } void set_logging(std::ostream *_logstream, log_level_values _log_level) { diff --git a/src/socket_server.cpp b/src/socket_server.cpp index 6ef9317..e9bdde0 100644 --- a/src/socket_server.cpp +++ b/src/socket_server.cpp @@ -201,7 +201,79 @@ socket_server::~socket_server() void socket_server::new_connection() { + struct sockaddr_un clientname; + unsigned int size = sizeof (clientname); + int newsock = accept (sock,(struct sockaddr *) &clientname,&size); + if (newsock < 0) + { + if (errno == EAGAIN) + { + log(error, "accept error (EAGAIN): no connection waiting"); + return; + } + + /* default: break */ + string err="error accepting connection: "; + err+=strerror(errno); + log(error, err); + throw t2n_server_error(err); + } + + FD_SET (newsock, &connection_set); + + int i=1; + + /* keepalive enable */ + if (setsockopt(newsock,SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i)) < 0) + { + string err="error setting socket option: "; + err+=strerror(errno); + log(error, err); + throw t2n_server_error(err); + } + + /* close on exec */ + int fdflags; + fdflags=fcntl(newsock,F_GETFD, 0); + if (fdflags < 0) + { + string err="fcntl error on socket: "; + err+=strerror(errno); + log(error, err); + throw t2n_server_error(err); + } + fdflags |= FD_CLOEXEC; + if (fcntl(newsock,F_SETFD,fdflags) < 0) + { + string err="fcntl error on socket: "; + err+=strerror(errno); + log(error, err); + throw t2n_server_error(err); + } + + /* non-blocking mode */ + int flflags; + flflags=fcntl(newsock,F_GETFL,0); + if (flflags < 0) + { + string err="fcntl error on socket: "; + err+=strerror(errno); + log(error, err); + throw t2n_server_error(err); + } + flflags |= O_NONBLOCK; + if (fcntl(newsock,F_SETFL,flflags) < 0) + { + string err="fcntl error on socket: "; + err+=strerror(errno); + log(error, err); + throw t2n_server_error(err); + } + + add_connection(new socket_connection(newsock, get_default_timeout())); + + return; } void socket_server::fill_buffer(long long usec_timeout) @@ -258,10 +330,10 @@ void socket_server::fill_buffer(long long usec_timeout) return; } -socket_connection::socket_connection(int _socket, int _timeout) +socket_connection::socket_connection(int _sock, int _timeout) : connection(_timeout) { - + sock=_sock; } void socket_connection::close() diff --git a/src/socket_server.hxx b/src/socket_server.hxx index 93111da..5dfea1f 100644 --- a/src/socket_server.hxx +++ b/src/socket_server.hxx @@ -60,11 +60,12 @@ class socket_server : public server */ class socket_connection : public connection { + friend class socket_server; + private: - int socket; + int sock; - friend void socket_server::fill_buffer(long long usec_timeout); - socket_connection(int _socket, int _timeout); + socket_connection(int _sock, int _timeout); public: diff --git a/src/t2n_exception.hxx b/src/t2n_exception.hxx index 2be0fc5..7b68c21 100644 --- a/src/t2n_exception.hxx +++ b/src/t2n_exception.hxx @@ -40,10 +40,7 @@ void serialize(Archive & ar, std::exception & g, const unsigned int version) namespace libt2n { -/** - generic libt2n exception -*/ -// a generic exception that can be handeled with libt2n +/// a generic exception that can be handeled with libt2n class t2n_exception : public std::exception { private: @@ -78,7 +75,7 @@ class t2n_exception : public std::exception }; BOOST_CLASS_EXPORT(t2n_exception) -// a (unspecified) problem with libt2n communication +/// a (unspecified) problem with libt2n communication class t2n_communication_error : public t2n_exception { private: @@ -105,7 +102,7 @@ class t2n_communication_error : public t2n_exception }; BOOST_CLASS_EXPORT(t2n_communication_error) -// can't connect to libt2n server +/// can't connect to libt2n server class t2n_connect_error : public t2n_communication_error { private: @@ -132,7 +129,7 @@ class t2n_connect_error : public t2n_communication_error }; BOOST_CLASS_EXPORT(t2n_connect_error) -// error establishing a socket on the server (only thrown on the server-side) +/// error establishing a socket on the server (only thrown on the server-side) class t2n_server_error : public t2n_communication_error { private: @@ -159,7 +156,7 @@ class t2n_server_error : public t2n_communication_error }; BOOST_CLASS_EXPORT(t2n_server_error) -// error transmitting or receiving libt2n messages +/// error transmitting or receiving libt2n messages class t2n_transfer_error : public t2n_communication_error { private: @@ -186,7 +183,7 @@ class t2n_transfer_error : public t2n_communication_error }; BOOST_CLASS_EXPORT(t2n_transfer_error) -// tried to talk to an incompatible libt2n version +/// tried to talk to an incompatible libt2n version class t2n_version_mismatch : public t2n_communication_error { private: @@ -213,7 +210,7 @@ class t2n_version_mismatch : public t2n_communication_error }; BOOST_CLASS_EXPORT(t2n_version_mismatch) -// illegal libt2n command received +/// illegal libt2n command received class t2n_command_error : public t2n_exception { private: @@ -240,7 +237,7 @@ class t2n_command_error : public t2n_exception }; BOOST_CLASS_EXPORT(t2n_command_error) -// error serializing or deserializing a libt2n command packet +/// error serializing or deserializing a libt2n command packet class t2n_serialization_error : public t2n_exception { private: @@ -267,8 +264,10 @@ class t2n_serialization_error : public t2n_exception }; BOOST_CLASS_EXPORT(t2n_serialization_error) -// a runtime error within the remote function -// derive your own custom exceptions from this one +/** + a runtime error within the remote function + derive your own custom exceptions from this one +*/ class t2n_runtime_error : public t2n_exception { private: