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(
56
56
}
57
57
}
58
58
59
+ // TODO: don't hardcode the host
60
+ private val HOST = " 0.0.0.0"
61
+
59
62
internal class NativeServer (
60
63
override val port : Int ,
61
64
// we must reference them, otherwise the credentials are getting garbage collected
@@ -77,7 +80,7 @@ internal class NativeServer(
77
80
78
81
init {
79
82
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)
81
84
addUnknownService()
82
85
}
83
86
@@ -113,10 +116,10 @@ internal class NativeServer(
113
116
// to construct a valid HTTP/2 path, we must prepend the name with a slash.
114
117
// the user does not do this to align it with the java implementation.
115
118
val name = " /" + desc.getFullMethodName()
116
- // TODO: don't hardcode localhost
117
119
val tag = grpc_server_register_method(
118
120
server = raw,
119
121
method = name,
122
+ // TODO: don't hardcode localhost
120
123
host = " localhost:$port " ,
121
124
payload_handling = grpc_server_register_method_payload_handling.GRPC_SRM_PAYLOAD_NONE ,
122
125
flags = 0u
Original file line number Diff line number Diff line change @@ -199,17 +199,17 @@ internal class NativeServerCall<Request, Response>(
199
199
}
200
200
}
201
201
} 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 )
213
213
}
214
214
}
215
215
}
@@ -306,7 +306,6 @@ private class DeferredCallListener<T> : ServerCall.Listener<T>() {
306
306
// fast path (delegate is already set)
307
307
f(d); return
308
308
}
309
- println (" delivering to queue..." )
310
309
// slow path: re-check under lock
311
310
val dd = mutex.withLock {
312
311
val cur = delegate
You can’t perform that action at this time.
0 commit comments