@@ -10,8 +10,6 @@ import (
1010 "github.com/ebitengine/purego"
1111)
1212
13- // bidirectionalStreamCallbackStruct mirrors the C struct bidirectional_stream_callback.
14- // It contains 8 function pointers in the same order as the C struct.
1513type bidirectionalStreamCallbackStruct struct {
1614 onStreamReady uintptr
1715 onResponseHeadersReceived uintptr
@@ -23,14 +21,12 @@ type bidirectionalStreamCallbackStruct struct {
2321 onCanceled uintptr
2422}
2523
26- // bidirectionalStreamHeaderArray mirrors the C struct bidirectional_stream_header_array
2724type bidirectionalStreamHeaderArray struct {
2825 count uintptr
2926 capacity uintptr
3027 headers uintptr
3128}
3229
33- // bidirectionalStreamHeader mirrors the C struct bidirectional_stream_header
3430type bidirectionalStreamHeader struct {
3531 key uintptr // const char*
3632 value uintptr // const char*
@@ -52,7 +48,7 @@ func init() {
5248func bsOnStreamReadyCallback (stream uintptr ) uintptr {
5349 cb := instanceOfBidirectionalStreamCallback (stream )
5450 if cb == nil {
55- return 0 // Post-destroy callback, silently ignore
51+ return 0
5652 }
5753 cb .OnStreamReady (BidirectionalStream {stream })
5854 return 0
@@ -61,7 +57,7 @@ func bsOnStreamReadyCallback(stream uintptr) uintptr {
6157func bsOnResponseHeadersReceivedCallback (stream , headers , negotiatedProtocol uintptr ) uintptr {
6258 cb := instanceOfBidirectionalStreamCallback (stream )
6359 if cb == nil {
64- return 0 // Post-destroy callback, silently ignore
60+ return 0
6561 }
6662 headerMap := parseHeaderArray (headers )
6763 cb .OnResponseHeadersReceived (BidirectionalStream {stream }, headerMap , cronet .GoString (negotiatedProtocol ))
@@ -71,7 +67,7 @@ func bsOnResponseHeadersReceivedCallback(stream, headers, negotiatedProtocol uin
7167func bsOnReadCompletedCallback (stream , data uintptr , bytesRead int32 ) uintptr {
7268 cb := instanceOfBidirectionalStreamCallback (stream )
7369 if cb == nil {
74- return 0 // Post-destroy callback, silently ignore
70+ return 0
7571 }
7672 cb .OnReadCompleted (BidirectionalStream {stream }, int (bytesRead ))
7773 return 0
@@ -80,7 +76,7 @@ func bsOnReadCompletedCallback(stream, data uintptr, bytesRead int32) uintptr {
8076func bsOnWriteCompletedCallback (stream , data uintptr ) uintptr {
8177 cb := instanceOfBidirectionalStreamCallback (stream )
8278 if cb == nil {
83- return 0 // Post-destroy callback, silently ignore
79+ return 0
8480 }
8581 cb .OnWriteCompleted (BidirectionalStream {stream })
8682 return 0
@@ -89,7 +85,7 @@ func bsOnWriteCompletedCallback(stream, data uintptr) uintptr {
8985func bsOnResponseTrailersReceivedCallback (stream , trailers uintptr ) uintptr {
9086 cb := instanceOfBidirectionalStreamCallback (stream )
9187 if cb == nil {
92- return 0 // Post-destroy callback, silently ignore
88+ return 0
9389 }
9490 trailerMap := parseHeaderArray (trailers )
9591 cb .OnResponseTrailersReceived (BidirectionalStream {stream }, trailerMap )
@@ -99,37 +95,33 @@ func bsOnResponseTrailersReceivedCallback(stream, trailers uintptr) uintptr {
9995func bsOnSucceededCallback (stream uintptr ) uintptr {
10096 cb := instanceOfBidirectionalStreamCallback (stream )
10197 if cb == nil {
102- return 0 // Post-destroy callback, silently ignore
98+ return 0
10399 }
104100 cb .OnSucceeded (BidirectionalStream {stream })
105- // Terminal callback - safe to cleanup
106101 cleanupBidirectionalStream (stream )
107102 return 0
108103}
109104
110105func bsOnFailedCallback (stream uintptr , netError int32 ) uintptr {
111106 cb := instanceOfBidirectionalStreamCallback (stream )
112107 if cb == nil {
113- return 0 // Post-destroy callback, silently ignore
108+ return 0
114109 }
115110 cb .OnFailed (BidirectionalStream {stream }, int (netError ))
116- // Terminal callback - safe to cleanup
117111 cleanupBidirectionalStream (stream )
118112 return 0
119113}
120114
121115func bsOnCanceledCallback (stream uintptr ) uintptr {
122116 cb := instanceOfBidirectionalStreamCallback (stream )
123117 if cb == nil {
124- return 0 // Post-destroy callback, silently ignore
118+ return 0
125119 }
126120 cb .OnCanceled (BidirectionalStream {stream })
127- // Terminal callback - safe to cleanup
128121 cleanupBidirectionalStream (stream )
129122 return 0
130123}
131124
132- // parseHeaderArray parses the bidirectional_stream_header_array pointer into a Go map
133125func parseHeaderArray (ptr uintptr ) map [string ]string {
134126 if ptr == 0 {
135127 return nil
0 commit comments