summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/client.c29
-rw-r--r--examples/deflate.c14
-rw-r--r--examples/libevent-client.c24
-rw-r--r--examples/libevent-server.c32
4 files changed, 54 insertions, 45 deletions
diff --git a/examples/client.c b/examples/client.c
index ce8d1d0..7d25610 100644
--- a/examples/client.c
+++ b/examples/client.c
@@ -56,6 +56,7 @@
#include <string.h>
#include <errno.h>
+#define NGHTTP2_NO_SSIZE_T
#include <nghttp2/nghttp2.h>
#include <openssl/ssl.h>
@@ -154,13 +155,14 @@ static void diec(const char *func, int error_code) {
}
/*
- * The implementation of nghttp2_send_callback type. Here we write
+ * The implementation of nghttp2_send_callback2 type. Here we write
* |data| with size |length| to the network and return the number of
* bytes actually written. See the documentation of
* nghttp2_send_callback for the details.
*/
-static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
- size_t length, int flags, void *user_data) {
+static nghttp2_ssize send_callback(nghttp2_session *session,
+ const uint8_t *data, size_t length,
+ int flags, void *user_data) {
struct Connection *connection;
int rv;
(void)session;
@@ -184,13 +186,14 @@ static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
}
/*
- * The implementation of nghttp2_recv_callback type. Here we read data
- * from the network and write them in |buf|. The capacity of |buf| is
- * |length| bytes. Returns the number of bytes stored in |buf|. See
- * the documentation of nghttp2_recv_callback for the details.
+ * The implementation of nghttp2_recv_callback2 type. Here we read
+ * data from the network and write them in |buf|. The capacity of
+ * |buf| is |length| bytes. Returns the number of bytes stored in
+ * |buf|. See the documentation of nghttp2_recv_callback for the
+ * details.
*/
-static ssize_t recv_callback(nghttp2_session *session, uint8_t *buf,
- size_t length, int flags, void *user_data) {
+static nghttp2_ssize recv_callback(nghttp2_session *session, uint8_t *buf,
+ size_t length, int flags, void *user_data) {
struct Connection *connection;
int rv;
(void)session;
@@ -328,9 +331,9 @@ static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
* recv_callback is also required.
*/
static void setup_nghttp2_callbacks(nghttp2_session_callbacks *callbacks) {
- nghttp2_session_callbacks_set_send_callback(callbacks, send_callback);
+ nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback);
- nghttp2_session_callbacks_set_recv_callback(callbacks, recv_callback);
+ nghttp2_session_callbacks_set_recv_callback2(callbacks, recv_callback);
nghttp2_session_callbacks_set_on_frame_send_callback(callbacks,
on_frame_send_callback);
@@ -458,8 +461,8 @@ static void submit_request(struct Connection *connection, struct Request *req) {
MAKE_NV("accept", "*/*"),
MAKE_NV("user-agent", "nghttp2/" NGHTTP2_VERSION)};
- stream_id = nghttp2_submit_request(connection->session, NULL, nva,
- sizeof(nva) / sizeof(nva[0]), NULL, req);
+ stream_id = nghttp2_submit_request2(connection->session, NULL, nva,
+ sizeof(nva) / sizeof(nva[0]), NULL, req);
if (stream_id < 0) {
diec("nghttp2_submit_request", stream_id);
diff --git a/examples/deflate.c b/examples/deflate.c
index df1cb92..8343b16 100644
--- a/examples/deflate.c
+++ b/examples/deflate.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
+#define NGHTTP2_NO_SSIZE_T
#include <nghttp2/nghttp2.h>
#define MAKE_NV(K, V) \
@@ -93,7 +94,7 @@ int main(void) {
static void deflate(nghttp2_hd_deflater *deflater,
nghttp2_hd_inflater *inflater, const nghttp2_nv *const nva,
size_t nvlen) {
- ssize_t rv;
+ nghttp2_ssize rv;
uint8_t *buf;
size_t buflen;
size_t outlen;
@@ -118,10 +119,10 @@ static void deflate(nghttp2_hd_deflater *deflater,
buflen = nghttp2_hd_deflate_bound(deflater, nva, nvlen);
buf = malloc(buflen);
- rv = nghttp2_hd_deflate_hd(deflater, buf, buflen, nva, nvlen);
+ rv = nghttp2_hd_deflate_hd2(deflater, buf, buflen, nva, nvlen);
if (rv < 0) {
- fprintf(stderr, "nghttp2_hd_deflate_hd() failed with error: %s\n",
+ fprintf(stderr, "nghttp2_hd_deflate_hd2() failed with error: %s\n",
nghttp2_strerror((int)rv));
free(buf);
@@ -166,17 +167,18 @@ static void deflate(nghttp2_hd_deflater *deflater,
int inflate_header_block(nghttp2_hd_inflater *inflater, uint8_t *in,
size_t inlen, int final) {
- ssize_t rv;
+ nghttp2_ssize rv;
for (;;) {
nghttp2_nv nv;
int inflate_flags = 0;
size_t proclen;
- rv = nghttp2_hd_inflate_hd(inflater, &nv, &inflate_flags, in, inlen, final);
+ rv =
+ nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, in, inlen, final);
if (rv < 0) {
- fprintf(stderr, "inflate failed with error code %zd", rv);
+ fprintf(stderr, "inflate failed with error code %td", rv);
return -1;
}
diff --git a/examples/libevent-client.c b/examples/libevent-client.c
index 0e1c14a..7f98368 100644
--- a/examples/libevent-client.c
+++ b/examples/libevent-client.c
@@ -63,6 +63,7 @@ char *strndup(const char *s, size_t size);
#include <event2/bufferevent_ssl.h>
#include <event2/dns.h>
+#define NGHTTP2_NO_SSIZE_T
#include <nghttp2/nghttp2.h>
#include "url-parser/url_parser.h"
@@ -196,18 +197,19 @@ static void print_headers(FILE *f, nghttp2_nv *nva, size_t nvlen) {
fprintf(f, "\n");
}
-/* nghttp2_send_callback. Here we transmit the |data|, |length| bytes,
- to the network. Because we are using libevent bufferevent, we just
- write those bytes into bufferevent buffer. */
-static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
- size_t length, int flags, void *user_data) {
+/* nghttp2_send_callback2. Here we transmit the |data|, |length|
+ bytes, to the network. Because we are using libevent bufferevent,
+ we just write those bytes into bufferevent buffer. */
+static nghttp2_ssize send_callback(nghttp2_session *session,
+ const uint8_t *data, size_t length,
+ int flags, void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data;
struct bufferevent *bev = session_data->bev;
(void)session;
(void)flags;
bufferevent_write(bev, data, length);
- return (ssize_t)length;
+ return (nghttp2_ssize)length;
}
/* nghttp2_on_header_callback: Called when nghttp2 library emits
@@ -342,7 +344,7 @@ static void initialize_nghttp2_session(http2_session_data *session_data) {
nghttp2_session_callbacks_new(&callbacks);
- nghttp2_session_callbacks_set_send_callback(callbacks, send_callback);
+ nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback);
nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks,
on_frame_recv_callback);
@@ -403,8 +405,8 @@ static void submit_request(http2_session_data *session_data) {
MAKE_NV(":path", stream_data->path, stream_data->pathlen)};
fprintf(stderr, "Request headers:\n");
print_headers(stderr, hdrs, ARRLEN(hdrs));
- stream_id = nghttp2_submit_request(session_data->session, NULL, hdrs,
- ARRLEN(hdrs), NULL, stream_data);
+ stream_id = nghttp2_submit_request2(session_data->session, NULL, hdrs,
+ ARRLEN(hdrs), NULL, stream_data);
if (stream_id < 0) {
errx(1, "Could not submit HTTP request: %s", nghttp2_strerror(stream_id));
}
@@ -431,12 +433,12 @@ static int session_send(http2_session_data *session_data) {
context. To send them, we call session_send() in the end. */
static void readcb(struct bufferevent *bev, void *ptr) {
http2_session_data *session_data = (http2_session_data *)ptr;
- ssize_t readlen;
+ nghttp2_ssize readlen;
struct evbuffer *input = bufferevent_get_input(bev);
size_t datalen = evbuffer_get_length(input);
unsigned char *data = evbuffer_pullup(input, -1);
- readlen = nghttp2_session_mem_recv(session_data->session, data, datalen);
+ readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen);
if (readlen < 0) {
warnx("Fatal error: %s", nghttp2_strerror((int)readlen));
delete_http2_session_data(session_data);
diff --git a/examples/libevent-server.c b/examples/libevent-server.c
index fa45d37..cc6c510 100644
--- a/examples/libevent-server.c
+++ b/examples/libevent-server.c
@@ -71,6 +71,7 @@
#include <event2/bufferevent_ssl.h>
#include <event2/listener.h>
+#define NGHTTP2_NO_SSIZE_T
#include <nghttp2/nghttp2.h>
#define OUTPUT_WOULDBLOCK_THRESHOLD (1 << 16)
@@ -277,16 +278,16 @@ static int session_send(http2_session_data *session_data) {
}
/* Read the data in the bufferevent and feed them into nghttp2 library
- function. Invocation of nghttp2_session_mem_recv() may make
+ function. Invocation of nghttp2_session_mem_recv2() may make
additional pending frames, so call session_send() at the end of the
function. */
static int session_recv(http2_session_data *session_data) {
- ssize_t readlen;
+ nghttp2_ssize readlen;
struct evbuffer *input = bufferevent_get_input(session_data->bev);
size_t datalen = evbuffer_get_length(input);
unsigned char *data = evbuffer_pullup(input, -1);
- readlen = nghttp2_session_mem_recv(session_data->session, data, datalen);
+ readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen);
if (readlen < 0) {
warnx("Fatal error: %s", nghttp2_strerror((int)readlen));
return -1;
@@ -301,8 +302,9 @@ static int session_recv(http2_session_data *session_data) {
return 0;
}
-static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
- size_t length, int flags, void *user_data) {
+static nghttp2_ssize send_callback(nghttp2_session *session,
+ const uint8_t *data, size_t length,
+ int flags, void *user_data) {
http2_session_data *session_data = (http2_session_data *)user_data;
struct bufferevent *bev = session_data->bev;
(void)session;
@@ -314,7 +316,7 @@ static ssize_t send_callback(nghttp2_session *session, const uint8_t *data,
return NGHTTP2_ERR_WOULDBLOCK;
}
bufferevent_write(bev, data, length);
- return (ssize_t)length;
+ return (nghttp2_ssize)length;
}
/* Returns nonzero if the string |s| ends with the substring |sub| */
@@ -370,11 +372,11 @@ static char *percent_decode(const uint8_t *value, size_t valuelen) {
return res;
}
-static ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id,
- uint8_t *buf, size_t length,
- uint32_t *data_flags,
- nghttp2_data_source *source,
- void *user_data) {
+static nghttp2_ssize file_read_callback(nghttp2_session *session,
+ int32_t stream_id, uint8_t *buf,
+ size_t length, uint32_t *data_flags,
+ nghttp2_data_source *source,
+ void *user_data) {
int fd = source->fd;
ssize_t r;
(void)session;
@@ -389,17 +391,17 @@ static ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id,
if (r == 0) {
*data_flags |= NGHTTP2_DATA_FLAG_EOF;
}
- return r;
+ return (nghttp2_ssize)r;
}
static int send_response(nghttp2_session *session, int32_t stream_id,
nghttp2_nv *nva, size_t nvlen, int fd) {
int rv;
- nghttp2_data_provider data_prd;
+ nghttp2_data_provider2 data_prd;
data_prd.source.fd = fd;
data_prd.read_callback = file_read_callback;
- rv = nghttp2_submit_response(session, stream_id, nva, nvlen, &data_prd);
+ rv = nghttp2_submit_response2(session, stream_id, nva, nvlen, &data_prd);
if (rv != 0) {
warnx("Fatal error: %s", nghttp2_strerror(rv));
return -1;
@@ -590,7 +592,7 @@ static void initialize_nghttp2_session(http2_session_data *session_data) {
nghttp2_session_callbacks_new(&callbacks);
- nghttp2_session_callbacks_set_send_callback(callbacks, send_callback);
+ nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback);
nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks,
on_frame_recv_callback);