From ade4dcb8a74b5b2bb9f67847473a1a7444a0e3f7 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Thu, 12 Jul 2018 15:06:53 +0800 Subject: [PATCH] remove some C wrapper function --- _nghttp2.h | 6 +++--- conn.go | 12 +++++++----- nghttp2.c | 33 +++++++++++++++++++++++---------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/_nghttp2.h b/_nghttp2.h index ab8c8be..436fcb4 100644 --- a/_nghttp2.h +++ b/_nghttp2.h @@ -42,10 +42,10 @@ int nv_array_set(struct nv_array *a, int index, struct nv_array *new_nv_array(size_t n); -int32_t submit_request(nghttp2_session *session, nghttp2_nv *hdrs, size_t hdrlen, - nghttp2_data_provider *dp); +//int32_t submit_request(nghttp2_session *session, nghttp2_nv *hdrs, size_t hdrlen, +// nghttp2_data_provider *dp); -int send_client_connection_header(nghttp2_session *session); +//int send_client_connection_header(nghttp2_session *session); nghttp2_session *init_nghttp2_client_session(size_t data); nghttp2_session *init_nghttp2_server_session(size_t data); diff --git a/conn.go b/conn.go index dee4790..6188761 100644 --- a/conn.go +++ b/conn.go @@ -49,7 +49,7 @@ func Client(c net.Conn) (*ClientConn, error) { if conn.session == nil { return nil, fmt.Errorf("init session failed") } - ret := C.send_client_connection_header(conn.session) + ret := C.nghttp2_submit_settings(conn.session, 0, nil, 0) if int(ret) < 0 { conn.Close() return nil, fmt.Errorf("submit settings error: %s", @@ -223,13 +223,14 @@ func (c *ClientConn) Connect(addr string) (cs *ClientStream, statusCode int, err dp, cdp = newDataProvider(c.lock) c.lock.Lock() - streamID := C.submit_request(c.session, nva.nv, C.size_t(nvIndex), cdp) + streamID := C.nghttp2_submit_request(c.session, nil, + nva.nv, C.size_t(nvIndex), cdp, nil) c.lock.Unlock() C.delete_nv_array(nva) if int(streamID) < 0 { - return nil, http.StatusServiceUnavailable, fmt.Errorf("submit request error: %s", - C.GoString(C.nghttp2_strerror(streamID))) + return nil, http.StatusServiceUnavailable, fmt.Errorf( + "submit request error: %s", C.GoString(C.nghttp2_strerror(streamID))) } if dp != nil { dp.streamID = int(streamID) @@ -314,7 +315,8 @@ func (c *ClientConn) CreateRequest(req *http.Request) (*http.Response, error) { } c.lock.Lock() - streamID := C.submit_request(c.session, nva.nv, C.size_t(nvIndex), cdp) + streamID := C.nghttp2_submit_request(c.session, nil, + nva.nv, C.size_t(nvIndex), cdp, nil) c.lock.Unlock() C.delete_nv_array(nva) diff --git a/nghttp2.c b/nghttp2.c index ffa5a4d..ee8540b 100644 --- a/nghttp2.c +++ b/nghttp2.c @@ -1,6 +1,11 @@ #include "_nghttp2.h" -int on_error_callback(nghttp2_session *session, const char *msg, size_t len, void *user_data); +int on_error_callback(nghttp2_session *session, const char *msg, + size_t len, void *user_data); + +int on_invalid_frame_recv_callback(nghttp2_session *session, + const nghttp2_frame *frame, + int lib_error_code, void *user_data); static ssize_t server_send_callback(nghttp2_session *session, const uint8_t *data, size_t length, @@ -101,6 +106,9 @@ nghttp2_session *init_nghttp2_server_session(size_t data) nghttp2_session_callbacks_set_on_stream_close_callback( callbacks, on_server_stream_close_callback); + nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(callbacks, + on_invalid_frame_recv_callback); + nghttp2_session_callbacks_set_on_data_chunk_recv_callback( callbacks, on_server_data_chunk_recv_callback); nghttp2_session_callbacks_set_on_header_callback(callbacks, @@ -119,7 +127,7 @@ nghttp2_session *init_nghttp2_server_session(size_t data) int send_server_connection_header(nghttp2_session *session) { nghttp2_settings_entry iv[1] = { - {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 1000}}; + {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}}; int rv; rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, @@ -191,7 +199,8 @@ static int on_client_begin_headers_callback(nghttp2_session *session, } int on_invalid_frame_recv_callback(nghttp2_session *session, - const nghttp2_frame *frame, int lib_error_code, void *user_data) + const nghttp2_frame *frame, + int lib_error_code, void *user_data) { printf("on_invalid_frame_recv, frame %d, code %d, msg %s\n", frame->hd.type, @@ -199,7 +208,7 @@ int on_invalid_frame_recv_callback(nghttp2_session *session, nghttp2_strerror(lib_error_code)); return 0; } - +#if 0 static int on_client_frame_send_callback(nghttp2_session *session, const nghttp2_frame *frame, void *user_data) { @@ -235,7 +244,7 @@ static int on_client_frame_send_callback(nghttp2_session *session, } return 0; } - +#endif static int on_client_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame, void *user_data) { @@ -288,6 +297,7 @@ static ssize_t data_source_read_callback(nghttp2_session *session, int32_t strea } return ret; } + int on_error_callback(nghttp2_session *session, const char *msg, size_t len, void *user_data) { @@ -302,7 +312,8 @@ void init_client_callbacks(nghttp2_session_callbacks *callbacks) //nghttp2_session_callbacks_set_recv_callback(callbacks, client_recv_callback); //nghttp2_session_callbacks_set_error_callback2(callbacks, on_error_callback); - nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(callbacks, on_invalid_frame_recv_callback); + nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(callbacks, + on_invalid_frame_recv_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_client_frame_recv_callback); @@ -334,11 +345,11 @@ nghttp2_session *init_nghttp2_client_session(size_t data) } return session; } - +#if 0 int send_client_connection_header(nghttp2_session *session) { - nghttp2_settings_entry iv[1] = { - {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}}; + //nghttp2_settings_entry iv[1] = { + // {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}}; int rv; /* client 24 bytes magic string will be sent by nghttp2 library */ @@ -356,7 +367,8 @@ int send_client_connection_header(nghttp2_session *session) */ return rv; } - +#endif +#if 0 int32_t submit_request(nghttp2_session *session, nghttp2_nv *hdrs, size_t hdrlen, nghttp2_data_provider *dp) { @@ -389,6 +401,7 @@ int32_t submit_request(nghttp2_session *session, nghttp2_nv *hdrs, size_t hdrlen return stream_id; } +#endif struct nv_array *new_nv_array(size_t n) {