From 29e6f7c659d49bb2570f0e8c710e177fb1971dad Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Wed, 18 Sep 2013 22:43:13 +0200
Subject: [PATCH 2/2] http2: switch recv/send functions to http2 ones after 101

---
 lib/http.h  |  3 +++
 lib/http2.c | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/lib/http.h b/lib/http.h
index 82a7b50..8d3f9d0 100644
--- a/lib/http.h
+++ b/lib/http.h
@@ -152,6 +152,9 @@ struct HTTP {
 struct http_conn {
 #ifdef USE_NGHTTP2
   nghttp2_session *h2;
+  char *mem;     /* points to a buffer in memory to store or read from */
+  size_t size;   /* size of the buffer 'mem' points to */
+  ssize_t nread; /* how much data that was sent/recv by the HTTP2 engine */
 #else
   int unused; /* prevent a compiler warning */
 #endif
diff --git a/lib/http2.c b/lib/http2.c
index f15cb17..b6b01cb 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -111,7 +111,7 @@ static ssize_t recv_callback(nghttp2_session *h2,
 {
   struct connectdata *conn = (struct connectdata *)userp;
   ssize_t nread;
-  CURLcode rc = Curl_read(conn, conn->sock[0], (char *)buf, length, &nread);
+  CURLcode rc = Curl_read_plain(conn->sock[0], (char *)buf, length, &nread);
   (void)h2;
   (void)flags;
 
@@ -208,10 +208,46 @@ CURLcode Curl_http2_request(Curl_send_buffer *req,
   return result;
 }
 
+/*
+ * If the read would block (EWOULDBLOCK) we return -1. Otherwise we return
+ * a regular CURLcode value.
+ */
+static ssize_t http2_recv(struct connectdata *conn, int sockindex,
+                          char *mem, size_t len, CURLcode *err)
+{
+  int rc;
+  (void)sockindex; /* we always do HTTP2 on sockindex 0 */
+
+  conn->proto.httpc.mem = mem;
+  conn->proto.httpc.size = len;
+
+  rc = nghttp2_session_recv(conn->proto.httpc.h2);
+
+  if(rc < 0) {
+    *err = CURLE_RECV_ERROR;
+  }
+  return 0;
+}
+
+/* return number of received (decrypted) bytes */
+static ssize_t http2_send(struct connectdata *conn, int sockindex,
+                          const void *mem, size_t len, CURLcode *err)
+{
+  /* TODO: proper implementation */
+  (void)conn;
+  (void)sockindex;
+  (void)mem;
+  (void)len;
+  (void)err;
+  return 0;
+}
+
 void Curl_http2_switched(struct connectdata *conn)
 {
   /* we are switched! */
   conn->handler = &Curl_handler_http2;
+  conn->recv[FIRSTSOCKET] = http2_recv;
+  conn->send[FIRSTSOCKET] = http2_send;
   infof(conn->data, "We have switched to HTTP2\n");
 }
 
-- 
1.8.5.3

