@@ -425,6 +425,7 @@ struct EndpointConfig {
425425
426426class Context ;
427427class Connection ;
428+ class BaseConnection ;
428429class RegisteredMemory ;
429430class SemaphoreStub ;
430431class Semaphore ;
@@ -474,7 +475,7 @@ class Endpoint {
474475 std::shared_ptr<Impl> pimpl_;
475476
476477 friend class Context ;
477- friend class Connection ;
478+ friend class BaseConnection ;
478479};
479480
480481// / Context for communication. This provides a low-level interface for forming connections in use-cases
@@ -521,8 +522,8 @@ class Context : public std::enable_shared_from_this<Context> {
521522 // /
522523 // / @param localEndpoint The local endpoint.
523524 // / @param remoteEndpoint The remote endpoint.
524- // / @return A shared pointer to the connection.
525- std::shared_ptr< Connection> connect (const Endpoint& localEndpoint, const Endpoint& remoteEndpoint);
525+ // / @return A connection object .
526+ Connection connect (const Endpoint& localEndpoint, const Endpoint& remoteEndpoint);
526527
527528 private:
528529 Context ();
@@ -531,7 +532,7 @@ class Context : public std::enable_shared_from_this<Context> {
531532 std::unique_ptr<Impl> pimpl_;
532533
533534 friend class Endpoint ;
534- friend class Connection ;
535+ friend class BaseConnection ;
535536 friend class RegisteredMemory ;
536537 friend class SemaphoreStub ;
537538};
@@ -578,7 +579,7 @@ class RegisteredMemory {
578579 std::shared_ptr<Impl> pimpl_;
579580
580581 friend class Context ;
581- friend class Connection ;
582+ friend class BaseConnection ;
582583 friend class SemaphoreStub ;
583584 friend class Semaphore ;
584585};
@@ -587,12 +588,7 @@ class RegisteredMemory {
587588class Connection {
588589 public:
589590 // / Constructor.
590- // / @param context The context associated with the connection.
591- // / @param localEndpoint The local endpoint of the connection.
592- Connection (std::shared_ptr<Context> context, const Endpoint& localEndpoint);
593-
594- // / Destructor.
595- virtual ~Connection () = default ;
591+ Connection () = default ;
596592
597593 // / Write data from a source RegisteredMemory to a destination RegisteredMemory.
598594 // /
@@ -601,28 +597,27 @@ class Connection {
601597 // / @param src The source RegisteredMemory.
602598 // / @param srcOffset The offset in bytes from the start of the source RegisteredMemory.
603599 // / @param size The number of bytes to write.
604- virtual void write (RegisteredMemory dst, uint64_t dstOffset, RegisteredMemory src, uint64_t srcOffset,
605- uint64_t size) = 0;
600+ void write (RegisteredMemory dst, uint64_t dstOffset, RegisteredMemory src, uint64_t srcOffset, uint64_t size);
606601
607602 // / Update an 8-byte value in a destination RegisteredMemory and synchronize the change with the remote process.
608603 // /
609604 // / @param dst The destination RegisteredMemory.
610605 // / @param dstOffset The offset in bytes from the start of the destination RegisteredMemory.
611606 // / @param src A pointer to the value to update.
612607 // / @param newValue The new value to write.
613- virtual void updateAndSync (RegisteredMemory dst, uint64_t dstOffset, uint64_t * src, uint64_t newValue) = 0 ;
608+ void updateAndSync (RegisteredMemory dst, uint64_t dstOffset, uint64_t * src, uint64_t newValue);
614609
615610 // / Flush any pending writes to the remote process.
616611 // / @param timeoutUsec Timeout in microseconds. Default: -1 (no timeout)
617- virtual void flush (int64_t timeoutUsec = -1 ) = 0 ;
612+ void flush (int64_t timeoutUsec = -1 );
618613
619614 // / Get the transport used by the local process.
620615 // / @return The transport used by the local process.
621- virtual Transport transport () const = 0 ;
616+ Transport transport () const ;
622617
623618 // / Get the transport used by the remote process.
624619 // / @return The transport used by the remote process.
625- virtual Transport remoteTransport () const = 0 ;
620+ Transport remoteTransport () const ;
626621
627622 // / Get the context associated with this connection.
628623 // / @return A shared pointer to the context associated with this connection.
@@ -636,22 +631,23 @@ class Connection {
636631 // / @return The maximum number of write requests that can be queued.
637632 int getMaxWriteQueueSize () const ;
638633
639- protected:
640- static const Endpoint::Impl& getImpl (const Endpoint& endpoint);
641- static const RegisteredMemory::Impl& getImpl (const RegisteredMemory& memory);
642- static Context::Impl& getImpl (Context& context);
634+ private:
635+ Connection (std::shared_ptr<BaseConnection> impl);
636+ std::shared_ptr<BaseConnection> impl_;
643637
644- std::shared_ptr<Context> context_;
645- Endpoint localEndpoint_;
646- int maxWriteQueueSize_;
638+ friend class Context ;
639+ friend class Communicator ;
640+ friend class SemaphoreStub ;
641+ friend class Semaphore ;
642+ friend class ProxyService ;
647643};
648644
649645// / SemaphoreStub object only used for constructing Semaphore, not for direct use by the user.
650646class SemaphoreStub {
651647 public:
652648 // / Constructor.
653- // / @param connection A shared pointer to the connection associated with this semaphore.
654- SemaphoreStub (std::shared_ptr< Connection> connection);
649+ // / @param connection The connection associated with this semaphore.
650+ SemaphoreStub (const Connection& connection);
655651
656652 // / Get the memory associated with this semaphore.
657653 // / @return A reference to the registered memory for this semaphore.
@@ -686,8 +682,8 @@ class Semaphore {
686682 Semaphore (const SemaphoreStub& localStub, const SemaphoreStub& remoteStub);
687683
688684 // / Get the connection associated with this semaphore.
689- // / @return A shared pointer to the connection.
690- std::shared_ptr< Connection> connection () const ;
685+ // / @return The connection.
686+ Connection& connection ();
691687
692688 // / Get the local memory associated with this semaphore.
693689 // / @return A reference to the local registered memory.
@@ -873,34 +869,23 @@ class Communicator {
873869 // / @param localEndpoint The local endpoint.
874870 // / @param remoteRank The rank of the remote process.
875871 // / @param tag The tag to use for identifying the send and receive.
876- // / @return A future of shared pointer to the connection.
872+ // / @return A future of the connection.
877873 // /
878- std::shared_future<std::shared_ptr< Connection> > connect (const Endpoint& localEndpoint, int remoteRank, int tag = 0 );
874+ std::shared_future<Connection> connect (const Endpoint& localEndpoint, int remoteRank, int tag = 0 );
879875
880876 // / Connect to a remote rank. Wrapper of `connect(localEndpoint, remoteRank, tag)`.
881877 // / @param localConfig The configuration for the local endpoint.
882878 // / @param remoteRank The rank of the remote process.
883879 // / @param tag The tag to use for identifying the send and receive.
884- // / @return A future of shared pointer to the connection.
885- std::shared_future<std::shared_ptr<Connection>> connect (const EndpointConfig& localConfig, int remoteRank,
886- int tag = 0 );
887-
888- [[deprecated(" Use connect(localConfig, remoteRank, tag) instead. This will be removed in a future release." )]] std::
889- shared_future<std::shared_ptr<Connection>>
890- connect (int remoteRank, int tag, EndpointConfig localConfig);
891-
892- [[deprecated(" Use connect() instead. This will be removed in a future release." )]] NonblockingFuture<
893- std::shared_ptr<Connection>>
894- connectOnSetup (int remoteRank, int tag, EndpointConfig localConfig) {
895- return connect (localConfig, remoteRank, tag);
896- }
880+ // / @return A future of the connection.
881+ std::shared_future<Connection> connect (const EndpointConfig& localConfig, int remoteRank, int tag = 0 );
897882
898883 // / Build a semaphore for cross-process synchronization.
899884 // / @param connection The connection associated with this semaphore.
900885 // / @param remoteRank The rank of the remote process.
901886 // / @param tag The tag to use for identifying the operation.
902887 // / @return A future of the built semaphore.
903- std::shared_future<Semaphore> buildSemaphore (std::shared_ptr< Connection> connection, int remoteRank, int tag = 0 );
888+ std::shared_future<Semaphore> buildSemaphore (const Connection& connection, int remoteRank, int tag = 0 );
904889
905890 // / Get the remote rank a connection is connected to.
906891 // /
0 commit comments