fix protocol error

merge_conn
fangdingjun 6 years ago
parent b141943c15
commit d41993b816

@ -147,7 +147,7 @@ func (c *Conn) run() {
errch := make(chan error) errch := make(chan error)
go func() { go func() {
buf := make([]byte, 4096) buf := make([]byte, 16*1024)
for { for {
n, err := c.conn.Read(buf) n, err := c.conn.Read(buf)
if err != nil { if err != nil {
@ -186,6 +186,7 @@ loop:
d1 := C.CBytes(d) d1 := C.CBytes(d)
ret1 := C.nghttp2_session_mem_recv(c.session, ret1 := C.nghttp2_session_mem_recv(c.session,
(*C.uchar)(d1), C.size_t(int(len(d)))) (*C.uchar)(d1), C.size_t(int(len(d))))
C.free(d1)
if int(ret1) < 0 { if int(ret1) < 0 {
c.err = fmt.Errorf("sesion recv error: %s", c.err = fmt.Errorf("sesion recv error: %s",
C.GoString(C.nghttp2_strerror(ret))) C.GoString(C.nghttp2_strerror(ret)))

@ -32,7 +32,9 @@ func TestHttp2Client(t *testing.T) {
param.Add("e", "b") param.Add("e", "b")
param.Add("f", "d") param.Add("f", "d")
data := bytes.NewReader([]byte(param.Encode())) data := bytes.NewReader([]byte(param.Encode()))
req, _ := http.NewRequest("POST", "https://www.simicloud.com/media/httpbin/post?a=b&c=d", data) req, _ := http.NewRequest("POST",
"https://www.simicloud.com/media/httpbin/post?a=b&c=d",
data)
log.Printf("%+v", req) log.Printf("%+v", req)
req.Header.Set("accept", "*/*") req.Header.Set("accept", "*/*")
req.Header.Set("user-agent", "go-nghttp2/1.0") req.Header.Set("user-agent", "go-nghttp2/1.0")
@ -42,5 +44,14 @@ func TestHttp2Client(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
res.Write(os.Stderr) res.Write(os.Stderr)
req, _ = http.NewRequest("GET",
"https://www.simicloud.com/media/httpbin/get?a=b&c=d", nil)
res, err = h2conn.CreateRequest(req)
if err != nil {
t.Fatal(err)
}
res.Write(os.Stderr)
log.Println("end") log.Println("end")
} }

@ -164,7 +164,7 @@ void init_callbacks(nghttp2_session_callbacks *callbacks)
nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); nghttp2_session_callbacks_set_send_callback(callbacks, send_callback);
nghttp2_session_callbacks_set_recv_callback(callbacks, recv_callback); nghttp2_session_callbacks_set_recv_callback(callbacks, recv_callback);
nghttp2_session_callbacks_set_error_callback2(callbacks, on_error_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, nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks,
on_frame_recv_callback); on_frame_recv_callback);
@ -190,7 +190,7 @@ nghttp2_session *init_client_session(size_t data)
nghttp2_session_callbacks *callbacks; nghttp2_session_callbacks *callbacks;
nghttp2_session_callbacks_new(&callbacks); nghttp2_session_callbacks_new(&callbacks);
init_callbacks(callbacks); init_callbacks(callbacks);
ret = nghttp2_session_server_new(&session, callbacks, (void *)((int *)(data))); ret = nghttp2_session_client_new(&session, callbacks, (void *)((int *)(data)));
if (session == NULL) if (session == NULL)
{ {
printf("c init session failed: %s\n", nghttp2_strerror(ret)); printf("c init session failed: %s\n", nghttp2_strerror(ret));

Loading…
Cancel
Save