MXS-1725 Use session_set_response() in Cache

- session_set_response() made const correct
- set_response() function added to mxs::FilterSession; calls
  session_set_response().
- Cache uses set_response() for delivering the cache result
  to the client.
This commit is contained in:
Johan Wikman 2018-03-23 16:43:19 +02:00
parent 9fd64cf7ba
commit c08fe079bf
4 changed files with 16 additions and 7 deletions

View File

@ -157,6 +157,18 @@ public:
protected: protected:
FilterSession(MXS_SESSION* pSession); FilterSession(MXS_SESSION* pSession);
/**
* To be called by a filter that short-circuits the request processing.
* If this function is called (in routeQuery), the filter must return
* without passing the request further.
*
* @param pResponse The response to be sent to the client.
*/
void set_response(GWBUF* pResponse) const
{
session_set_response(m_pSession, &m_up.m_data, pResponse);
}
protected: protected:
MXS_SESSION* m_pSession; /*< The MXS_SESSION this filter session is associated with. */ MXS_SESSION* m_pSession; /*< The MXS_SESSION this filter session is associated with. */
Downstream m_down; /*< The downstream component. */ Downstream m_down; /*< The downstream component. */
@ -362,5 +374,4 @@ MXS_FILTER_OBJECT Filter<FilterType, FilterSessionType>::s_object =
&Filter<FilterType, FilterSessionType>::destroyInstance, &Filter<FilterType, FilterSessionType>::destroyInstance,
}; };
} }

View File

@ -213,7 +213,7 @@ typedef struct session
* @param up The filter that should receive the response. * @param up The filter that should receive the response.
* @param buffer The response. * @param buffer The response.
*/ */
void session_set_response(MXS_SESSION *session, MXS_UPSTREAM *up, GWBUF *buffer); void session_set_response(MXS_SESSION *session, const MXS_UPSTREAM *up, GWBUF *buffer);
/** /**
* Function to be used by protocol module for routing incoming data * Function to be used by protocol module for routing incoming data

View File

@ -1229,7 +1229,7 @@ bool session_remove_variable(MXS_SESSION* session,
return removed; return removed;
} }
void session_set_response(MXS_SESSION *session, MXS_UPSTREAM *up, GWBUF *buffer) void session_set_response(MXS_SESSION *session, const MXS_UPSTREAM *up, GWBUF *buffer)
{ {
// Valid arguments. // Valid arguments.
ss_dassert(session && up && buffer); ss_dassert(session && up && buffer);

View File

@ -1128,13 +1128,11 @@ CacheFilterSession::routing_action_t CacheFilterSession::route_SELECT(cache_acti
{ {
MXS_NOTICE("Found in cache."); MXS_NOTICE("Found in cache.");
} }
m_state = CACHE_EXPECTING_NOTHING; m_state = CACHE_EXPECTING_NOTHING;
gwbuf_free(pPacket); gwbuf_free(pPacket);
DCB *dcb = m_pSession->client_dcb;
// TODO: This is not ok. Any filters before this filter, will not set_response(pResponse);
// TODO: see this data.
dcb->func.write(dcb, pResponse);
} }
} }
else if (should_populate(cache_action)) else if (should_populate(cache_action))