mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-25 07:41:10 +00:00
Start rhizome HTTP server on first available port
This commit is contained in:
parent
1193763abd
commit
08a8ec13e8
@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#define RHIZOME_CRYPT_PAGE_SIZE 4096
|
#define RHIZOME_CRYPT_PAGE_SIZE 4096
|
||||||
|
|
||||||
#define RHIZOME_HTTP_PORT 4110
|
#define RHIZOME_HTTP_PORT 4110
|
||||||
|
#define RHIZOME_HTTP_PORT_MAX 4150
|
||||||
|
|
||||||
extern long long rhizome_voice_timeout;
|
extern long long rhizome_voice_timeout;
|
||||||
|
|
||||||
|
@ -96,12 +96,18 @@ static int rhizome_http_server_start()
|
|||||||
return WHY("Failed to start rhizome HTTP server");
|
return WHY("Failed to start rhizome HTTP server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Starting at the default port, look for a free port to bind to. */
|
||||||
struct sockaddr_in address;
|
struct sockaddr_in address;
|
||||||
bzero((char *) &address, sizeof(address));
|
bzero((char *) &address, sizeof(address));
|
||||||
address.sin_family = AF_INET;
|
address.sin_family = AF_INET;
|
||||||
address.sin_addr.s_addr = INADDR_ANY;
|
address.sin_addr.s_addr = INADDR_ANY;
|
||||||
address.sin_port = htons(RHIZOME_HTTP_PORT);
|
int port = RHIZOME_HTTP_PORT;
|
||||||
if (bind(rhizome_server_socket, (struct sockaddr *) &address, sizeof(address)) == -1) {
|
int result = -1;
|
||||||
|
do {
|
||||||
|
address.sin_port = htons(port);
|
||||||
|
result = bind(rhizome_server_socket, (struct sockaddr *) &address, sizeof(address));
|
||||||
|
} while (result == -1 && errno == EADDRINUSE && ++port <= RHIZOME_HTTP_PORT_MAX);
|
||||||
|
if (result == -1) {
|
||||||
WHY_perror("bind");
|
WHY_perror("bind");
|
||||||
close(rhizome_server_socket);
|
close(rhizome_server_socket);
|
||||||
rhizome_server_socket = -1;
|
rhizome_server_socket = -1;
|
||||||
@ -122,6 +128,7 @@ static int rhizome_http_server_start()
|
|||||||
return WHY("Failed to start rhizome HTTP server");
|
return WHY("Failed to start rhizome HTTP server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INFOF("Started Rhizome HTTP server on port %d", port);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user