nrtb-core team mailing list archive
-
nrtb-core team
-
Mailing list archive
-
Message #00525
[Branch ~fpstovall/nrtb/fps-sprint-003] Rev 28: Completed bug 1217384. nrtb::tcp_server_socket_factory now uses unique_ptrs for queuing and distr...
------------------------------------------------------------
revno: 28
committer: Rick Stovall <fpstovall>
branch nick: ricks-sprint-003
timestamp: Tue 2013-08-27 12:49:20 -0400
message:
Completed bug 1217384. nrtb::tcp_server_socket_factory now uses unique_ptrs for queuing and distributing tcp_sockets. Also, a final change for bug 1217388 to complete the fix for nrtb::abs_queue not properly implementing move semantics.
NOTE: We discovered boost::circular_queue can not handle std::unique_ptr, so tcp_server_socket_factory is now using a linear_queue.
modified:
cpp/common/abs_queue/abs_queue.h
cpp/common/sockets/base_socket.cpp
cpp/common/sockets/base_socket.h
--
lp:~fpstovall/nrtb/fps-sprint-003
https://code.launchpad.net/~fpstovall/nrtb/fps-sprint-003
Your team NRTB Core is subscribed to branch lp:~fpstovall/nrtb/fps-sprint-003.
To unsubscribe from this branch go to https://code.launchpad.net/~fpstovall/nrtb/fps-sprint-003/+edit-subscription
=== modified file 'cpp/common/abs_queue/abs_queue.h'
--- cpp/common/abs_queue/abs_queue.h 2013-08-27 15:22:39 +0000
+++ cpp/common/abs_queue/abs_queue.h 2013-08-27 16:49:20 +0000
@@ -136,7 +136,7 @@
signal.wait(lock);
if (ready)
{
- T returnme = buffer.front();
+ T returnme = std::move(buffer.front());
buffer.pop();
out_count++;
return std::move(returnme);
=== modified file 'cpp/common/sockets/base_socket.cpp'
--- cpp/common/sockets/base_socket.cpp 2013-07-14 18:47:08 +0000
+++ cpp/common/sockets/base_socket.cpp 2013-08-27 16:49:20 +0000
@@ -541,16 +541,13 @@
return sockaddr_to_str(myaddr);
};
-
tcp_server_socket_factory::tcp_server_socket_factory(
const string & address,
- const unsigned short int backlog,
- const int queue_size)
+ const unsigned short int backlog)
{
// does not attempt to set up the connection initially.
_address = address;
_backlog = backlog;
- pending.resize(queue_size);
};
tcp_server_socket_factory::~tcp_server_socket_factory()
@@ -561,6 +558,13 @@
try { stop_listen(); } catch (...) {};
};
+tcp_socket_p tcp_server_socket_factory::get_sock()
+{
+ tcp_socket_p returnme = std::move(pending.pop());
+ return std::move(returnme);
+};
+
+
void tcp_server_socket_factory::start_listen()
{
// take no action if the listen thread is already running.
@@ -725,7 +729,7 @@
if (good_connect)
{
tcp_socket_p storeme(new tcp_socket(new_conn));
- server->pending.push(storeme);
+ server->pending.push(std::move(storeme));
};
}; // while go;
}
=== modified file 'cpp/common/sockets/base_socket.h'
--- cpp/common/sockets/base_socket.h 2013-07-14 18:47:08 +0000
+++ cpp/common/sockets/base_socket.h 2013-08-27 16:49:20 +0000
@@ -23,7 +23,7 @@
#include <atomic>
#include <thread>
#include <common.h>
-#include <circular_queue.h>
+#include <linear_queue.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -376,7 +376,7 @@
};
/// smart pointer for use with tcp_sockets
-typedef std::shared_ptr<nrtb::tcp_socket> tcp_socket_p;
+typedef std::unique_ptr<nrtb::tcp_socket> tcp_socket_p;
/** "listener" TCP/IP socket socket factory for servers.
**
@@ -400,7 +400,7 @@
/// Thrown by by the listen thread in case of unexpected error.
class listen_terminated_exception: public general_exception {};
/// handlers should catch this and shutdown gracefully.
- typedef circular_queue<tcp_socket_p>::queue_not_ready queue_not_ready;
+ typedef linear_queue<tcp_socket_p>::queue_not_ready queue_not_ready;
/** Construct a tcp_server_socket_factory and puts it online.
**
@@ -419,8 +419,7 @@
** exceeded, oldest connections will be discarded.
**/
tcp_server_socket_factory(const std::string & address,
- const unsigned short int backlog = 5,
- const int queue_size=10);
+ const unsigned short int backlog = 5);
/** Destructs a server_sock.
**
@@ -433,7 +432,7 @@
virtual ~tcp_server_socket_factory();
/// Consumers call this to get a connected socket.
- tcp_socket_p get_sock() { return pending.pop(); };
+ tcp_socket_p get_sock();
/// returns the number of connections received.
int accepted() { return pending.in_count; };
@@ -512,7 +511,7 @@
std::atomic< int > _last_thread_fault {0};
std::atomic< bool > in_run_method {false};
// The accepted inbound connection queue
- nrtb::circular_queue<tcp_socket_p> pending;
+ nrtb::linear_queue<tcp_socket_p> pending;
// Provides the listener thread.
static void run(tcp_server_socket_factory * server);