Skip to content

Commit

Permalink
Mac compatibility with nghttp2
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 12, 2019
1 parent c84abdb commit 6c5407e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
37 changes: 6 additions & 31 deletions src/Internal/HPackNghttp2.php
Expand Up @@ -67,38 +67,13 @@ private static function init(): void
return;
}

self::$ffi = FFI::cdef('
$header = \file_get_contents(__DIR__ . '/amp-hpack.h');

#define FFI_SCOPE "amphp-hpack-nghttp2"
#define FFI_LIB "libnghttp2.so"
typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;
typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;
typedef struct {
uint8_t *name;
uint8_t *value;
size_t namelen;
size_t valuelen;
uint8_t flags;
} nghttp2_nv;
int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr, size_t deflate_hd_table_bufsize_max);
ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf, size_t buflen, const nghttp2_nv *nva, size_t nvlen);
size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, const nghttp2_nv *nva, size_t nvlen);
int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);
ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, const uint8_t *in, size_t inlen, int in_final);
int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
', 'libnghttp2.so');
try {
self::$ffi = FFI::cdef($header, 'libnghttp2.so');
} catch (\Throwable $exception) {
self::$ffi = FFI::cdef($header, 'libnghttp2.dylib');
}

self::$deflatePtrType = self::$ffi->type('nghttp2_hd_deflater*');
self::$inflatePtrType = self::$ffi->type('nghttp2_hd_inflater*');
Expand Down
29 changes: 29 additions & 0 deletions src/Internal/amp-hpack.h
@@ -0,0 +1,29 @@

#define FFI_SCOPE "amphp-hpack-nghttp2"
#define FFI_LIB "libnghttp2.so"

typedef struct nghttp2_hd_deflater nghttp2_hd_deflater;

typedef struct nghttp2_hd_inflater nghttp2_hd_inflater;

typedef struct {
uint8_t *name;
uint8_t *value;

size_t namelen;
size_t valuelen;

uint8_t flags;
} nghttp2_nv;

int nghttp2_hd_deflate_new(nghttp2_hd_deflater **deflater_ptr, size_t deflate_hd_table_bufsize_max);

ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf, size_t buflen, const nghttp2_nv *nva, size_t nvlen);

size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, const nghttp2_nv *nva, size_t nvlen);

int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr);

ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, const uint8_t *in, size_t inlen, int in_final);

int nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);

0 comments on commit 6c5407e

Please sign in to comment.