@@ -426,6 +426,7 @@ struct EndpointConfig {
426426
427427class Context ;
428428class Connection ;
429+ class BaseConnection ;
429430class RegisteredMemory ;
430431class SemaphoreStub ;
431432class Semaphore ;
@@ -475,7 +476,7 @@ class Endpoint {
475476 std::shared_ptr<Impl> pimpl_;
476477
477478 friend class Context ;
478- friend class Connection ;
479+ friend class BaseConnection ;
479480};
480481
481482// / Context for communication. This provides a low-level interface for forming connections in use-cases
@@ -522,8 +523,8 @@ class Context : public std::enable_shared_from_this<Context> {
522523 // /
523524 // / @param localEndpoint The local endpoint.
524525 // / @param remoteEndpoint The remote endpoint.
525- // / @return A shared pointer to the connection.
526- std::shared_ptr< Connection> connect (const Endpoint& localEndpoint, const Endpoint& remoteEndpoint);
526+ // / @return A connection object .
527+ Connection connect (const Endpoint& localEndpoint, const Endpoint& remoteEndpoint);
527528
528529 private:
529530 Context ();
@@ -532,7 +533,7 @@ class Context : public std::enable_shared_from_this<Context> {
532533 std::unique_ptr<Impl> pimpl_;
533534
534535 friend class Endpoint ;
535- friend class Connection ;
536+ friend class BaseConnection ;
536537 friend class RegisteredMemory ;
537538 friend class SemaphoreStub ;
538539};
@@ -579,7 +580,7 @@ class RegisteredMemory {
579580 std::shared_ptr<Impl> pimpl_;
580581
581582 friend class Context ;
582- friend class Connection ;
583+ friend class BaseConnection ;
583584 friend class SemaphoreStub ;
584585 friend class Semaphore ;
585586};
@@ -588,12 +589,7 @@ class RegisteredMemory {
588589class Connection {
589590 public:
590591 // / Constructor.
591- // / @param context The context associated with the connection.
592- // / @param localEndpoint The local endpoint of the connection.
593- Connection (std::shared_ptr<Context> context, const Endpoint& localEndpoint);
594-
595- // / Destructor.
596- virtual ~Connection () = default ;
592+ Connection () = default ;
597593
598594 // / Write data from a source RegisteredMemory to a destination RegisteredMemory.
599595 // /
@@ -602,28 +598,27 @@ class Connection {
602598 // / @param src The source RegisteredMemory.
603599 // / @param srcOffset The offset in bytes from the start of the source RegisteredMemory.
604600 // / @param size The number of bytes to write.
605- virtual void write (RegisteredMemory dst, uint64_t dstOffset, RegisteredMemory src, uint64_t srcOffset,
606- uint64_t size) = 0;
601+ void write (RegisteredMemory dst, uint64_t dstOffset, RegisteredMemory src, uint64_t srcOffset, uint64_t size);
607602
608603 // / Update an 8-byte value in a destination RegisteredMemory and synchronize the change with the remote process.
609604 // /
610605 // / @param dst The destination RegisteredMemory.
611606 // / @param dstOffset The offset in bytes from the start of the destination RegisteredMemory.
612607 // / @param src A pointer to the value to update.
613608 // / @param newValue The new value to write.
614- virtual void updateAndSync (RegisteredMemory dst, uint64_t dstOffset, uint64_t * src, uint64_t newValue) = 0 ;
609+ void updateAndSync (RegisteredMemory dst, uint64_t dstOffset, uint64_t * src, uint64_t newValue);
615610
616611 // / Flush any pending writes to the remote process.
617612 // / @param timeoutUsec Timeout in microseconds. Default: -1 (no timeout)
618- virtual void flush (int64_t timeoutUsec = -1 ) = 0 ;
613+ void flush (int64_t timeoutUsec = -1 );
619614
620615 // / Get the transport used by the local process.
621616 // / @return The transport used by the local process.
622- virtual Transport transport () const = 0 ;
617+ Transport transport () const ;
623618
624619 // / Get the transport used by the remote process.
625620 // / @return The transport used by the remote process.
626- virtual Transport remoteTransport () const = 0 ;
621+ Transport remoteTransport () const ;
627622
628623 // / Get the context associated with this connection.
629624 // / @return A shared pointer to the context associated with this connection.
@@ -637,22 +632,23 @@ class Connection {
637632 // / @return The maximum number of write requests that can be queued.
638633 int getMaxWriteQueueSize () const ;
639634
640- protected:
641- static const Endpoint::Impl& getImpl (const Endpoint& endpoint);
642- static const RegisteredMemory::Impl& getImpl (const RegisteredMemory& memory);
643- static Context::Impl& getImpl (Context& context);
635+ private:
636+ Connection (std::shared_ptr<BaseConnection> impl);
637+ std::shared_ptr<BaseConnection> impl_;
644638
645- std::shared_ptr<Context> context_;
646- Endpoint localEndpoint_;
647- int maxWriteQueueSize_;
639+ friend class Context ;
640+ friend class Communicator ;
641+ friend class SemaphoreStub ;
642+ friend class Semaphore ;
643+ friend class ProxyService ;
648644};
649645
650646// / SemaphoreStub object only used for constructing Semaphore, not for direct use by the user.
651647class SemaphoreStub {
652648 public:
653649 // / Constructor.
654- // / @param connection A shared pointer to the connection associated with this semaphore.
655- SemaphoreStub (std::shared_ptr< Connection> connection);
650+ // / @param connection The connection associated with this semaphore.
651+ SemaphoreStub (const Connection& connection);
656652
657653 // / Get the memory associated with this semaphore.
658654 // / @return A reference to the registered memory for this semaphore.
@@ -687,8 +683,8 @@ class Semaphore {
687683 Semaphore (const SemaphoreStub& localStub, const SemaphoreStub& remoteStub);
688684
689685 // / Get the connection associated with this semaphore.
690- // / @return A shared pointer to the connection.
691- std::shared_ptr< Connection> connection () const ;
686+ // / @return The connection.
687+ Connection& connection ();
692688
693689 // / Get the local memory associated with this semaphore.
694690 // / @return A reference to the local registered memory.
@@ -874,34 +870,23 @@ class Communicator {
874870 // / @param localEndpoint The local endpoint.
875871 // / @param remoteRank The rank of the remote process.
876872 // / @param tag The tag to use for identifying the send and receive.
877- // / @return A future of shared pointer to the connection.
873+ // / @return A future of the connection.
878874 // /
879- std::shared_future<std::shared_ptr< Connection> > connect (const Endpoint& localEndpoint, int remoteRank, int tag = 0 );
875+ std::shared_future<Connection> connect (const Endpoint& localEndpoint, int remoteRank, int tag = 0 );
880876
881877 // / Connect to a remote rank. Wrapper of `connect(localEndpoint, remoteRank, tag)`.
882878 // / @param localConfig The configuration for the local endpoint.
883879 // / @param remoteRank The rank of the remote process.
884880 // / @param tag The tag to use for identifying the send and receive.
885- // / @return A future of shared pointer to the connection.
886- std::shared_future<std::shared_ptr<Connection>> connect (const EndpointConfig& localConfig, int remoteRank,
887- int tag = 0 );
888-
889- [[deprecated("Use connect(localConfig, remoteRank, tag) instead. This will be removed in a future release.")]] std::
890- shared_future<std::shared_ptr<Connection>>
891- connect (int remoteRank, int tag, EndpointConfig localConfig);
892-
893- [[deprecated("Use connect() instead. This will be removed in a future release.")]] NonblockingFuture<
894- std::shared_ptr<Connection>>
895- connectOnSetup (int remoteRank, int tag, EndpointConfig localConfig) {
896- return connect (localConfig, remoteRank, tag);
897- }
881+ // / @return A future of the connection.
882+ std::shared_future<Connection> connect (const EndpointConfig& localConfig, int remoteRank, int tag = 0 );
898883
899884 // / Build a semaphore for cross-process synchronization.
900885 // / @param connection The connection associated with this semaphore.
901886 // / @param remoteRank The rank of the remote process.
902887 // / @param tag The tag to use for identifying the operation.
903888 // / @return A future of the built semaphore.
904- std::shared_future<Semaphore> buildSemaphore (std::shared_ptr< Connection> connection, int remoteRank, int tag = 0 );
889+ std::shared_future<Semaphore> buildSemaphore (const Connection& connection, int remoteRank, int tag = 0 );
905890
906891 // / Get the remote rank a connection is connected to.
907892 // /
0 commit comments