#include <stdio.h>
#include "libwebsockets.h"

int callback_data_ws(struct lws* wsi, enum lws_callback_reasons reason,
	void* user, void* in, size_t len) {
	return 0;
}
pthread_mutex_t  mutex;  
struct lws_protocols protocols_data_ws[] = { { "ND_ws", callback_data_ws, 0, 0}, { NULL, NULL, 0, 0 } };
char ndhomepath[100];
void * threadFunc1(void * arg) {

	struct lws_context_creation_info dataContextInfo;
	struct lws_context* dataContext;
	char* websocketUrl = NULL;

	memset(&dataContextInfo, 0, sizeof dataContextInfo);
	  dataContextInfo.port = CONTEXT_PORT_NO_LISTEN;
	  
	    dataContextInfo.protocols = protocols_data_ws;
	    dataContextInfo.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
	    dataContextInfo.client_ssl_cert_filepath = ndhomepath;
	  dataContextInfo.client_ssl_cipher_list = "DEFAULT:@SECLEVEL=1";

	  pthread_mutex_lock(&mutex);
	  fprintf(stderr, "the contx start\n");
	  dataContext = lws_create_context(&dataContextInfo);
	  pthread_mutex_unlock(&mutex);
	  fprintf(stderr, "the contx %p\n", dataContext);

	  sleep(20);
		return NULL;
}

int main() {

	char *ndhome = getenv("NDHOME");
	char ndhomepath[100];
	sprintf(ndhomepath,"%s/config/server.pem",ndhome);
	pthread_mutex_init(&mutex, NULL);
	pthread_t threadId1[10];

	int ret;
	size_t size = 512*1024;;
	for(int i = 0; i <30;i++) {
		int err = pthread_create(&threadId1[i], NULL, &threadFunc1, NULL);
	}

	pthread_join(threadId1[0], NULL);
}