enclave-tls: allow enclave-tls-server to be alive by default
Fixes:
@@ -91,7 +91,7 @@ int sgx_create_report(sgx_report_t *report)
}
#endif
-int enclave_tls_server_startup(int fd, enclave_tls_log_level_t log_level,
+int enclave_tls_server_startup(int sockfd, enclave_tls_log_level_t log_level,
char *attester_type, char *verifier_type,
char *tls_type, char *crypto_type, bool mutual)
{
@@ -117,7 +117,19 @@ int enclave_tls_server_startup(int fd, enclave_tls_log_level_t log_level,
return -1;
}
- ret = enclave_tls_negotiate(handle, fd);
+ /* Accept client connections */
+ struct sockaddr_in c_addr;
+ socklen_t size = sizeof(c_addr);
+ while (1) {
+ printf("Waiting for a connection ...\n");
+
+ int connd = accept(sockfd, (struct sockaddr *)&c_addr, &size);
+ if (connd < 0) {
+ perror("Failed to call accept()");
+ return -1;
+ }
+
+ ret = enclave_tls_negotiate(handle, connd);
if (ret != ENCLAVE_TLS_ERR_NONE) {
fprintf(stderr, "failed to negotiate %#x\n", ret);
goto err;
@@ -162,6 +174,9 @@ int enclave_tls_server_startup(int fd, enclave_tls_log_level_t log_level,
goto err;
}
+ close(connd);
+ }
+
err:
ret = enclave_tls_cleanup(handle);
if (ret != ENCLAVE_TLS_ERR_NONE) {
@@ -277,18 +292,7 @@ int main(int argc, char **argv)
return -1;
}
- printf("Waiting for a connection ...\n");
-
- /* Accept client connections */
- struct sockaddr_in c_addr;
- socklen_t size = sizeof(c_addr);
- int connd = accept(sockfd, (struct sockaddr *)&c_addr, &size);
- if (connd < 0) {
- perror("Failed to call accept()");
- return -1;
- }
-
- return enclave_tls_server_startup(connd, log_level,
+ return enclave_tls_server_startup(sockfd, log_level,
attester_type, verifier_type,
tls_type, crypto_type, mutual);
}
