28 #include "webserver.h"
33 #include <curl/curl.h>
45 static pthread_mutex_t
lock;
48 static hpd_ws_t *
ws = NULL;
52 curl_global_init(CURL_GLOBAL_ALL);
57 curl_global_cleanup();
60 static size_t data_from_curl(
char *buffer,
size_t buffer_size,
size_t nmemb,
char **userdata)
62 *userdata = malloc(buffer_size*nmemb + 1);
63 memcpy(*userdata, buffer, buffer_size*nmemb);
64 (*userdata)[buffer_size*nmemb] =
'\0';
66 return buffer_size*nmemb;
71 CURL *handle = curl_easy_init();
77 curl_easy_setopt(handle, CURLOPT_URL, url);
79 curl_easy_setopt(handle, CURLOPT_WRITEDATA, &userdata);
81 if((c = curl_easy_perform(handle)) != CURLE_OK)
83 fprintf(stderr,
"curl_easy_perform failed: %s\n", curl_easy_strerror(c));
87 curl_easy_cleanup(handle);
92 perror(
"Could not initialize curl: ");
112 if(strstr(received, contains) != NULL)
118 printf(
"The following bad string was received: %s\n", received);
127 pthread_mutex_lock(&
lock);
129 pthread_mutex_unlock(&
lock);
136 for(i = 0; i<arguments->
assaults; i++)
163 printf(
"\nError creating thread: %i %i %s",threads, err,strerror(err));
170 pthread_join((
threadID[threads]), NULL);
184 printf(
"Running tcpd tests:\n");
186 printf(
"\tBasic connection test: ");
195 printf(
"\tBasic multithreaded stress test: ");
211 const char *buf,
size_t len)
213 ws_conn_sendf(conn,
"HTTP/1.1 200 OK\r\n\r\nHello");
225 fprintf(stderr,
"Sending stop signal\n");
229 static void exit_cb(EV_P_ ev_async *watcher,
int revents)
231 fprintf(stderr,
"Stopping tcpd\n");
238 ev_break(
loop, EVBREAK_ALL);
251 struct ws_settings settings = WS_SETTINGS_DEFAULT;
252 settings.port = HPD_TCPD_P_HTTP_ALT;
257 printf(
"Debugging is set\n");
265 ws = ws_create(&settings,
loop);
275 int main(
int argc,
char *argv[])
278 pthread_t server_thread;
287 pthread_join(server_thread, NULL);
289 if (stat == 0)
return 1;
static size_t data_from_curl(char *buffer, size_t buffer_size, size_t nmemb, char **userdata)
int main(int argc, char *argv[])
static void * get_mt_loop(void *args)
static void cleanup_libcurl()
static int on_receive(hpd_ws_t *instance, hpd_ws_conn_t *conn, void *ctx, void **data, const char *buf, size_t len)
static int multithreaded_results
static char * simple_get_request(char *url)
static int basic_get_multithreaded_stress_test(char *url, char *contains)
static int basic_get_contains_test(char *url, char *contains)
static void init_libcurl()
static void cleanup_tests()
static void set_bad_multithreaded_result()
static struct ev_async exit_watcher
static void * webserver_thread(void *arg)
static void exit_cb(EV_P_ ev_async *watcher, int revents)
static pthread_t threadID[NTHREADS]
static void exit_handler(int sig)
static struct ev_loop * loop
static pthread_mutex_t lock