Evo C++ Library v0.5.1
Classes | Public Types | Public Member Functions | List of all members
AsyncServerReplyT< T > Class Template Reference

#include <evo/ioasync_server.h>

Detailed Description

template<class T = AsyncBuffers>
class evo::AsyncServerReplyT< T >

Handles sending server replies, and accounts for potentially out of order responses.

Classes

struct  Writer
 Response writer used to group multiple writes together for best performance. More...
 

Public Types

typedef T OutBuffer
 Output buffer type. More...
 
typedef AsyncServerReplyT< T > This
 This type. More...
 
enum  WriterFlags { wfNONE = 0, wfDEFERRED = 0x01, wfDEFERRED_LAST = 0x03 }
 Flags used with Writer. More...
 

Public Member Functions

 AsyncServerReplyT (T &bufs)
 Constructor. More...
 
ulong deferred_active () const
 Get current number of deferred responses in progress. More...
 
template<class U >
bool deferred_end (U &context)
 Call when deferred response is finished. More...
 
Thisdeferred_send (ulong id, String &data, bool last)
 Send deferred response for given request ID. More...
 
template<class U >
void deferred_start (U &context)
 Call when deferred response is started. More...
 
ulong gen_id ()
 Generate a new request ID. More...
 
void nosend (ulong id)
 Cancel current ID since current request doesn't have a response. More...
 
void send (ulong id, String &data)
 Send response for given request ID. More...
 
void send_end ()
 End current response. More...
 

Member Typedef Documentation

◆ OutBuffer

typedef T OutBuffer

Output buffer type.

◆ This

typedef AsyncServerReplyT<T> This

This type.

Member Enumeration Documentation

◆ WriterFlags

Flags used with Writer.

Enumerator
wfNONE 
wfDEFERRED 

Deferred but not the last part of this response.

wfDEFERRED_LAST 

Deferred and the last part of this response.

Constructor & Destructor Documentation

◆ AsyncServerReplyT()

AsyncServerReplyT ( T &  bufs)
inline

Constructor.

Parameters
bufsBuffer to use for writes

Member Function Documentation

◆ deferred_active()

ulong deferred_active ( ) const
inline

Get current number of deferred responses in progress.

Returns
Number of current deferred responses in progress, 0 for none

◆ deferred_end()

bool deferred_end ( U &  context)
inline

Call when deferred response is finished.

  • This is used to track the current number of deferred events are being waited on
  • Call this only after response is fully sent with send()
  • This calls send_end()
Parameters
contextDeferredContext for current connection
Returns
Whether this was the last context reference, meaning context was destroyed, false if not destroyed

◆ deferred_send()

This& deferred_send ( ulong  id,
String data,
bool  last 
)
inline

Send deferred response for given request ID.

  • Call gen_id() before response is deferred to get an ID to use
  • Do not call this with non-deferred response, use send() instead
  • Multiple calls with the same ID are effectively appended together, but must set last=true on last part of response
  • Caution: Results are undefined if last isn't set correctly
Parameters
idRequest ID for response
dataResponse data to send
lastWhether this is the last part of the response, true to allow processing of next request response
Returns
This

◆ deferred_start()

void deferred_start ( U &  context)
inline

Call when deferred response is started.

  • This is used to track the current number of deferred events are being waited on
Parameters
contextDeferredContext for current connection
Returns
Whether this was the last context reference, meaning context was destroyed, false if not destroyed

◆ gen_id()

ulong gen_id ( )
inline

Generate a new request ID.

Returns
New request ID

◆ nosend()

void nosend ( ulong  id)
inline

Cancel current ID since current request doesn't have a response.

  • This must be called before the next ID is created (i.e. before next request is processed), otherwise the connection will likely hang
Parameters
idID to cancel

◆ send()

void send ( ulong  id,
String data 
)
inline

Send response for given request ID.

  • Call gen_id() to get an ID to use
  • Do not call this with deferred response, use deferred_send() instead
  • Multiple calls with the same ID are effectively appended together
  • Responses sent out of order are queued so they're actually sent in the right order
Parameters
idRequest ID for response
dataResponse data to send

◆ send_end()

void send_end ( )
inline

End current response.

  • Call after last send() for current response
  • Not needed for deferred responses, deferred_end() calls this

The documentation for this class was generated from the following file: