Http2Session.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. unsigned char frame_hdbuf[HTTP2_FRAME_HDLEN+GRPC_MESSAGE_HDLEN];
  29. Http2Session(http_session_type type = HTTP_CLIENT);
  30. virtual ~Http2Session();
  31. virtual int GetSendData(char** data, size_t* len);
  32. virtual int FeedRecvData(const char* data, size_t len);
  33. virtual bool WantRecv();
  34. // client
  35. // SubmitRequest -> while(GetSendData) {send} -> InitResponse -> do {recv -> FeedRecvData} while(WantRecv)
  36. virtual int SubmitRequest(HttpRequest* req);
  37. virtual int InitResponse(HttpResponse* res);
  38. // server
  39. // InitRequest -> do {recv -> FeedRecvData} while(WantRecv) -> SubmitResponse -> while(GetSendData) {send}
  40. virtual int InitRequest(HttpRequest* req);
  41. virtual int SubmitResponse(HttpResponse* res);
  42. virtual int GetError();
  43. virtual const char* StrError(int error);
  44. };
  45. #endif
  46. #endif // HTTP2_SESSION_H_