~fpstovall/nrtb/fps-sprint-003

« back to all changes in this revision

Viewing changes to cpp/common/sockets/base_socket.h

  • Committer: Rick Stovall
  • Date: 2013-08-27 16:49:20 UTC
  • Revision ID: rick_stovall_fpstovall-20130827164920-orpg39e9hcsqmjyt
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <atomic>
24
24
#include <thread>
25
25
#include <common.h>
26
 
#include <circular_queue.h>
 
26
#include <linear_queue.h>
27
27
#include <sys/socket.h>
28
28
#include <netinet/in.h>
29
29
 
376
376
};
377
377
 
378
378
/// smart pointer for use with tcp_sockets
379
 
typedef std::shared_ptr<nrtb::tcp_socket> tcp_socket_p;
 
379
typedef std::unique_ptr<nrtb::tcp_socket> tcp_socket_p;
380
380
 
381
381
/** "listener" TCP/IP socket socket factory for servers. 
382
382
 ** 
400
400
  /// Thrown by by the listen thread in case of unexpected error.
401
401
  class listen_terminated_exception: public general_exception {};
402
402
  /// handlers should catch this and shutdown gracefully.
403
 
  typedef circular_queue<tcp_socket_p>::queue_not_ready queue_not_ready;
 
403
  typedef linear_queue<tcp_socket_p>::queue_not_ready queue_not_ready;
404
404
  
405
405
  /** Construct a tcp_server_socket_factory and puts it online.
406
406
    ** 
419
419
    ** exceeded, oldest connections will be discarded. 
420
420
    **/
421
421
  tcp_server_socket_factory(const std::string & address, 
422
 
        const unsigned short int backlog = 5,
423
 
        const int queue_size=10);
 
422
        const unsigned short int backlog = 5);
424
423
 
425
424
  /** Destructs a server_sock. 
426
425
    ** 
433
432
  virtual ~tcp_server_socket_factory();
434
433
 
435
434
  /// Consumers call this to get a connected socket.
436
 
  tcp_socket_p get_sock() { return pending.pop(); };
 
435
  tcp_socket_p get_sock();
437
436
  
438
437
  /// returns the number of connections received.
439
438
  int accepted() { return pending.in_count; };
512
511
  std::atomic< int > _last_thread_fault {0};
513
512
  std::atomic< bool > in_run_method {false};
514
513
  // The accepted inbound connection queue
515
 
  nrtb::circular_queue<tcp_socket_p> pending;
 
514
  nrtb::linear_queue<tcp_socket_p> pending;
516
515
  // Provides the listener thread.
517
516
  static void run(tcp_server_socket_factory * server);
518
517