Http2Session.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef HTTP2_SESSION_H_
  2. #define HTTP2_SESSION_H_
  3. #ifdef WITH_NGHTTP2
  4. #include "HttpSession.h"
  5. #include "http2def.h"
  6. #include "grpcdef.h"
  7. #include "nghttp2/nghttp2.h"
  8. enum http2_session_state {
  9. HSS_SEND_MAGIC,
  10. HSS_SEND_SETTINGS,
  11. HSS_SEND_HEADERS,
  12. HSS_SEND_DATA_FRAME_HD,
  13. HSS_SEND_DATA,
  14. HSS_SEND_DONE
  15. };
  16. class Http2Session : public HttpSession {
  17. public:
  18. http_session_type type;
  19. static nghttp2_session_callbacks* cbs;
  20. nghttp2_session* session;
  21. http2_session_state state;
  22. HttpPayload* submited;
  23. HttpPayload* parsed;
  24. int error;
  25. int stream_id;
  26. int stream_closed;
  27. // http2_frame_hd + grpc_message_hd
  28. // at least HTTP2_FRAME_HDLEN + GRPC_MESSAGE_HDLEN = 9 + 5 = 14
  29. unsigned char frame_hdbuf[32];
  30. Http2Session(http_session_type type = HTTP_CLIENT);
  31. virtual ~Http2Session();
  32. virtual int GetSendData(char** data, size_t* len);
  33. virtual int FeedRecvData(const char* data, size_t len);
  34. virtual bool WantRecv();
  35. // client
  36. // SubmitRequest -> while(GetSendData) {send} -> InitResponse -> do {recv -> FeedRecvData} while(WantRecv)
  37. virtual int SubmitRequest(HttpRequest* req);
  38. virtual int InitResponse(HttpResponse* res);
  39. // server
  40. // InitRequest -> do {recv -> FeedRecvData} while(WantRecv) -> SubmitResponse -> while(GetSendData) {send}
  41. virtual int InitRequest(HttpRequest* req);
  42. virtual int SubmitResponse(HttpResponse* res);
  43. virtual int GetError();
  44. virtual const char* StrError(int error);
  45. };
  46. #endif
  47. #endif // HTTP2_SESSION_H_