make all C callback functions unexported

merge_conn
fangdingjun 6 years ago
parent 2b04f2d580
commit 3409e5e702

@ -7,23 +7,23 @@
#define ARRLEN(x) (sizeof(x) / sizeof(x[0])) #define ARRLEN(x) (sizeof(x) / sizeof(x[0]))
extern ssize_t OnClientDataRecvCallback(void *, void *data, size_t); extern ssize_t onClientDataRecvCallback(void *, void *data, size_t);
extern ssize_t OnClientDataSendCallback(void *, void *data, size_t); extern ssize_t onClientDataSendCallback(void *, void *data, size_t);
extern ssize_t OnDataSourceReadCallback(void *, void *, size_t); extern ssize_t onDataSourceReadCallback(void *, void *, size_t);
extern int OnClientDataChunkRecv(void *, int, void *, size_t); extern int onClientDataChunkRecv(void *, int, void *, size_t);
extern int OnClientBeginHeaderCallback(void *, int); extern int onClientBeginHeaderCallback(void *, int);
extern int OnClientHeaderCallback(void *, int, void *, int, void *, int); extern int onClientHeaderCallback(void *, int, void *, int, void *, int);
extern int OnClientHeadersDoneCallback(void *, int); extern int onClientHeadersDoneCallback(void *, int);
extern int OnClientStreamClose(void *, int); extern int onClientStreamClose(void *, int);
extern ssize_t OnServerDataRecvCallback(void *, void *data, size_t); extern ssize_t onServerDataRecvCallback(void *, void *data, size_t);
extern ssize_t OnServerDataSendCallback(void *, void *data, size_t); extern ssize_t onServerDataSendCallback(void *, void *data, size_t);
extern int OnServerDataChunkRecv(void *, int, void *, size_t); extern int onServerDataChunkRecv(void *, int, void *, size_t);
extern int OnServerBeginHeaderCallback(void *, int); extern int onServerBeginHeaderCallback(void *, int);
extern int OnServerHeaderCallback(void *, int, void *, int, void *, int); extern int onServerHeaderCallback(void *, int, void *, int, void *, int);
extern int OnServerStreamEndCallback(void *, int); extern int onServerStreamEndCallback(void *, int);
extern int OnServerHeadersDoneCallback(void *, int); extern int onServerHeadersDoneCallback(void *, int);
extern int OnServerStreamClose(void *, int); extern int onServerStreamClose(void *, int);
int send_server_connection_header(nghttp2_session *session); int send_server_connection_header(nghttp2_session *session);
struct nv_array struct nv_array

@ -23,11 +23,11 @@ const (
NGHTTP2_ERR_DEFERRED = -508 NGHTTP2_ERR_DEFERRED = -508
) )
// OnServerDataRecvCallback callback function for libnghttp2 library // onServerDataRecvCallback callback function for libnghttp2 library
// want receive data from network. // want receive data from network.
// //
//export OnServerDataRecvCallback //export onServerDataRecvCallback
func OnServerDataRecvCallback(ptr unsafe.Pointer, data unsafe.Pointer, func onServerDataRecvCallback(ptr unsafe.Pointer, data unsafe.Pointer,
length C.size_t) C.ssize_t { length C.size_t) C.ssize_t {
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
buf := make([]byte, int(length)) buf := make([]byte, int(length))
@ -41,11 +41,11 @@ func OnServerDataRecvCallback(ptr unsafe.Pointer, data unsafe.Pointer,
return C.ssize_t(n) return C.ssize_t(n)
} }
// OnServerDataSendCallback callback function for libnghttp2 library // onServerDataSendCallback callback function for libnghttp2 library
// want send data to network. // want send data to network.
// //
//export OnServerDataSendCallback //export onServerDataSendCallback
func OnServerDataSendCallback(ptr unsafe.Pointer, data unsafe.Pointer, func onServerDataSendCallback(ptr unsafe.Pointer, data unsafe.Pointer,
length C.size_t) C.ssize_t { length C.size_t) C.ssize_t {
//log.Println("server data send") //log.Println("server data send")
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
@ -58,10 +58,10 @@ func OnServerDataSendCallback(ptr unsafe.Pointer, data unsafe.Pointer,
return C.ssize_t(n) return C.ssize_t(n)
} }
// OnServerDataChunkRecv callback function for libnghttp2 library's data chunk recv. // onServerDataChunkRecv callback function for libnghttp2 library's data chunk recv.
// //
//export OnServerDataChunkRecv //export onServerDataChunkRecv
func OnServerDataChunkRecv(ptr unsafe.Pointer, streamID C.int, func onServerDataChunkRecv(ptr unsafe.Pointer, streamID C.int,
data unsafe.Pointer, length C.size_t) C.int { data unsafe.Pointer, length C.size_t) C.int {
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
s, ok := conn.streams[int(streamID)] s, ok := conn.streams[int(streamID)]
@ -74,10 +74,10 @@ func OnServerDataChunkRecv(ptr unsafe.Pointer, streamID C.int,
return C.int(length) return C.int(length)
} }
// OnServerBeginHeaderCallback callback function for begin begin header recv. // onServerBeginHeaderCallback callback function for begin begin header recv.
// //
//export OnServerBeginHeaderCallback //export onServerBeginHeaderCallback
func OnServerBeginHeaderCallback(ptr unsafe.Pointer, streamID C.int) C.int { func onServerBeginHeaderCallback(ptr unsafe.Pointer, streamID C.int) C.int {
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
var TLS tls.ConnectionState var TLS tls.ConnectionState
if tlsconn, ok := conn.conn.(*tls.Conn); ok { if tlsconn, ok := conn.conn.(*tls.Conn); ok {
@ -102,10 +102,10 @@ func OnServerBeginHeaderCallback(ptr unsafe.Pointer, streamID C.int) C.int {
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnServerHeaderCallback callback function for each header recv. // onServerHeaderCallback callback function for each header recv.
// //
//export OnServerHeaderCallback //export onServerHeaderCallback
func OnServerHeaderCallback(ptr unsafe.Pointer, streamID C.int, func onServerHeaderCallback(ptr unsafe.Pointer, streamID C.int,
name unsafe.Pointer, namelen C.int, name unsafe.Pointer, namelen C.int,
value unsafe.Pointer, valuelen C.int) C.int { value unsafe.Pointer, valuelen C.int) C.int {
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
@ -139,10 +139,10 @@ func OnServerHeaderCallback(ptr unsafe.Pointer, streamID C.int,
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnServerStreamEndCallback callback function for the stream when END_STREAM flag set // onServerStreamEndCallback callback function for the stream when END_STREAM flag set
// //
//export OnServerStreamEndCallback //export onServerStreamEndCallback
func OnServerStreamEndCallback(ptr unsafe.Pointer, streamID C.int) C.int { func onServerStreamEndCallback(ptr unsafe.Pointer, streamID C.int) C.int {
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
s, ok := conn.streams[int(streamID)] s, ok := conn.streams[int(streamID)]
@ -160,10 +160,10 @@ func OnServerStreamEndCallback(ptr unsafe.Pointer, streamID C.int) C.int {
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnServerHeadersDoneCallback callback function for the stream when all headers received. // onServerHeadersDoneCallback callback function for the stream when all headers received.
// //
//export OnServerHeadersDoneCallback //export onServerHeadersDoneCallback
func OnServerHeadersDoneCallback(ptr unsafe.Pointer, streamID C.int) C.int { func onServerHeadersDoneCallback(ptr unsafe.Pointer, streamID C.int) C.int {
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
s, ok := conn.streams[int(streamID)] s, ok := conn.streams[int(streamID)]
if !ok { if !ok {
@ -181,10 +181,10 @@ func OnServerHeadersDoneCallback(ptr unsafe.Pointer, streamID C.int) C.int {
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnServerStreamClose callback function for the stream when closed. // onServerStreamClose callback function for the stream when closed.
// //
//export OnServerStreamClose //export onServerStreamClose
func OnServerStreamClose(ptr unsafe.Pointer, streamID C.int) C.int { func onServerStreamClose(ptr unsafe.Pointer, streamID C.int) C.int {
conn := (*ServerConn)(ptr) conn := (*ServerConn)(ptr)
s, ok := conn.streams[int(streamID)] s, ok := conn.streams[int(streamID)]
if !ok { if !ok {
@ -197,13 +197,13 @@ func OnServerStreamClose(ptr unsafe.Pointer, streamID C.int) C.int {
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnDataSourceReadCallback callback function for libnghttp2 library // onDataSourceReadCallback callback function for libnghttp2 library
// want read data from data provider source, // want read data from data provider source,
// return NGHTTP2_ERR_DEFERRED will cause data frame defered, // return NGHTTP2_ERR_DEFERRED will cause data frame defered,
// application later call nghttp2_session_resume_data will re-quene the data frame // application later call nghttp2_session_resume_data will re-quene the data frame
// //
//export OnDataSourceReadCallback //export onDataSourceReadCallback
func OnDataSourceReadCallback(ptr unsafe.Pointer, func onDataSourceReadCallback(ptr unsafe.Pointer,
buf unsafe.Pointer, length C.size_t) C.ssize_t { buf unsafe.Pointer, length C.size_t) C.ssize_t {
//log.Println("data source read") //log.Println("data source read")
dp := (*dataProvider)(ptr) dp := (*dataProvider)(ptr)
@ -224,10 +224,10 @@ func OnDataSourceReadCallback(ptr unsafe.Pointer,
return C.ssize_t(n) return C.ssize_t(n)
} }
// OnClientDataChunkRecv callback function for libnghttp2 library data chunk received. // onClientDataChunkRecv callback function for libnghttp2 library data chunk received.
// //
//export OnClientDataChunkRecv //export onClientDataChunkRecv
func OnClientDataChunkRecv(ptr unsafe.Pointer, streamID C.int, func onClientDataChunkRecv(ptr unsafe.Pointer, streamID C.int,
buf unsafe.Pointer, length C.size_t) C.int { buf unsafe.Pointer, length C.size_t) C.int {
//log.Println("on data recv") //log.Println("on data recv")
conn := (*ClientConn)(ptr) conn := (*ClientConn)(ptr)
@ -252,10 +252,10 @@ func OnClientDataChunkRecv(ptr unsafe.Pointer, streamID C.int,
return C.int(length) return C.int(length)
} }
// OnClientDataRecvCallback callback function for libnghttp2 library want read data from network. // onClientDataRecvCallback callback function for libnghttp2 library want read data from network.
// //
//export OnClientDataRecvCallback //export onClientDataRecvCallback
func OnClientDataRecvCallback(ptr unsafe.Pointer, data unsafe.Pointer, size C.size_t) C.ssize_t { func onClientDataRecvCallback(ptr unsafe.Pointer, data unsafe.Pointer, size C.size_t) C.ssize_t {
//log.Println("data read req", int(size)) //log.Println("data read req", int(size))
conn := (*ClientConn)(ptr) conn := (*ClientConn)(ptr)
buf := make([]byte, int(size)) buf := make([]byte, int(size))
@ -271,10 +271,10 @@ func OnClientDataRecvCallback(ptr unsafe.Pointer, data unsafe.Pointer, size C.si
return C.ssize_t(n) return C.ssize_t(n)
} }
// OnClientDataSendCallback callback function for libnghttp2 library want send data to network. // onClientDataSendCallback callback function for libnghttp2 library want send data to network.
// //
//export OnClientDataSendCallback //export onClientDataSendCallback
func OnClientDataSendCallback(ptr unsafe.Pointer, data unsafe.Pointer, size C.size_t) C.ssize_t { func onClientDataSendCallback(ptr unsafe.Pointer, data unsafe.Pointer, size C.size_t) C.ssize_t {
//log.Println("data write req ", int(size)) //log.Println("data write req ", int(size))
conn := (*ClientConn)(ptr) conn := (*ClientConn)(ptr)
buf := C.GoBytes(data, C.int(size)) buf := C.GoBytes(data, C.int(size))
@ -287,10 +287,10 @@ func OnClientDataSendCallback(ptr unsafe.Pointer, data unsafe.Pointer, size C.si
return C.ssize_t(n) return C.ssize_t(n)
} }
// OnClientBeginHeaderCallback callback function for begin header receive. // onClientBeginHeaderCallback callback function for begin header receive.
// //
//export OnClientBeginHeaderCallback //export onClientBeginHeaderCallback
func OnClientBeginHeaderCallback(ptr unsafe.Pointer, streamID C.int) C.int { func onClientBeginHeaderCallback(ptr unsafe.Pointer, streamID C.int) C.int {
//log.Println("begin header") //log.Println("begin header")
conn := (*ClientConn)(ptr) conn := (*ClientConn)(ptr)
@ -313,10 +313,10 @@ func OnClientBeginHeaderCallback(ptr unsafe.Pointer, streamID C.int) C.int {
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnClientHeaderCallback callback function for each header received. // onClientHeaderCallback callback function for each header received.
// //
//export OnClientHeaderCallback //export onClientHeaderCallback
func OnClientHeaderCallback(ptr unsafe.Pointer, streamID C.int, func onClientHeaderCallback(ptr unsafe.Pointer, streamID C.int,
name unsafe.Pointer, namelen C.int, name unsafe.Pointer, namelen C.int,
value unsafe.Pointer, valuelen C.int) C.int { value unsafe.Pointer, valuelen C.int) C.int {
//log.Println("header") //log.Println("header")
@ -352,10 +352,10 @@ func OnClientHeaderCallback(ptr unsafe.Pointer, streamID C.int,
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnClientHeadersDoneCallback callback function for the stream when all headers received. // onClientHeadersDoneCallback callback function for the stream when all headers received.
// //
//export OnClientHeadersDoneCallback //export onClientHeadersDoneCallback
func OnClientHeadersDoneCallback(ptr unsafe.Pointer, streamID C.int) C.int { func onClientHeadersDoneCallback(ptr unsafe.Pointer, streamID C.int) C.int {
//log.Println("frame recv") //log.Println("frame recv")
conn := (*ClientConn)(ptr) conn := (*ClientConn)(ptr)
s, ok := conn.streams[int(streamID)] s, ok := conn.streams[int(streamID)]
@ -366,10 +366,10 @@ func OnClientHeadersDoneCallback(ptr unsafe.Pointer, streamID C.int) C.int {
return NGHTTP2_NO_ERROR return NGHTTP2_NO_ERROR
} }
// OnClientStreamClose callback function for the stream when closed. // onClientStreamClose callback function for the stream when closed.
// //
//export OnClientStreamClose //export onClientStreamClose
func OnClientStreamClose(ptr unsafe.Pointer, streamID C.int) C.int { func onClientStreamClose(ptr unsafe.Pointer, streamID C.int) C.int {
//log.Println("stream close") //log.Println("stream close")
conn := (*ClientConn)(ptr) conn := (*ClientConn)(ptr)

@ -4,7 +4,7 @@ static ssize_t server_send_callback(nghttp2_session *session,
const uint8_t *data, size_t length, const uint8_t *data, size_t length,
int flags, void *user_data) int flags, void *user_data)
{ {
return OnServerDataSendCallback(user_data, (void *)data, length); return onServerDataSendCallback(user_data, (void *)data, length);
} }
static int on_server_frame_recv_callback(nghttp2_session *session, static int on_server_frame_recv_callback(nghttp2_session *session,
@ -16,12 +16,12 @@ static int on_server_frame_recv_callback(nghttp2_session *session,
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat == NGHTTP2_HCAT_REQUEST) if (frame->headers.cat == NGHTTP2_HCAT_REQUEST)
{ {
OnServerHeadersDoneCallback(user_data, frame->hd.stream_id); onServerHeadersDoneCallback(user_data, frame->hd.stream_id);
} }
case NGHTTP2_DATA: case NGHTTP2_DATA:
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM)
{ {
OnServerStreamEndCallback(user_data, frame->hd.stream_id); onServerStreamEndCallback(user_data, frame->hd.stream_id);
} }
break; break;
} }
@ -34,7 +34,7 @@ static int on_server_stream_close_callback(nghttp2_session *session,
void *user_data) void *user_data)
{ {
OnServerStreamClose(user_data, stream_id); onServerStreamClose(user_data, stream_id);
return 0; return 0;
} }
@ -50,7 +50,7 @@ static int on_server_header_callback(nghttp2_session *session,
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat == NGHTTP2_HCAT_REQUEST) if (frame->headers.cat == NGHTTP2_HCAT_REQUEST)
{ {
OnServerHeaderCallback(user_data, frame->hd.stream_id, onServerHeaderCallback(user_data, frame->hd.stream_id,
(void *)name, namelen, (void *)value, valuelen); (void *)name, namelen, (void *)value, valuelen);
} }
break; break;
@ -64,7 +64,7 @@ static int on_server_data_chunk_recv_callback(nghttp2_session *session,
const uint8_t *data, const uint8_t *data,
size_t len, void *user_data) size_t len, void *user_data)
{ {
return OnServerDataChunkRecv(user_data, stream_id, (void *)data, len); return onServerDataChunkRecv(user_data, stream_id, (void *)data, len);
} }
static int on_server_begin_headers_callback(nghttp2_session *session, static int on_server_begin_headers_callback(nghttp2_session *session,
@ -77,7 +77,7 @@ static int on_server_begin_headers_callback(nghttp2_session *session,
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
if (frame->headers.cat == NGHTTP2_HCAT_REQUEST) if (frame->headers.cat == NGHTTP2_HCAT_REQUEST)
{ {
OnServerBeginHeaderCallback(user_data, frame->hd.stream_id); onServerBeginHeaderCallback(user_data, frame->hd.stream_id);
} }
break; break;
} }
@ -135,14 +135,14 @@ int send_server_connection_header(nghttp2_session *session)
static ssize_t client_send_callback(nghttp2_session *session, const uint8_t *data, static ssize_t client_send_callback(nghttp2_session *session, const uint8_t *data,
size_t length, int flags, void *user_data) size_t length, int flags, void *user_data)
{ {
return OnClientDataSendCallback(user_data, (void *)data, length); return onClientDataSendCallback(user_data, (void *)data, length);
} }
// recv_callback read data from network // recv_callback read data from network
static ssize_t client_recv_callback(nghttp2_session *session, uint8_t *buf, static ssize_t client_recv_callback(nghttp2_session *session, uint8_t *buf,
size_t length, int flags, void *user_data) size_t length, int flags, void *user_data)
{ {
return OnClientDataRecvCallback(user_data, (void *)buf, length); return onClientDataRecvCallback(user_data, (void *)buf, length);
} }
static int on_client_header_callback(nghttp2_session *session, static int on_client_header_callback(nghttp2_session *session,
@ -158,7 +158,7 @@ static int on_client_header_callback(nghttp2_session *session,
{ {
/* Print response headers for the initiated request. */ /* Print response headers for the initiated request. */
//print_header(stderr, name, namelen, value, valuelen); //print_header(stderr, name, namelen, value, valuelen);
OnClientHeaderCallback(user_data, frame->hd.stream_id, onClientHeaderCallback(user_data, frame->hd.stream_id,
(void *)name, namelen, (void *)value, valuelen); (void *)name, namelen, (void *)value, valuelen);
break; break;
} }
@ -179,7 +179,7 @@ static int on_client_begin_headers_callback(nghttp2_session *session,
{ {
//fprintf(stderr, "Response headers for stream ID=%d:\n", //fprintf(stderr, "Response headers for stream ID=%d:\n",
// frame->hd.stream_id); // frame->hd.stream_id);
OnClientBeginHeaderCallback(user_data, stream_id); onClientBeginHeaderCallback(user_data, stream_id);
} }
break; break;
} }
@ -242,7 +242,7 @@ static int on_client_frame_recv_callback(nghttp2_session *session,
if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE) if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE)
{ {
//fprintf(stderr, "All headers received\n"); //fprintf(stderr, "All headers received\n");
OnClientHeadersDoneCallback(user_data, frame->hd.stream_id); onClientHeadersDoneCallback(user_data, frame->hd.stream_id);
} }
break; break;
case NGHTTP2_RST_STREAM: case NGHTTP2_RST_STREAM:
@ -259,13 +259,13 @@ static int on_client_data_chunk_recv_callback(nghttp2_session *session, uint8_t
int32_t stream_id, const uint8_t *data, int32_t stream_id, const uint8_t *data,
size_t len, void *user_data) size_t len, void *user_data)
{ {
return OnClientDataChunkRecv(user_data, stream_id, (void *)data, len); return onClientDataChunkRecv(user_data, stream_id, (void *)data, len);
} }
static int on_client_stream_close_callback(nghttp2_session *session, int32_t stream_id, static int on_client_stream_close_callback(nghttp2_session *session, int32_t stream_id,
uint32_t error_code, void *user_data) uint32_t error_code, void *user_data)
{ {
OnClientStreamClose(user_data, stream_id); onClientStreamClose(user_data, stream_id);
return 0; return 0;
} }
@ -273,7 +273,7 @@ static ssize_t data_source_read_callback(nghttp2_session *session, int32_t strea
uint8_t *buf, size_t length, uint32_t *data_flags, uint8_t *buf, size_t length, uint32_t *data_flags,
nghttp2_data_source *source, void *user_data) nghttp2_data_source *source, void *user_data)
{ {
int ret = OnDataSourceReadCallback(source->ptr, buf, length); int ret = onDataSourceReadCallback(source->ptr, buf, length);
if (ret == 0) if (ret == 0)
{ {
*data_flags = NGHTTP2_DATA_FLAG_EOF; *data_flags = NGHTTP2_DATA_FLAG_EOF;

Loading…
Cancel
Save