|  | @@ -40,7 +40,12 @@ namespace internal {
 | 
	
		
			
				|  |  |  class ServerReactor {
 | 
	
		
			
				|  |  |   public:
 | 
	
		
			
				|  |  |    virtual ~ServerReactor() = default;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Notifies the application that all operations associated with this RPC
 | 
	
		
			
				|  |  | +  /// have completed.
 | 
	
		
			
				|  |  |    virtual void OnDone() {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Notifies the application that this RPC has been cancelled.
 | 
	
		
			
				|  |  |    virtual void OnCancel() {}
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -167,33 +172,110 @@ class ServerCallbackReaderWriter {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -// The following classes are reactors that are to be implemented
 | 
	
		
			
				|  |  | -// by the user, returned as the result of the method handler for
 | 
	
		
			
				|  |  | -// a callback method, and activated by the call to OnStarted
 | 
	
		
			
				|  |  | +// The following classes are the reactor interfaces that are to be implemented
 | 
	
		
			
				|  |  | +// by the user, returned as the result of the method handler for a callback
 | 
	
		
			
				|  |  | +// method, and activated by the call to OnStarted. Note that none of the classes
 | 
	
		
			
				|  |  | +// are pure; all reactions have a default empty reaction so that the user class
 | 
	
		
			
				|  |  | +// only needs to override those classes that it cares about.
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/// \a ServerBidiReactor is the interface for a bidirectional streaming RPC.
 | 
	
		
			
				|  |  |  template <class Request, class Response>
 | 
	
		
			
				|  |  |  class ServerBidiReactor : public internal::ServerReactor {
 | 
	
		
			
				|  |  |   public:
 | 
	
		
			
				|  |  |    ~ServerBidiReactor() = default;
 | 
	
		
			
				|  |  | -  virtual void OnStarted(ServerContext*) {}
 | 
	
		
			
				|  |  | -  virtual void OnSendInitialMetadataDone(bool ok) {}
 | 
	
		
			
				|  |  | -  virtual void OnReadDone(bool ok) {}
 | 
	
		
			
				|  |  | -  virtual void OnWriteDone(bool ok) {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +  /// Send any initial metadata stored in the RPC context. If not invoked,
 | 
	
		
			
				|  |  | +  /// any initial metadata will be passed along with the first Write or the
 | 
	
		
			
				|  |  | +  /// Finish (if there are no writes).
 | 
	
		
			
				|  |  |    void StartSendInitialMetadata() { stream_->SendInitialMetadata(); }
 | 
	
		
			
				|  |  | -  void StartRead(Request* msg) { stream_->Read(msg); }
 | 
	
		
			
				|  |  | -  void StartWrite(const Response* msg) { StartWrite(msg, WriteOptions()); }
 | 
	
		
			
				|  |  | -  void StartWrite(const Response* msg, WriteOptions options) {
 | 
	
		
			
				|  |  | -    stream_->Write(msg, std::move(options));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Initiate a read operation.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[out] req Where to eventually store the read message. Valid when
 | 
	
		
			
				|  |  | +  ///                 the library calls OnReadDone
 | 
	
		
			
				|  |  | +  void StartRead(Request* req) { stream_->Read(req); }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Initiate a write operation.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] resp The message to be written. The library takes temporary
 | 
	
		
			
				|  |  | +  ///                 ownership until OnWriteDone, at which point the
 | 
	
		
			
				|  |  | +  ///                 application regains ownership of resp.
 | 
	
		
			
				|  |  | +  void StartWrite(const Response* resp) { StartWrite(resp, WriteOptions()); }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Initiate a write operation with specified options.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] resp The message to be written. The library takes temporary
 | 
	
		
			
				|  |  | +  ///                 ownership until OnWriteDone, at which point the
 | 
	
		
			
				|  |  | +  ///                 application regains ownership of resp.
 | 
	
		
			
				|  |  | +  /// \param[in] options The WriteOptions to use for writing this message
 | 
	
		
			
				|  |  | +  void StartWrite(const Response* resp, WriteOptions options) {
 | 
	
		
			
				|  |  | +    stream_->Write(resp, std::move(options));
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  void StartWriteAndFinish(const Response* msg, WriteOptions options,
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Initiate a write operation with specified options and final RPC Status,
 | 
	
		
			
				|  |  | +  /// which also causes any trailing metadata for this RPC to be sent out.
 | 
	
		
			
				|  |  | +  /// StartWriteAndFinish is like merging StartWriteLast and Finish into a
 | 
	
		
			
				|  |  | +  /// single step. A key difference, though, is that this operation doesn't have
 | 
	
		
			
				|  |  | +  /// an OnWriteDone reaction - it is considered complete only when OnDone is
 | 
	
		
			
				|  |  | +  /// available. An RPC can either have StartWriteAndFinish or Finish, but not
 | 
	
		
			
				|  |  | +  /// both.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] resp The message to be written. The library takes temporary
 | 
	
		
			
				|  |  | +  ///                 ownership until Onone, at which point the application
 | 
	
		
			
				|  |  | +  ///                 regains ownership of resp.
 | 
	
		
			
				|  |  | +  /// \param[in] options The WriteOptions to use for writing this message
 | 
	
		
			
				|  |  | +  /// \param[in] s The status outcome of this RPC
 | 
	
		
			
				|  |  | +  void StartWriteAndFinish(const Response* resp, WriteOptions options,
 | 
	
		
			
				|  |  |                             Status s) {
 | 
	
		
			
				|  |  | -    stream_->WriteAndFinish(msg, std::move(options), std::move(s));
 | 
	
		
			
				|  |  | +    stream_->WriteAndFinish(resp, std::move(options), std::move(s));
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  void StartWriteLast(const Response* msg, WriteOptions options) {
 | 
	
		
			
				|  |  | -    StartWrite(msg, std::move(options.set_last_message()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Inform system of a planned write operation with specified options, but
 | 
	
		
			
				|  |  | +  /// allow the library to schedule the actual write coalesced with the writing
 | 
	
		
			
				|  |  | +  /// of trailing metadata (which takes place on a Finish call).
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] resp The message to be written. The library takes temporary
 | 
	
		
			
				|  |  | +  ///                 ownership until OnWriteDone, at which point the
 | 
	
		
			
				|  |  | +  ///                 application regains ownership of resp.
 | 
	
		
			
				|  |  | +  /// \param[in] options The WriteOptions to use for writing this message
 | 
	
		
			
				|  |  | +  void StartWriteLast(const Response* resp, WriteOptions options) {
 | 
	
		
			
				|  |  | +    StartWrite(resp, std::move(options.set_last_message()));
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Indicate that the stream is to be finished and the trailing metadata and
 | 
	
		
			
				|  |  | +  /// RPC status are to be sent. Every RPC MUST be finished using either Finish
 | 
	
		
			
				|  |  | +  /// or StartWriteAndFinish (but not both), even if the RPC is already
 | 
	
		
			
				|  |  | +  /// cancelled.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] s The status outcome of this RPC
 | 
	
		
			
				|  |  |    void Finish(Status s) { stream_->Finish(std::move(s)); }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +  /// Notify the application that a streaming RPC has started
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] context The context object now associated with this RPC
 | 
	
		
			
				|  |  | +  virtual void OnStarted(ServerContext* context) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Notifies the application that an explicit StartSendInitialMetadata
 | 
	
		
			
				|  |  | +  /// operation completed. Not used when the sending of initial metadata
 | 
	
		
			
				|  |  | +  /// piggybacks onto the first write.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] ok Was it successful? If false, no further write-side operation
 | 
	
		
			
				|  |  | +  ///               will succeed.
 | 
	
		
			
				|  |  | +  virtual void OnSendInitialMetadataDone(bool ok) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Notifies the application that a StartRead operation completed.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] ok Was it successful? If false, no further read-side operation
 | 
	
		
			
				|  |  | +  ///               will succeed.
 | 
	
		
			
				|  |  | +  virtual void OnReadDone(bool ok) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// Notifies the application that a StartWrite (or StartWriteLast) operation
 | 
	
		
			
				|  |  | +  /// completed.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] ok Was it successful? If false, no further write-side operation
 | 
	
		
			
				|  |  | +  ///               will succeed.
 | 
	
		
			
				|  |  | +  virtual void OnWriteDone(bool ok) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |   private:
 | 
	
		
			
				|  |  |    friend class ServerCallbackReaderWriter<Request, Response>;
 | 
	
		
			
				|  |  |    void BindStream(ServerCallbackReaderWriter<Request, Response>* stream) {
 | 
	
	
		
			
				|  | @@ -203,18 +285,29 @@ class ServerBidiReactor : public internal::ServerReactor {
 | 
	
		
			
				|  |  |    ServerCallbackReaderWriter<Request, Response>* stream_;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +/// \a ServerReadReactor is the interface for a client-streaming RPC.
 | 
	
		
			
				|  |  |  template <class Request, class Response>
 | 
	
		
			
				|  |  |  class ServerReadReactor : public internal::ServerReactor {
 | 
	
		
			
				|  |  |   public:
 | 
	
		
			
				|  |  |    ~ServerReadReactor() = default;
 | 
	
		
			
				|  |  | -  virtual void OnStarted(ServerContext*, Response* resp) {}
 | 
	
		
			
				|  |  | -  virtual void OnSendInitialMetadataDone(bool ok) {}
 | 
	
		
			
				|  |  | -  virtual void OnReadDone(bool ok) {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +  /// The following operation initiations are exactly like ServerBidiReactor.
 | 
	
		
			
				|  |  |    void StartSendInitialMetadata() { reader_->SendInitialMetadata(); }
 | 
	
		
			
				|  |  | -  void StartRead(Request* msg) { reader_->Read(msg); }
 | 
	
		
			
				|  |  | +  void StartRead(Request* req) { reader_->Read(req); }
 | 
	
		
			
				|  |  |    void Finish(Status s) { reader_->Finish(std::move(s)); }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +  /// Similar to ServerBidiReactor::OnStarted, except that this also provides
 | 
	
		
			
				|  |  | +  /// the response object that the stream fills in before calling Finish.
 | 
	
		
			
				|  |  | +  /// (It must be filled in if status is OK, but it may be filled in otherwise.)
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] context The context object now associated with this RPC
 | 
	
		
			
				|  |  | +  /// \param[in] resp The response object to be used by this RPC
 | 
	
		
			
				|  |  | +  virtual void OnStarted(ServerContext* context, Response* resp) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// The following notifications are exactly like ServerBidiReactor.
 | 
	
		
			
				|  |  | +  virtual void OnSendInitialMetadataDone(bool ok) {}
 | 
	
		
			
				|  |  | +  virtual void OnReadDone(bool ok) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |   private:
 | 
	
		
			
				|  |  |    friend class ServerCallbackReader<Request>;
 | 
	
		
			
				|  |  |    void BindReader(ServerCallbackReader<Request>* reader) { reader_ = reader; }
 | 
	
	
		
			
				|  | @@ -222,28 +315,38 @@ class ServerReadReactor : public internal::ServerReactor {
 | 
	
		
			
				|  |  |    ServerCallbackReader<Request>* reader_;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +/// \a ServerReadReactor is the interface for a server-streaming RPC.
 | 
	
		
			
				|  |  |  template <class Request, class Response>
 | 
	
		
			
				|  |  |  class ServerWriteReactor : public internal::ServerReactor {
 | 
	
		
			
				|  |  |   public:
 | 
	
		
			
				|  |  |    ~ServerWriteReactor() = default;
 | 
	
		
			
				|  |  | -  virtual void OnStarted(ServerContext*, const Request* req) {}
 | 
	
		
			
				|  |  | -  virtual void OnSendInitialMetadataDone(bool ok) {}
 | 
	
		
			
				|  |  | -  virtual void OnWriteDone(bool ok) {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +  /// The following operation initiations are exactly like ServerBidiReactor.
 | 
	
		
			
				|  |  |    void StartSendInitialMetadata() { writer_->SendInitialMetadata(); }
 | 
	
		
			
				|  |  | -  void StartWrite(const Response* msg) { StartWrite(msg, WriteOptions()); }
 | 
	
		
			
				|  |  | -  void StartWrite(const Response* msg, WriteOptions options) {
 | 
	
		
			
				|  |  | -    writer_->Write(msg, std::move(options));
 | 
	
		
			
				|  |  | +  void StartWrite(const Response* resp) { StartWrite(resp, WriteOptions()); }
 | 
	
		
			
				|  |  | +  void StartWrite(const Response* resp, WriteOptions options) {
 | 
	
		
			
				|  |  | +    writer_->Write(resp, std::move(options));
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  void StartWriteAndFinish(const Response* msg, WriteOptions options,
 | 
	
		
			
				|  |  | +  void StartWriteAndFinish(const Response* resp, WriteOptions options,
 | 
	
		
			
				|  |  |                             Status s) {
 | 
	
		
			
				|  |  | -    writer_->WriteAndFinish(msg, std::move(options), std::move(s));
 | 
	
		
			
				|  |  | +    writer_->WriteAndFinish(resp, std::move(options), std::move(s));
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  void StartWriteLast(const Response* msg, WriteOptions options) {
 | 
	
		
			
				|  |  | -    StartWrite(msg, std::move(options.set_last_message()));
 | 
	
		
			
				|  |  | +  void StartWriteLast(const Response* resp, WriteOptions options) {
 | 
	
		
			
				|  |  | +    StartWrite(resp, std::move(options.set_last_message()));
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    void Finish(Status s) { writer_->Finish(std::move(s)); }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +  /// Similar to ServerBidiReactor::OnStarted, except that this also provides
 | 
	
		
			
				|  |  | +  /// the request object sent by the client.
 | 
	
		
			
				|  |  | +  ///
 | 
	
		
			
				|  |  | +  /// \param[in] context The context object now associated with this RPC
 | 
	
		
			
				|  |  | +  /// \param[in] req The request object sent by the client
 | 
	
		
			
				|  |  | +  virtual void OnStarted(ServerContext* context, const Request* req) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  /// The following notifications are exactly like ServerBidiReactor.
 | 
	
		
			
				|  |  | +  virtual void OnSendInitialMetadataDone(bool ok) {}
 | 
	
		
			
				|  |  | +  virtual void OnWriteDone(bool ok) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |   private:
 | 
	
		
			
				|  |  |    friend class ServerCallbackWriter<Response>;
 | 
	
		
			
				|  |  |    void BindWriter(ServerCallbackWriter<Response>* writer) { writer_ = writer; }
 |