remove some C wrapper function

merge_conn
fangdingjun 6 years ago
parent 994f455368
commit ade4dcb8a7

@ -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);

@ -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)

@ -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)
{

Loading…
Cancel
Save