mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-07 16:02:55 +03:00
Fixed MSVC issues
This commit is contained in:
1
Makefile
1
Makefile
@@ -1409,6 +1409,7 @@ ${OBJDIR}httplib_pthread_cond_signal${OBJEXT} : ${SRCDIR}httplib_pthread_cond
|
|||||||
|
|
||||||
${OBJDIR}httplib_pthread_cond_timedwait${OBJEXT} : ${SRCDIR}httplib_pthread_cond_timedwait.c \
|
${OBJDIR}httplib_pthread_cond_timedwait${OBJEXT} : ${SRCDIR}httplib_pthread_cond_timedwait.c \
|
||||||
${SRCDIR}httplib_main.h \
|
${SRCDIR}httplib_main.h \
|
||||||
|
${SRCDIR}httplib_pthread.h \
|
||||||
${INCDIR}libhttp.h
|
${INCDIR}libhttp.h
|
||||||
|
|
||||||
${OBJDIR}httplib_pthread_cond_wait${OBJEXT} : ${SRCDIR}httplib_pthread_cond_wait.c \
|
${OBJDIR}httplib_pthread_cond_wait${OBJEXT} : ${SRCDIR}httplib_pthread_cond_wait.c \
|
||||||
|
@@ -45,6 +45,14 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For our Posix emulation functions to open and close directories we need
|
* For our Posix emulation functions to open and close directories we need
|
||||||
@@ -73,6 +81,15 @@
|
|||||||
typedef HANDLE pthread_t;
|
typedef HANDLE pthread_t;
|
||||||
typedef HANDLE pthread_mutex_t;
|
typedef HANDLE pthread_mutex_t;
|
||||||
typedef DWORD pthread_key_t;
|
typedef DWORD pthread_key_t;
|
||||||
|
typedef void pthread_condattr_t;
|
||||||
|
typedef void pthread_mutexattr_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CRITICAL_SECTION threadIdSec;
|
||||||
|
struct httplib_workerTLS * waiting_thread; /* The chain of threads */
|
||||||
|
} pthread_cond_t;
|
||||||
|
|
||||||
|
#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
|
||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
@@ -793,9 +810,25 @@ enum {
|
|||||||
LIBHTTP_API int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_form_data_handler *fdh);
|
LIBHTTP_API int httplib_handle_form_request(struct httplib_connection *conn, struct httplib_form_data_handler *fdh);
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LIBHTTP_THREAD
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define LIBHTTP_THREAD unsigned __stdcall
|
||||||
|
#define LIBHTTP_THREAD_TYPE unsigned
|
||||||
|
#define LIBHTTP_THREAD_CALLING_CONV __stdcall
|
||||||
|
#define LIBHTTP_THREAD_RETNULL 0
|
||||||
|
#else /* _WIN32 */
|
||||||
|
#define LIBHTTP_THREAD void *
|
||||||
|
#define LIBHTTP_THREAD_TYPE void *
|
||||||
|
#define LIBHTTP_THREAD_CALLING_CONV
|
||||||
|
#define LIBHTTP_THREAD_RETNULL NULL
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
#endif /* LIBHTTP_THREAD */
|
||||||
|
|
||||||
/* Convenience function -- create detached thread.
|
/* Convenience function -- create detached thread.
|
||||||
Return: 0 on success, non-0 on error. */
|
Return: 0 on success, non-0 on error. */
|
||||||
typedef void *(*httplib_thread_func_t)(void *);
|
typedef LIBHTTP_THREAD_TYPE (LIBHTTP_THREAD_CALLING_CONV *httplib_thread_func_t)(void *);
|
||||||
LIBHTTP_API int httplib_start_thread(httplib_thread_func_t f, void *p);
|
LIBHTTP_API int httplib_start_thread(httplib_thread_func_t f, void *p);
|
||||||
|
|
||||||
|
|
||||||
@@ -865,8 +898,7 @@ LIBHTTP_API void httplib_cry(const struct httplib_connection *conn, PRINTF_FORMA
|
|||||||
On success, valid httplib_connection object.
|
On success, valid httplib_connection object.
|
||||||
On error, NULL. Se error_buffer for details.
|
On error, NULL. Se error_buffer for details.
|
||||||
*/
|
*/
|
||||||
LIBHTTP_API struct httplib_connection *
|
LIBHTTP_API struct httplib_connection *httplib_connect_websocket_client( const char *host,
|
||||||
httplib_connect_websocket_client(const char *host,
|
|
||||||
int port,
|
int port,
|
||||||
int use_ssl,
|
int use_ssl,
|
||||||
char *error_buffer,
|
char *error_buffer,
|
||||||
@@ -940,18 +972,6 @@ LIBHTTP_API int httplib_get_response(struct httplib_connection *conn, char *ebuf
|
|||||||
*/
|
*/
|
||||||
LIBHTTP_API unsigned httplib_check_feature(unsigned feature);
|
LIBHTTP_API unsigned httplib_check_feature(unsigned feature);
|
||||||
|
|
||||||
#ifndef LIBHTTP_THREAD
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#define LIBHTTP_THREAD unsigned __stcall
|
|
||||||
#define LIBHTTP_THREAD_RETNULL 0
|
|
||||||
#else /* _WIN32 */
|
|
||||||
#define LIBHTTP_THREAD void *
|
|
||||||
#define LIBHTTP_THREAD_RETNULL NULL
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
#endif /* LIBHTTP_THREAD */
|
|
||||||
|
|
||||||
typedef void (*httplib_alloc_callback_func)( const char *file, unsigned line, const char *action, int64_t current_bytes, int64_t total_blocks, int64_t total_bytes );
|
typedef void (*httplib_alloc_callback_func)( const char *file, unsigned line, const char *action, int64_t current_bytes, int64_t total_blocks, int64_t total_bytes );
|
||||||
|
|
||||||
#define httplib_calloc(a, b) XX_httplib_calloc_ex(a, b, __FILE__, __LINE__)
|
#define httplib_calloc(a, b) XX_httplib_calloc_ex(a, b, __FILE__, __LINE__)
|
||||||
@@ -987,7 +1007,7 @@ LIBHTTP_API int httplib_pthread_mutex_lock( pthread_mutex_t *mutex );
|
|||||||
LIBHTTP_API int httplib_pthread_mutex_trylock( pthread_mutex_t *mutex );
|
LIBHTTP_API int httplib_pthread_mutex_trylock( pthread_mutex_t *mutex );
|
||||||
LIBHTTP_API int httplib_pthread_mutex_unlock( pthread_mutex_t *mutex );
|
LIBHTTP_API int httplib_pthread_mutex_unlock( pthread_mutex_t *mutex );
|
||||||
LIBHTTP_API pthread_t httplib_pthread_self( void );
|
LIBHTTP_API pthread_t httplib_pthread_self( void );
|
||||||
LIBHTTP_API int httplib_pthread_setspecific( pthread_key_t key, const void *value );
|
LIBHTTP_API int httplib_pthread_setspecific( pthread_key_t key, void *value );
|
||||||
LIBHTTP_API struct dirent * httplib_readdir( DIR *dir );
|
LIBHTTP_API struct dirent * httplib_readdir( DIR *dir );
|
||||||
LIBHTTP_API int httplib_remove( const char *path );
|
LIBHTTP_API int httplib_remove( const char *path );
|
||||||
LIBHTTP_API void httplib_send_file( struct httplib_connection *conn, const char *path, const char *mime_type, const char *additional_headers );
|
LIBHTTP_API void httplib_send_file( struct httplib_connection *conn, const char *path, const char *mime_type, const char *additional_headers );
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
* Release: 2.0
|
* Release: 2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "libhttp.h"
|
||||||
#include "httplib_main.h"
|
#include "httplib_main.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -47,7 +47,7 @@ LIBHTTP_API int httplib_closedir( DIR *dir ) {
|
|||||||
if ( dir != NULL ) {
|
if ( dir != NULL ) {
|
||||||
|
|
||||||
if ( dir->handle != INVALID_HANDLE_VALUE ) result = ( FindClose( dir->handle ) ) ? 0 : -1;
|
if ( dir->handle != INVALID_HANDLE_VALUE ) result = ( FindClose( dir->handle ) ) ? 0 : -1;
|
||||||
XX_httplib_free( dir );
|
httplib_free( dir );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
@@ -121,7 +121,7 @@ static struct httplib_connection *httplib_connect_client_impl( const struct http
|
|||||||
if ( getsockname( sock, psa, &len ) != 0 ) httplib_cry(conn, "%s: getsockname() failed: %s", __func__, strerror(ERRNO) );
|
if ( getsockname( sock, psa, &len ) != 0 ) httplib_cry(conn, "%s: getsockname() failed: %s", __func__, strerror(ERRNO) );
|
||||||
|
|
||||||
conn->client.is_ssl = (use_ssl) ? 1 : 0;
|
conn->client.is_ssl = (use_ssl) ? 1 : 0;
|
||||||
pthread_mutex_init( &conn->mutex, &XX_httplib_pthread_mutex_attr );
|
httplib_pthread_mutex_init( &conn->mutex, &XX_httplib_pthread_mutex_attr );
|
||||||
|
|
||||||
#ifndef NO_SSL
|
#ifndef NO_SSL
|
||||||
if ( use_ssl ) {
|
if ( use_ssl ) {
|
||||||
|
@@ -83,7 +83,7 @@ int XX_httplib_initialize_ssl( struct httplib_context *ctx ) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<CRYPTO_num_locks(); i++) pthread_mutex_init( & XX_httplib_ssl_mutexes[i], &XX_httplib_pthread_mutex_attr);
|
for (i=0; i<CRYPTO_num_locks(); i++) httplib_pthread_mutex_init( & XX_httplib_ssl_mutexes[i], &XX_httplib_pthread_mutex_attr);
|
||||||
|
|
||||||
CRYPTO_set_locking_callback( & XX_httplib_ssl_locking_callback );
|
CRYPTO_set_locking_callback( & XX_httplib_ssl_locking_callback );
|
||||||
CRYPTO_set_id_callback( & XX_httplib_ssl_id_callback );
|
CRYPTO_set_id_callback( & XX_httplib_ssl_id_callback );
|
||||||
|
@@ -43,7 +43,7 @@ static HANDLE dlopen( const char *dll_name, int flags ) {
|
|||||||
|
|
||||||
UNUSED_PARAMETER(flags);
|
UNUSED_PARAMETER(flags);
|
||||||
|
|
||||||
XX_httplib_path_to_unicode( NULL, dll_name, wbuf, ARRAY_SIZE(wbuf) );
|
XX_httplib_path_to_unicode( dll_name, wbuf, ARRAY_SIZE(wbuf) );
|
||||||
return LoadLibraryW( wbuf );
|
return LoadLibraryW( wbuf );
|
||||||
|
|
||||||
} /* dlopen */
|
} /* dlopen */
|
||||||
|
@@ -270,11 +270,6 @@ typedef long off_t;
|
|||||||
#define fileno(x) (_fileno(x))
|
#define fileno(x) (_fileno(x))
|
||||||
#endif /* !fileno MINGW #defines fileno */
|
#endif /* !fileno MINGW #defines fileno */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
CRITICAL_SECTION threadIdSec;
|
|
||||||
struct httplib_workerTLS * waiting_thread; /* The chain of threads */
|
|
||||||
} pthread_cond_t;
|
|
||||||
|
|
||||||
#ifndef __clockid_t_defined
|
#ifndef __clockid_t_defined
|
||||||
typedef DWORD clockid_t;
|
typedef DWORD clockid_t;
|
||||||
#endif /* __clockid_t_defined */
|
#endif /* __clockid_t_defined */
|
||||||
@@ -291,14 +286,6 @@ typedef DWORD clockid_t;
|
|||||||
#define _TIMESPEC_DEFINED
|
#define _TIMESPEC_DEFINED
|
||||||
#endif /* _MSC_VER && _MSC_VER >= 1900 */
|
#endif /* _MSC_VER && _MSC_VER >= 1900 */
|
||||||
|
|
||||||
#ifndef _TIMESPEC_DEFINED
|
|
||||||
struct timespec {
|
|
||||||
time_t tv_sec; /* seconds */
|
|
||||||
long tv_nsec; /* nanoseconds */
|
|
||||||
};
|
|
||||||
#endif /* _TIMESPEC_DEFINED */
|
|
||||||
|
|
||||||
#define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */
|
|
||||||
|
|
||||||
/* Mark required libraries */
|
/* Mark required libraries */
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
@@ -491,10 +478,11 @@ typedef struct ssl_st SSL;
|
|||||||
typedef struct ssl_method_st SSL_METHOD;
|
typedef struct ssl_method_st SSL_METHOD;
|
||||||
typedef struct ssl_ctx_st SSL_CTX;
|
typedef struct ssl_ctx_st SSL_CTX;
|
||||||
typedef struct x509_store_ctx_st X509_STORE_CTX;
|
typedef struct x509_store_ctx_st X509_STORE_CTX;
|
||||||
typedef struct x509_name X509_NAME;
|
// typedef struct x509_name X509_NAME;
|
||||||
typedef struct asn1_integer ASN1_INTEGER;
|
typedef struct asn1_integer ASN1_INTEGER;
|
||||||
typedef struct evp_md EVP_MD;
|
typedef struct evp_md EVP_MD;
|
||||||
typedef struct x509 X509;
|
typedef struct x509 X509;
|
||||||
|
typedef struct x509_name X509_NAMEX;
|
||||||
|
|
||||||
#endif /* NO_SSL_DL */
|
#endif /* NO_SSL_DL */
|
||||||
#endif /* NO_SSL */
|
#endif /* NO_SSL */
|
||||||
@@ -845,6 +833,7 @@ int XX_httplib_is_valid_port( unsigned long port );
|
|||||||
bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn );
|
bool XX_httplib_is_websocket_protocol( const struct httplib_connection *conn );
|
||||||
void * XX_httplib_load_dll( struct httplib_context *ctx, const char *dll_name, struct ssl_func *sw );
|
void * XX_httplib_load_dll( struct httplib_context *ctx, const char *dll_name, struct ssl_func *sw );
|
||||||
void XX_httplib_log_access( const struct httplib_connection *conn );
|
void XX_httplib_log_access( const struct httplib_connection *conn );
|
||||||
|
LIBHTTP_THREAD XX_httplib_master_thread( void *thread_func_param );
|
||||||
int XX_httplib_match_prefix(const char *pattern, size_t pattern_len, const char *str);
|
int XX_httplib_match_prefix(const char *pattern, size_t pattern_len, const char *str);
|
||||||
void XX_httplib_mkcol( struct httplib_connection *conn, const char *path );
|
void XX_httplib_mkcol( struct httplib_connection *conn, const char *path );
|
||||||
int XX_httplib_must_hide_file( struct httplib_connection *conn, const char *path );
|
int XX_httplib_must_hide_file( struct httplib_connection *conn, const char *path );
|
||||||
@@ -900,11 +889,13 @@ char * XX_httplib_skip( char **buf, const char *delimiters );
|
|||||||
char * XX_httplib_skip_quoted( char **buf, const char *delimiters, const char *whitespace, char quotechar );
|
char * XX_httplib_skip_quoted( char **buf, const char *delimiters, const char *whitespace, char quotechar );
|
||||||
void XX_httplib_sockaddr_to_string(char *buf, size_t len, const union usa *usa );
|
void XX_httplib_sockaddr_to_string(char *buf, size_t len, const union usa *usa );
|
||||||
pid_t XX_httplib_spawn_process( struct httplib_connection *conn, const char *prog, char *envblk, char *envp[], int fdin[2], int fdout[2], int fderr[2], const char *dir );
|
pid_t XX_httplib_spawn_process( struct httplib_connection *conn, const char *prog, char *envblk, char *envp[], int fdin[2], int fdout[2], int fderr[2], const char *dir );
|
||||||
|
int XX_httplib_start_thread_with_id( httplib_thread_func_t func, void *param, pthread_t *threadidptr );
|
||||||
int XX_httplib_stat( struct httplib_connection *conn, const char *path, struct file *filep );
|
int XX_httplib_stat( struct httplib_connection *conn, const char *path, struct file *filep );
|
||||||
int XX_httplib_substitute_index_file( struct httplib_connection *conn, char *path, size_t path_len, struct file *filep );
|
int XX_httplib_substitute_index_file( struct httplib_connection *conn, char *path, size_t path_len, struct file *filep );
|
||||||
const char * XX_httplib_suggest_connection_header( const struct httplib_connection *conn );
|
const char * XX_httplib_suggest_connection_header( const struct httplib_connection *conn );
|
||||||
LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data );
|
LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data );
|
||||||
int XX_httplib_websocket_write_exec( struct httplib_connection *conn, int opcode, const char *data, size_t dataLen, uint32_t masking_key );
|
int XX_httplib_websocket_write_exec( struct httplib_connection *conn, int opcode, const char *data, size_t dataLen, uint32_t masking_key );
|
||||||
|
LIBHTTP_THREAD XX_httplib_worker_thread( void *thread_func_param );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -924,16 +915,8 @@ void md5_finish( md5_state_t *pms, md5_byte_t digest[16] );
|
|||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
unsigned __stdcall XX_httplib_master_thread( void *thread_func_param );
|
|
||||||
int XX_httplib_start_thread_with_id( unsigned(__stdcall *f)(void *), void *p, pthread_t *threadidptr );
|
|
||||||
unsigned __stdcall XX_httplib_worker_thread( void *thread_func_param );
|
|
||||||
|
|
||||||
extern struct pthread_mutex_undefined_struct * XX_httplib_pthread_mutex_attr;
|
extern struct pthread_mutex_undefined_struct * XX_httplib_pthread_mutex_attr;
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
void * XX_httplib_master_thread( void *thread_func_param );
|
|
||||||
int XX_httplib_start_thread_with_id( httplib_thread_func_t func, void *param, pthread_t *threadidptr );
|
|
||||||
void * XX_httplib_worker_thread( void *thread_func_param );
|
|
||||||
|
|
||||||
extern pthread_mutexattr_t XX_httplib_pthread_mutex_attr;
|
extern pthread_mutexattr_t XX_httplib_pthread_mutex_attr;
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
@@ -127,7 +127,7 @@ static void master_thread_run(void *thread_func_param) {
|
|||||||
pfd[i].events = POLLIN;
|
pfd[i].events = POLLIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( poll( pfd, ctx->num_listening_sockets, 200 ) > 0 ) {
|
if ( httplib_poll( pfd, ctx->num_listening_sockets, 200 ) > 0 ) {
|
||||||
|
|
||||||
for (i=0; i<ctx->num_listening_sockets; i++) {
|
for (i=0; i<ctx->num_listening_sockets; i++) {
|
||||||
|
|
||||||
|
@@ -46,6 +46,8 @@ LIBHTTP_API int httplib_mkdir( const char *path, int mode ) {
|
|||||||
|
|
||||||
wchar_t wbuf[PATH_MAX];
|
wchar_t wbuf[PATH_MAX];
|
||||||
|
|
||||||
|
UNUSED_PARAMETER(mode);
|
||||||
|
|
||||||
XX_httplib_path_to_unicode( path, wbuf, ARRAY_SIZE(wbuf) );
|
XX_httplib_path_to_unicode( path, wbuf, ARRAY_SIZE(wbuf) );
|
||||||
return ( CreateDirectoryW( wbuf, NULL ) ) ? 0 : -1;
|
return ( CreateDirectoryW( wbuf, NULL ) ) ? 0 : -1;
|
||||||
|
|
||||||
|
@@ -50,9 +50,9 @@ LIBHTTP_API DIR *httplib_opendir( const char *name ) {
|
|||||||
dir = NULL;
|
dir = NULL;
|
||||||
|
|
||||||
if ( name == NULL ) SetLastError( ERROR_BAD_ARGUMENTS );
|
if ( name == NULL ) SetLastError( ERROR_BAD_ARGUMENTS );
|
||||||
else if ( (dir = XX_httplib_malloc( sizeof(*dir) )) == NULL ) SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
else if ( (dir = httplib_malloc( sizeof(*dir) )) == NULL ) SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
||||||
else {
|
else {
|
||||||
XX_httplib_path_to_unicode( conn, name, wpath, ARRAY_SIZE(wpath) );
|
XX_httplib_path_to_unicode( name, wpath, ARRAY_SIZE(wpath) );
|
||||||
attrs = GetFileAttributesW( wpath );
|
attrs = GetFileAttributesW( wpath );
|
||||||
|
|
||||||
if (attrs != 0xFFFFFFFF && ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) ) {
|
if (attrs != 0xFFFFFFFF && ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) ) {
|
||||||
@@ -62,7 +62,7 @@ LIBHTTP_API DIR *httplib_opendir( const char *name ) {
|
|||||||
dir->result.d_name[0] = '\0';
|
dir->result.d_name[0] = '\0';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
XX_httplib_free( dir );
|
httplib_free( dir );
|
||||||
dir = NULL;
|
dir = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -84,7 +84,7 @@ void XX_httplib_path_to_unicode( const char *path, wchar_t *wbuf, size_t wbuf_le
|
|||||||
DWORD err;
|
DWORD err;
|
||||||
int (*fcompare)(const wchar_t *, const wchar_t *) = httplib_wcscasecmp;
|
int (*fcompare)(const wchar_t *, const wchar_t *) = httplib_wcscasecmp;
|
||||||
|
|
||||||
XX_httplib_strlcpy(buf, path, sizeof(buf));
|
httplib_strlcpy( buf, path, sizeof(buf) );
|
||||||
change_slashes_to_backslashes( buf );
|
change_slashes_to_backslashes( buf );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "httplib_main.h"
|
#include "httplib_main.h"
|
||||||
|
#include "httplib_pthread.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int httplib_pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex *mutex, const struct timespec *abstime );
|
* int httplib_pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex *mutex, const struct timespec *abstime );
|
||||||
@@ -53,7 +54,7 @@ int httplib_pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex_t *mutex,
|
|||||||
int64_t nswaitrel;
|
int64_t nswaitrel;
|
||||||
DWORD mswaitrel;
|
DWORD mswaitrel;
|
||||||
|
|
||||||
tls = pthread_getspecific( XX_httplib_sTlsKey );
|
tls = httplib_pthread_getspecific( XX_httplib_sTlsKey );
|
||||||
|
|
||||||
/* Add this thread to cv's waiting list */
|
/* Add this thread to cv's waiting list */
|
||||||
EnterCriticalSection( & cv->threadIdSec );
|
EnterCriticalSection( & cv->threadIdSec );
|
||||||
@@ -81,7 +82,7 @@ int httplib_pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex_t *mutex,
|
|||||||
|
|
||||||
else mswaitrel = INFINITE;
|
else mswaitrel = INFINITE;
|
||||||
|
|
||||||
pthread_mutex_unlock( mutex );
|
httplib_pthread_mutex_unlock( mutex );
|
||||||
ok = ( WaitForSingleObject( tls->pthread_cond_helper_mutex, mswaitrel ) == WAIT_OBJECT_0 );
|
ok = ( WaitForSingleObject( tls->pthread_cond_helper_mutex, mswaitrel ) == WAIT_OBJECT_0 );
|
||||||
|
|
||||||
if ( ! ok ) {
|
if ( ! ok ) {
|
||||||
@@ -110,7 +111,7 @@ int httplib_pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex_t *mutex,
|
|||||||
if ( ok ) WaitForSingleObject( tls->pthread_cond_helper_mutex, INFINITE );
|
if ( ok ) WaitForSingleObject( tls->pthread_cond_helper_mutex, INFINITE );
|
||||||
}
|
}
|
||||||
/* This thread has been removed from cv's waiting list */
|
/* This thread has been removed from cv's waiting list */
|
||||||
pthread_mutex_lock( mutex );
|
httplib_pthread_mutex_lock( mutex );
|
||||||
|
|
||||||
return ok ? 0 : -1;
|
return ok ? 0 : -1;
|
||||||
|
|
||||||
|
@@ -50,14 +50,14 @@ int httplib_pthread_join( pthread_t thread, void **value_ptr ) {
|
|||||||
UNUSED_PARAMETER(value_ptr);
|
UNUSED_PARAMETER(value_ptr);
|
||||||
|
|
||||||
result = -1;
|
result = -1;
|
||||||
dwevent = WaitForSingleObject( threadid, INFINITE );
|
dwevent = WaitForSingleObject( thread, INFINITE );
|
||||||
|
|
||||||
if ( dwevent == WAIT_FAILED ) {
|
if ( dwevent == WAIT_FAILED ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( dwevent == WAIT_OBJECT_0 ) {
|
else if ( dwevent == WAIT_OBJECT_0 ) {
|
||||||
|
|
||||||
CloseHandle( threadid );
|
CloseHandle( thread );
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ pthread_t httplib_pthread_self( void ) {
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
return GetCurrentThreadId();
|
return (pthread_t)GetCurrentThreadId();
|
||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "httplib_main.h"
|
#include "httplib_main.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* int httplib_pthread_setspecific( pthread_key_t key, const void *value );
|
* int httplib_pthread_setspecific( pthread_key_t key, void *value );
|
||||||
*
|
*
|
||||||
* The platform independent function httplib_pthread_setspecific() is used to
|
* The platform independent function httplib_pthread_setspecific() is used to
|
||||||
* set a key value for a previously obtained thread specific key. The function
|
* set a key value for a previously obtained thread specific key. The function
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
* function call is used.
|
* function call is used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int httplib_pthread_setspecific( pthread_key_t key, const void *value ) {
|
int httplib_pthread_setspecific( pthread_key_t key, void *value ) {
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
@@ -54,6 +54,7 @@ int XX_httplib_set_sock_timeout( SOCKET sock, int milliseconds ) {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
DWORD tv = (DWORD)milliseconds;
|
DWORD tv = (DWORD)milliseconds;
|
||||||
|
r0 = 0;
|
||||||
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
|
||||||
|
@@ -119,9 +119,9 @@ struct ssl_func {
|
|||||||
#define CRYPTO_cleanup_all_ex_data (*(void (*)(void))XX_httplib_crypto_sw[9].ptr)
|
#define CRYPTO_cleanup_all_ex_data (*(void (*)(void))XX_httplib_crypto_sw[9].ptr)
|
||||||
#define EVP_cleanup (*(void (*)(void))XX_httplib_crypto_sw[10].ptr)
|
#define EVP_cleanup (*(void (*)(void))XX_httplib_crypto_sw[10].ptr)
|
||||||
#define X509_free (*(void (*)(X509 *))XX_httplib_crypto_sw[11].ptr)
|
#define X509_free (*(void (*)(X509 *))XX_httplib_crypto_sw[11].ptr)
|
||||||
#define X509_get_subject_name (*(X509_NAME * (*)(X509 *))XX_httplib_crypto_sw[12].ptr)
|
#define X509_get_subject_name (*(X509_NAMEX * (*)(X509 *))XX_httplib_crypto_sw[12].ptr)
|
||||||
#define X509_get_issuer_name (*(X509_NAME * (*)(X509 *))XX_httplib_crypto_sw[13].ptr)
|
#define X509_get_issuer_name (*(X509_NAMEX * (*)(X509 *))XX_httplib_crypto_sw[13].ptr)
|
||||||
#define X509_NAME_oneline (*(char *(*)(X509_NAME *, char *, int))XX_httplib_crypto_sw[14].ptr)
|
#define X509_NAME_oneline (*(char *(*)(X509_NAMEX *, char *, int))XX_httplib_crypto_sw[14].ptr)
|
||||||
#define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *))XX_httplib_crypto_sw[15].ptr)
|
#define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *))XX_httplib_crypto_sw[15].ptr)
|
||||||
#define i2c_ASN1_INTEGER (*(int (*)(ASN1_INTEGER *, unsigned char **))XX_httplib_crypto_sw[16].ptr)
|
#define i2c_ASN1_INTEGER (*(int (*)(ASN1_INTEGER *, unsigned char **))XX_httplib_crypto_sw[16].ptr)
|
||||||
#define EVP_get_digestbyname (*(const EVP_MD *(*)(const char *))XX_httplib_crypto_sw[17].ptr)
|
#define EVP_get_digestbyname (*(const EVP_MD *(*)(const char *))XX_httplib_crypto_sw[17].ptr)
|
||||||
|
@@ -53,8 +53,8 @@ void XX_httplib_ssl_get_client_cert_info( struct httplib_connection *conn ) {
|
|||||||
int len2;
|
int len2;
|
||||||
unsigned int ulen;
|
unsigned int ulen;
|
||||||
X509 *cert;
|
X509 *cert;
|
||||||
X509_NAME *subj;
|
X509_NAMEX *subj;
|
||||||
X509_NAME *iss;
|
X509_NAMEX *iss;
|
||||||
ASN1_INTEGER *serial;
|
ASN1_INTEGER *serial;
|
||||||
const EVP_MD *digest;
|
const EVP_MD *digest;
|
||||||
|
|
||||||
|
@@ -105,12 +105,12 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks
|
|||||||
#endif
|
#endif
|
||||||
httplib_pthread_setspecific( XX_httplib_sTlsKey, & tls );
|
httplib_pthread_setspecific( XX_httplib_sTlsKey, & tls );
|
||||||
|
|
||||||
ok = 0 == pthread_mutex_init( & ctx->thread_mutex, &XX_httplib_pthread_mutex_attr );
|
ok = 0 == httplib_pthread_mutex_init( & ctx->thread_mutex, &XX_httplib_pthread_mutex_attr );
|
||||||
#if !defined(ALTERNATIVE_QUEUE)
|
#if !defined(ALTERNATIVE_QUEUE)
|
||||||
ok &= 0 == httplib_pthread_cond_init( & ctx->sq_empty, NULL );
|
ok &= 0 == httplib_pthread_cond_init( & ctx->sq_empty, NULL );
|
||||||
ok &= 0 == httplib_pthread_cond_init( & ctx->sq_full, NULL );
|
ok &= 0 == httplib_pthread_cond_init( & ctx->sq_full, NULL );
|
||||||
#endif
|
#endif
|
||||||
ok &= 0 == pthread_mutex_init( & ctx->nonce_mutex, & XX_httplib_pthread_mutex_attr );
|
ok &= 0 == httplib_pthread_mutex_init( & ctx->nonce_mutex, & XX_httplib_pthread_mutex_attr );
|
||||||
|
|
||||||
if ( ! ok ) {
|
if ( ! ok ) {
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ int XX_httplib_stat( struct httplib_connection *conn, const char *path, struct f
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
XX_httplib_path_to_unicode( conn, path, wbuf, ARRAY_SIZE(wbuf) );
|
XX_httplib_path_to_unicode( path, wbuf, ARRAY_SIZE(wbuf) );
|
||||||
|
|
||||||
if ( GetFileAttributesExW( wbuf, GetFileExInfoStandard, &info ) != 0 ) {
|
if ( GetFileAttributesExW( wbuf, GetFileExInfoStandard, &info ) != 0 ) {
|
||||||
|
|
||||||
|
@@ -103,7 +103,7 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) {
|
|||||||
* within the request handler and from elsewhere in the application
|
* within the request handler and from elsewhere in the application
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pthread_mutex_init( & conn->mutex, &XX_httplib_pthread_mutex_attr );
|
httplib_pthread_mutex_init( & conn->mutex, &XX_httplib_pthread_mutex_attr );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call XX_httplib_consume_socket() even when ctx->stop_flag > 0, to let it
|
* Call XX_httplib_consume_socket() even when ctx->stop_flag > 0, to let it
|
||||||
|
Reference in New Issue
Block a user