File tree Expand file tree Collapse file tree 2 files changed +16
-14
lines changed
grpc/grpc-core/src/nativeMain/kotlin/kotlinx/rpc/grpc/internal Expand file tree Collapse file tree 2 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ internal class GrpcServerCredentials(
5656 }
5757}
5858
59+ // TODO: don't hardcode the host
60+ private val HOST = " 0.0.0.0"
61+
5962internal class NativeServer (
6063 override val port : Int ,
6164 // we must reference them, otherwise the credentials are getting garbage collected
@@ -77,7 +80,7 @@ internal class NativeServer(
7780
7881 init {
7982 grpc_server_register_completion_queue(raw, cq.raw, null )
80- grpc_server_add_http2_port(raw, " localhost :$port " , credentials.raw)
83+ grpc_server_add_http2_port(raw, " $HOST :$port " , credentials.raw)
8184 addUnknownService()
8285 }
8386
@@ -113,10 +116,10 @@ internal class NativeServer(
113116 // to construct a valid HTTP/2 path, we must prepend the name with a slash.
114117 // the user does not do this to align it with the java implementation.
115118 val name = " /" + desc.getFullMethodName()
116- // TODO: don't hardcode localhost
117119 val tag = grpc_server_register_method(
118120 server = raw,
119121 method = name,
122+ // TODO: don't hardcode localhost
120123 host = " localhost:$port " ,
121124 payload_handling = grpc_server_register_method_payload_handling.GRPC_SRM_PAYLOAD_NONE ,
122125 flags = 0u
Original file line number Diff line number Diff line change @@ -199,17 +199,17 @@ internal class NativeServerCall<Request, Response>(
199199 }
200200 }
201201 } else {
202- val msg = methodDescriptor.getRequestMarshaller()
203- .parse(buf.toKotlin().asInputStream() )
204-
205- // destroy the buffer, we don't need it anymore
206- grpc_byte_buffer_destroy(buf)
207-
208- // Mark that we have received at least one request message
209- receivedFirstMessage = true
210-
211- callbackMutex.withLock {
212- listener.onMessage(msg )
202+ try {
203+ val msg = methodDescriptor.getRequestMarshaller( )
204+ .parse(buf.toKotlin().asInputStream())
205+ // Mark that we have received at least one request message
206+ receivedFirstMessage = true
207+ callbackMutex.withLock {
208+ listener.onMessage(msg)
209+ }
210+ } finally {
211+ // destroy the buffer, we don't need it anymore
212+ grpc_byte_buffer_destroy(buf )
213213 }
214214 }
215215 }
@@ -306,7 +306,6 @@ private class DeferredCallListener<T> : ServerCall.Listener<T>() {
306306 // fast path (delegate is already set)
307307 f(d); return
308308 }
309- println (" delivering to queue..." )
310309 // slow path: re-check under lock
311310 val dd = mutex.withLock {
312311 val cur = delegate
You can’t perform that action at this time.
0 commit comments