aboutsummaryrefslogtreecommitdiff
path: root/lib/http2.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2013-09-18 22:43:13 +0200
committerDaniel Stenberg <daniel@haxx.se>2014-01-29 10:24:05 +0100
commit53940f883450d1976105677adda41696e5094602 (patch)
treee1f34d2502c216717decf301a9282c213812555d /lib/http2.c
parent8d3608f2ad29bb65ce0926a45b46ff29902c279f (diff)
http2: switch recv/send functions to http2 ones after 101
Diffstat (limited to 'lib/http2.c')
-rw-r--r--lib/http2.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/http2.c b/lib/http2.c
index f15cb1700..b6b01cb7e 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");
}