File tree 1 file changed +14
-2
lines changed 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -3347,8 +3347,18 @@ int main(int argc, char ** argv) {
3347
3347
llama_backend_free ();
3348
3348
};
3349
3349
3350
- // bind HTTP listen port, run the HTTP server in a thread
3351
- if (!svr->bind_to_port (params.hostname , params.port )) {
3350
+ // bind HTTP listen port
3351
+ bool was_bound = false ;
3352
+ if (params.port == 0 ) {
3353
+ int bound_port = svr->bind_to_any_port (params.hostname );
3354
+ if ((was_bound = (bound_port >= 0 ))) {
3355
+ params.port = bound_port;
3356
+ }
3357
+ } else {
3358
+ was_bound = svr->bind_to_port (params.hostname , params.port );
3359
+ }
3360
+
3361
+ if (!was_bound) {
3352
3362
// LOG_ERROR("couldn't bind HTTP server socket", {
3353
3363
// {"hostname", params.hostname},
3354
3364
// {"port", params.port},
@@ -3357,6 +3367,8 @@ int main(int argc, char ** argv) {
3357
3367
clean_up ();
3358
3368
return 1 ;
3359
3369
}
3370
+
3371
+ // run the HTTP server in a thread
3360
3372
std::thread t ([&]() { svr->listen_after_bind (); });
3361
3373
svr->wait_until_ready ();
3362
3374
You can’t perform that action at this time.
0 commit comments