CivetWeb是一款简单易用且强大的开源 C/C++ 嵌入式 web 服务器,支持 CGI、SSL、Lua脚本、HTTP、Websocket、WebDAV,可作为库引入已有项目,使其转变成 web 服务器,也可做为独立的 web 服务器使用。CivetWeb 是从 Mongoose 发展而来,使用 MIT 开源协议。
另外也支持HTTPS协议,可选OpenSSL或者mbedTLS。
本文主要目的是使用gcc编译项目,然后翻译Freebasic的文件头,最终实现在VisualFreeBasic上调用,实现多线程、不阻塞、基于事件驱动的Web服务器。
项目地址下载在
Release v1.16 · civetweb/civetweb · GitHub
下载之后,因为我的编译环境是MSSY2,在win上模拟的linux指令,所以要把Makefile下面这一段删除
ifeq ($(TARGET_OS),WIN32)
MKDIR = mkdir
RMF = del /q
RMRF = rmdir /s /q
endif
执行
make lib
然后在项目根目录得到libcivetweb.a,拷贝到Compile\expand\lib\win32文件夹
拷贝fbfrog下面的default.h到include目录,执行
fbfrog.exe *.h -o civetweb.bi -inclib civetweb -inclib ws2_32 -inclib winpthread
需要把civetweb.bi修改以下地方
批量替换mg_connection ptr为mg_connection
批量替换mg_context ptr为mg_context
并增加
type mg_connection as any ptr
type mg_context as any ptr
最终头文件为
#pragma once
#inclib "winpthread"
#inclib "ws2_32"
#inclib "civetweb"
#include once "crt/stddef.bi"
#include once "crt/stdio.bi"
extern "C"
#define CIVETSERVER_HEADER_INCLUDED
#define CIVETWEB_HEADER_INCLUDED
#define CIVETWEB_VERSION "1.16"
const CIVETWEB_VERSION_MAJOR = 1
const CIVETWEB_VERSION_MINOR = 16
const CIVETWEB_VERSION_PATCH = 0
#ifdef __FB_WIN32__
#define CIVETWEB_API
#endif
enum
MG_FEATURES_DEFAULT = &h0u
MG_FEATURES_FILES = &h1u
MG_FEATURES_TLS = &h2u
MG_FEATURES_SSL = &h2u
MG_FEATURES_CGI = &h4u
MG_FEATURES_IPV6 = &h8u
MG_FEATURES_WEBSOCKET = &h10u
MG_FEATURES_LUA = &h20u
MG_FEATURES_SSJS = &h40u
MG_FEATURES_CACHE = &h80u
MG_FEATURES_STATS = &h100u
MG_FEATURES_COMPRESSION = &h200u
MG_FEATURES_HTTP2 = &h400u
MG_FEATURES_X_DOMAIN_SOCKET = &h800u
MG_FEATURES_ALL = &hFFFFu
end enum
declare function mg_init_library(byval features as ulong) as ulong
declare function mg_exit_library() as ulong
const MG_MAX_HEADERS = 64
type mg_header
name as const zstring ptr
value as const zstring ptr
end type
type mg_client_cert as mg_client_cert_
type mg_request_info
request_method as const zstring ptr
request_uri as const zstring ptr
local_uri_raw as const zstring ptr
local_uri as const zstring ptr
http_version as const zstring ptr
query_string as const zstring ptr
remote_user as const zstring ptr
remote_addr as zstring * 48
content_length as longint
remote_port as long
server_port as long
is_ssl as long
user_data as any ptr
conn_data as any ptr
num_headers as long
http_headers(0 to 63) as mg_header
client_cert as mg_client_cert ptr
acceptedWebSocketSubprotocol as const zstring ptr
end type
type mg_response_info
status_code as long
status_text as const zstring ptr
http_version as const zstring ptr
content_length as longint
num_headers as long
http_headers(0 to 63) as mg_header
end type
type mg_client_cert_
peer_cert as any ptr
subject as const zstring ptr
issuer as const zstring ptr
serial as const zstring ptr
finger as const zstring ptr
end type
type mg_connection as any ptr
type mg_context as any ptr
type mg_callbacks
begin_request as function(byval as mg_connection) as long
end_request as sub(byval as const mg_connection, byval reply_status_code as long)
log_message as function(byval as const mg_connection, byval message as const zstring ptr) as long
log_access as function(byval as const mg_connection, byval message as const zstring ptr) as long
init_ssl as function(byval ssl_ctx as any ptr, byval user_data as any ptr) as long
init_ssl_domain as function(byval server_domain as const zstring ptr, byval ssl_ctx as any ptr, byval user_data as any ptr) as long
external_ssl_ctx as function(byval ssl_ctx as any ptr ptr, byval user_data as any ptr) as long
external_ssl_ctx_domain as function(byval server_domain as const zstring ptr, byval ssl_ctx as any ptr ptr, byval user_data as any ptr) as long
connection_close as sub(byval as const mg_connection)
connection_closed as sub(byval as const mg_connection)
init_lua as sub(byval conn as const mg_connection, byval lua_context as any ptr, byval context_flags as ulong)
exit_lua as sub(byval conn as const mg_connection, byval lua_context as any ptr, byval context_flags as ulong)
http_error as function(byval conn as mg_connection, byval status as long, byval errmsg as const zstring ptr) as long
init_context as sub(byval ctx as const mg_context)
exit_context as sub(byval ctx as const mg_context)
init_thread as function(byval ctx as const mg_context, byval thread_type as long) as any ptr
exit_thread as sub(byval ctx as const mg_context, byval thread_type as long, byval thread_pointer as any ptr)
init_connection as function(byval conn as const mg_connection, byval conn_data as any ptr ptr) as long
end type
declare function mg_start(byval callbacks as const mg_callbacks ptr, byval user_data as any ptr, byval configuration_options as const zstring ptr ptr) as mg_context
declare sub mg_stop(byval as mg_context)
declare function mg_start_domain(byval ctx as mg_context, byval configuration_options as const zstring ptr ptr) as long
type mg_request_handler as function(byval conn as mg_connection, byval cbdata as any ptr) as long
declare sub mg_set_request_handler(byval ctx as mg_context, byval uri as const zstring ptr, byval handler as mg_request_handler, byval cbdata as any ptr)
type mg_websocket_connect_handler as function(byval as const mg_connection, byval as any ptr) as long
type mg_websocket_ready_handler as sub(byval as mg_connection, byval as any ptr)
type mg_websocket_data_handler as function(byval as mg_connection, byval as long, byval as zstring ptr, byval as uinteger, byval as any ptr) as long
type mg_websocket_close_handler as sub(byval as const mg_connection, byval as any ptr)
type mg_websocket_subprotocols
nb_subprotocols as long
subprotocols as const zstring ptr ptr
end type
declare sub mg_set_websocket_handler(byval ctx as mg_context, byval uri as const zstring ptr, byval connect_handler as mg_websocket_connect_handler, byval ready_handler as mg_websocket_ready_handler, byval data_handler as mg_websocket_data_handler, byval close_handler as mg_websocket_close_handler, byval cbdata as any ptr)
declare sub mg_set_websocket_handler_with_subprotocols(byval ctx as mg_context, byval uri as const zstring ptr, byval subprotocols as mg_websocket_subprotocols ptr, byval connect_handler as mg_websocket_connect_handler, byval ready_handler as mg_websocket_ready_handler, byval data_handler as mg_websocket_data_handler, byval close_handler as mg_websocket_close_handler, byval cbdata as any ptr)
type mg_authorization_handler as function(byval conn as mg_connection, byval cbdata as any ptr) as long
declare sub mg_set_auth_handler(byval ctx as mg_context, byval uri as const zstring ptr, byval handler as mg_authorization_handler, byval cbdata as any ptr)
declare function mg_get_option(byval ctx as const mg_context, byval name as const zstring ptr) as const zstring ptr
declare function mg_get_context(byval conn as const mg_connection) as mg_context
declare function mg_get_user_data(byval ctx as const mg_context) as any ptr
declare function mg_get_user_context_data(byval conn as const mg_connection) as any ptr
declare function mg_get_thread_pointer(byval conn as const mg_connection) as any ptr
declare sub mg_set_user_connection_data(byval conn as const mg_connection, byval data as any ptr)
declare function mg_get_user_connection_data(byval conn as const mg_connection) as any ptr
declare function mg_get_request_link(byval conn as const mg_connection, byval buf as zstring ptr, byval buflen as uinteger) as long
type mg_option
name as const zstring ptr
as long type
default_value as const zstring ptr
end type
enum
MG_CONFIG_TYPE_UNKNOWN = &h0
MG_CONFIG_TYPE_NUMBER = &h1
MG_CONFIG_TYPE_STRING = &h2
MG_CONFIG_TYPE_FILE = &h3
MG_CONFIG_TYPE_DIRECTORY = &h4
MG_CONFIG_TYPE_BOOLEAN = &h5
MG_CONFIG_TYPE_EXT_PATTERN = &h6
MG_CONFIG_TYPE_STRING_LIST = &h7
MG_CONFIG_TYPE_STRING_MULTILINE = &h8
MG_CONFIG_TYPE_YES_NO_OPTIONAL = &h9
end enum
declare function mg_get_valid_options() as const mg_option ptr
type mg_server_port
protocol as long
port as long
is_ssl as long
is_redirect as long
_reserved1 as long
_reserved2 as long
_reserved3 as long
_reserved4 as long
end type
type mg_server_ports as mg_server_port
declare function mg_get_server_ports(byval ctx as const mg_context, byval size as long, byval ports as mg_server_port ptr) as long
declare function mg_modify_passwords_file(byval passwords_file_name as const zstring ptr, byval realm as const zstring ptr, byval user as const zstring ptr, byval password as const zstring ptr) as long
declare function mg_modify_passwords_file_ha1(byval passwords_file_name as const zstring ptr, byval realm as const zstring ptr, byval user as const zstring ptr, byval ha1 as const zstring ptr) as long
declare function mg_get_request_info(byval as const mg_connection) as const mg_request_info ptr
declare function mg_get_response_info(byval as const mg_connection) as const mg_response_info ptr
declare function mg_write(byval as mg_connection, byval buf as const any ptr, byval len as uinteger) as long
declare function mg_websocket_write(byval conn as mg_connection, byval opcode as long, byval data as const zstring ptr, byval data_len as uinteger) as long
declare function mg_websocket_client_write(byval conn as mg_connection, byval opcode as long, byval data as const zstring ptr, byval data_len as uinteger) as long
declare sub mg_lock_connection(byval conn as mg_connection)
declare sub mg_unlock_connection(byval conn as mg_connection)
declare sub mg_lock_context(byval ctx as mg_context)
declare sub mg_unlock_context(byval ctx as mg_context)
enum
MG_WEBSOCKET_OPCODE_CONTINUATION = &h0
MG_WEBSOCKET_OPCODE_TEXT = &h1
MG_WEBSOCKET_OPCODE_BINARY = &h2
MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE = &h8
MG_WEBSOCKET_OPCODE_PING = &h9
MG_WEBSOCKET_OPCODE_PONG = &ha
end enum
#undef PRINTF_FORMAT_STRING
#define PRINTF_FORMAT_STRING(s) s
declare function mg_printf(byval as mg_connection, byval fmt as const zstring ptr, ...) as long
declare function mg_send_chunk(byval conn as mg_connection, byval chunk as const zstring ptr, byval chunk_len as ulong) as long
declare sub mg_send_file(byval conn as mg_connection, byval path as const zstring ptr)
declare function mg_send_file_body(byval conn as mg_connection, byval path as const zstring ptr) as long
declare function mg_send_http_error(byval conn as mg_connection, byval status_code as long, byval fmt as const zstring ptr, ...) as long
declare function mg_send_http_ok(byval conn as mg_connection, byval mime_type as const zstring ptr, byval content_length as longint) as long
declare function mg_send_http_redirect(byval conn as mg_connection, byval target_url as const zstring ptr, byval redirect_code as long) as long
declare function mg_send_digest_access_authentication_request(byval conn as mg_connection, byval realm as const zstring ptr) as long
declare function mg_check_digest_access_authentication(byval conn as mg_connection, byval realm as const zstring ptr, byval filename as const zstring ptr) as long
declare sub mg_send_mime_file(byval conn as mg_connection, byval path as const zstring ptr, byval mime_type as const zstring ptr)
declare sub mg_send_mime_file2(byval conn as mg_connection, byval path as const zstring ptr, byval mime_type as const zstring ptr, byval additional_headers as const zstring ptr)
declare function mg_store_body(byval conn as mg_connection, byval path as const zstring ptr) as longint
declare function mg_read(byval as mg_connection, byval buf as any ptr, byval len as uinteger) as long
declare function mg_get_header(byval as const mg_connection, byval name as const zstring ptr) as const zstring ptr
declare function mg_get_var(byval data as const zstring ptr, byval data_len as uinteger, byval var_name as const zstring ptr, byval dst as zstring ptr, byval dst_len as uinteger) as long
declare function mg_get_var2(byval data as const zstring ptr, byval data_len as uinteger, byval var_name as const zstring ptr, byval dst as zstring ptr, byval dst_len as uinteger, byval occurrence as uinteger) as long
declare function mg_split_form_urlencoded(byval data as zstring ptr, byval form_fields as mg_header ptr, byval num_form_fields as ulong) as long
declare function mg_get_cookie(byval cookie as const zstring ptr, byval var_name as const zstring ptr, byval buf as zstring ptr, byval buf_len as uinteger) as long
declare function mg_download(byval host as const zstring ptr, byval port as long, byval use_ssl as long, byval error_buffer as zstring ptr, byval error_buffer_size as uinteger, byval request_fmt as const zstring ptr, ...) as mg_connection
declare sub mg_close_connection(byval conn as mg_connection)
type mg_form_data_handler
field_found as function(byval key as const zstring ptr, byval filename as const zstring ptr, byval path as zstring ptr, byval pathlen as uinteger, byval user_data as any ptr) as long
field_get as function(byval key as const zstring ptr, byval value as const zstring ptr, byval valuelen as uinteger, byval user_data as any ptr) as long
field_store as function(byval path as const zstring ptr, byval file_size as longint, byval user_data as any ptr) as long
user_data as any ptr
end type
enum
MG_FORM_FIELD_STORAGE_SKIP = &h0
MG_FORM_FIELD_STORAGE_GET = &h1
MG_FORM_FIELD_STORAGE_STORE = &h2
MG_FORM_FIELD_STORAGE_ABORT = &h10
end enum
enum
MG_FORM_FIELD_HANDLE_GET = &h1
MG_FORM_FIELD_HANDLE_NEXT = &h8
MG_FORM_FIELD_HANDLE_ABORT = &h10
end enum
declare function mg_handle_form_request(byval conn as mg_connection, byval fdh as mg_form_data_handler ptr) as long
type mg_thread_func_t as function(byval as any ptr) as any ptr
declare function mg_start_thread(byval f as mg_thread_func_t, byval p as any ptr) as long
declare function mg_get_builtin_mime_type(byval file_name as const zstring ptr) as const zstring ptr
declare function mg_get_response_code_text(byval conn as const mg_connection, byval response_code as long) as const zstring ptr
declare function mg_version() as const zstring ptr
declare function mg_url_decode(byval src as const zstring ptr, byval src_len as long, byval dst as zstring ptr, byval dst_len as long, byval is_form_url_encoded as long) as long
declare function mg_url_encode(byval src as const zstring ptr, byval dst as zstring ptr, byval dst_len as uinteger) as long
declare function mg_base64_encode(byval src as const ubyte ptr, byval src_len as uinteger, byval dst as zstring ptr, byval dst_len as uinteger ptr) as long
declare function mg_base64_decode(byval src as const zstring ptr, byval src_len as uinteger, byval dst as ubyte ptr, byval dst_len as uinteger ptr) as long
declare function mg_md5(byval buf as zstring ptr, ...) as zstring ptr
const MG_MATCH_CONTEXT_MAX_MATCHES = 32
type mg_match_element
str as const zstring ptr
len as uinteger
end type
type mg_match_context
case_sensitive as long
num_matches as uinteger
match(0 to 31) as mg_match_element
end type
declare sub mg_cry(byval conn as const mg_connection, byval fmt as const zstring ptr, ...)
declare function mg_strcasecmp(byval s1 as const zstring ptr, byval s2 as const zstring ptr) as long
declare function mg_strncasecmp(byval s1 as const zstring ptr, byval s2 as const zstring ptr, byval len as uinteger) as long
declare function mg_connect_websocket_client(byval host as const zstring ptr, byval port as long, byval use_ssl as long, byval error_buffer as zstring ptr, byval error_buffer_size as uinteger, byval path as const zstring ptr, byval origin as const zstring ptr, byval data_func as mg_websocket_data_handler, byval close_func as mg_websocket_close_handler, byval user_data as any ptr) as mg_connection
declare function mg_connect_websocket_client_extensions(byval host as const zstring ptr, byval port as long, byval use_ssl as long, byval error_buffer as zstring ptr, byval error_buffer_size as uinteger, byval path as const zstring ptr, byval origin as const zstring ptr, byval extensions as const zstring ptr, byval data_func as mg_websocket_data_handler, byval close_func as mg_websocket_close_handler, byval user_data as any ptr) as mg_connection
declare function mg_connect_client(byval host as const zstring ptr, byval port as long, byval use_ssl as long, byval error_buffer as zstring ptr, byval error_buffer_size as uinteger) as mg_connection
type mg_client_options
host as const zstring ptr
port as long
client_cert as const zstring ptr
server_cert as const zstring ptr
host_name as const zstring ptr
end type
declare function mg_connect_client_secure(byval client_options as const mg_client_options ptr, byval error_buffer as zstring ptr, byval error_buffer_size as uinteger) as mg_connection
declare function mg_connect_websocket_client_secure(byval client_options as const mg_client_options ptr, byval error_buffer as zstring ptr, byval error_buffer_size as uinteger, byval path as const zstring ptr, byval origin as const zstring ptr, byval data_func as mg_websocket_data_handler, byval close_func as mg_websocket_close_handler, byval user_data as any ptr) as mg_connection
declare function mg_connect_websocket_client_secure_extensions(byval client_options as const mg_client_options ptr, byval error_buffer as zstring ptr, byval error_buffer_size as uinteger, byval path as const zstring ptr, byval origin as const zstring ptr, byval extensions as const zstring ptr, byval data_func as mg_websocket_data_handler, byval close_func as mg_websocket_close_handler, byval user_data as any ptr) as mg_connection
enum
MG_TIMEOUT_INFINITE = -1
end enum
declare function mg_get_response(byval conn as mg_connection, byval ebuf as zstring ptr, byval ebuf_len as uinteger, byval timeout as long) as long
declare function mg_response_header_start(byval conn as mg_connection, byval status as long) as long
declare function mg_response_header_add(byval conn as mg_connection, byval header as const zstring ptr, byval value as const zstring ptr, byval value_len as long) as long
declare function mg_response_header_add_lines(byval conn as mg_connection, byval http1_headers as const zstring ptr) as long
declare function mg_response_header_send(byval conn as mg_connection) as long
declare function mg_check_feature(byval feature as ulong) as ulong
declare function mg_get_system_info(byval buffer as zstring ptr, byval buflen as long) as long
declare function mg_get_context_info(byval ctx as const mg_context, byval buffer as zstring ptr, byval buflen as long) as long
declare sub mg_disable_connection_keep_alive(byval conn as mg_connection)
type mg_error_data
code as ulong
code_sub as ulong
text as zstring ptr
text_buffer_size as uinteger
end type
enum
MG_ERROR_DATA_CODE_OK = 0u
MG_ERROR_DATA_CODE_INVALID_PARAM = 1u
MG_ERROR_DATA_CODE_INVALID_OPTION = 2u
MG_ERROR_DATA_CODE_INIT_TLS_FAILED = 3u
MG_ERROR_DATA_CODE_MISSING_OPTION = 4u
MG_ERROR_DATA_CODE_DUPLICATE_DOMAIN = 5u
MG_ERROR_DATA_CODE_OUT_OF_MEMORY = 6u
MG_ERROR_DATA_CODE_SERVER_STOPPED = 7u
MG_ERROR_DATA_CODE_INIT_LIBRARY_FAILED = 8u
MG_ERROR_DATA_CODE_OS_ERROR = 9u
MG_ERROR_DATA_CODE_INIT_PORTS_FAILED = 10u
MG_ERROR_DATA_CODE_INIT_USER_FAILED = 11u
MG_ERROR_DATA_CODE_INIT_ACL_FAILED = 12u
MG_ERROR_DATA_CODE_INVALID_PASS_FILE = 13u
MG_ERROR_DATA_CODE_SCRIPT_ERROR = 14u
MG_ERROR_DATA_CODE_HOST_NOT_FOUND = 15u
MG_ERROR_DATA_CODE_CONNECT_TIMEOUT = 16u
MG_ERROR_DATA_CODE_CONNECT_FAILED = 17u
MG_ERROR_DATA_CODE_TLS_CLIENT_CERT_ERROR = 18u
MG_ERROR_DATA_CODE_TLS_SERVER_CERT_ERROR = 19u
MG_ERROR_DATA_CODE_TLS_CONNECT_ERROR = 20u
end enum
type mg_init_data
callbacks as const mg_callbacks ptr
user_data as any ptr
configuration_options as const zstring ptr ptr
end type
declare function mg_start2(byval init as mg_init_data ptr, byval error as mg_error_data ptr) as mg_context
declare function mg_start_domain2(byval ctx as mg_context, byval configuration_options as const zstring ptr ptr, byval error as mg_error_data ptr) as long
const __STDC__ = 1
const __STDC_VERSION__ = 199901
const __STDC_HOSTED__ = 1
const __STDC_IEC_559__ = 1
const __GNUC__ = 4
const __GNUC_MINOR__ = 1111111
const __GNUC_PATCHLEVEL__ = 1111111
#define __GNUC_PREREQ(maj, min) (((__GNUC__ shl 16) + __GNUC_MINOR__) >= (((maj) shl 16) + (min)))
const __clang__ = 1
const __clang_major__ = 3
const __clang_minor__ = 1111111
const __clang_patchlevel__ = 1111111
#define __clang_version__ "fbfrog"
const __llvm__ = 1
#ifdef __FB_UNIX__
const unix = 1
const __unix = 1
const __unix__ = 1
#endif
#if defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__)
const __ELF__ = 1
#endif
#ifdef __FB_LINUX__
const linux = 1
const __linux = 1
const __linux__ = 1
const __gnu_linux__ = 1
#elseif defined(__FB_FREEBSD__)
const __FreeBSD__ = 10
const __FreeBSD_cc_version = 1000001
#elseif defined(__FB_OPENBSD__)
const __OpenBSD__ = 1
#elseif defined(__FB_NETBSD__)
const __NetBSD__ = 1
#elseif defined(__FB_DARWIN__)
const __APPLE__ = 1
const __MACH__ = 1
#elseif defined(__FB_WIN32__)
const __MINGW32__ = 1
const __MSVCRT__ = 1
const WIN32 = 1
const _WIN32 = 1
const __WIN32 = 1
const __WIN32__ = 1
const WINNT = 1
const __WINNT = 1
const __WINNT__ = 1
#elseif defined(__FB_CYGWIN__)
const __CYGWIN__ = 1
#endif
#if defined(__FB_CYGWIN__) and (not defined(__FB_64BIT__))
const __CYGWIN32__ = 1
#elseif defined(__FB_DOS__)
const DJGPP = 2
const __DJGPP = 2
const __DJGPP__ = 2
const GO32 = 1
const __GO32 = 1
const __GO32__ = 1
const MSDOS = 1
const __MSDOS = 1
const __MSDOS__ = 1
#endif
#if defined(__FB_DOS__) or ((not defined(__FB_64BIT__)) and (defined(__FB_DARWIN__) or defined(__FB_WIN32__) or defined(__FB_CYGWIN__) or ((not defined(__FB_ARM__)) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__)))))
const i386 = 1
const __i386 = 1
const __i386__ = 1
const __i486__ = 1
const __i586 = 1
const __i586__ = 1
const __pentium = 1
const __pentium__ = 1
const __i686 = 1
const __i686__ = 1
const __pentiumpro = 1
const __pentiumpro__ = 1
#define _M_IX86
#define _X86_
#define __X86__
const __code_model_32__ = 1
#elseif defined(__FB_64BIT__) and defined(__FB_UNIX__)
const __LP64__ = 1
const _LP64 = 1
#elseif defined(__FB_WIN32__) and defined(__FB_64BIT__)
const __MINGW64__ = 1
const WIN64 = 1
const _WIN64 = 1
const __WIN64 = 1
const __WIN64__ = 1
#endif
#if defined(__FB_64BIT__) and (defined(__FB_DARWIN__) or defined(__FB_WIN32__) or defined(__FB_CYGWIN__) or ((not defined(__FB_ARM__)) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))))
const __x86_64 = 1
const __x86_64__ = 1
const __amd64 = 1
const __amd64__ = 1
const __k8 = 1
const __k8__ = 1
#define _M_X64
#define _M_AMD64
const __code_model_small__ = 1
const __MMX__ = 1
const __SSE__ = 1
const __SSE2__ = 1
const __SSE2_MATH__ = 1
const __SSE_MATH__ = 1
#elseif (not defined(__FB_64BIT__)) and defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
const __APCS_32__ = 1
const __arm__ = 1
const __ARM_32BIT_STATE = 1
const __ARM_ARCH = 7
const __ARM_ARCH_7A__ = 1
const __ARM_ARCH_ISA_ARM = 1
const __ARM_ARCH_ISA_THUMB = 2
#elseif defined(__FB_64BIT__) and defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
const __aarch64__ = 1
const __AARCH64_CMODEL_SMALL__ = 1
const __AARCH64EL__ = 1
const __ARM_64BIT_STATE = 1
const __ARM_ARCH = 8
const __ARM_ARCH_8A = 1
const __ARM_ARCH_ISA_A64 = 1
#endif
#if defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
const __ARM_ARCH_PROFILE = 65
#endif
#if (not defined(__FB_64BIT__)) and defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
const __ARM_EABI__ = 1
const __ARMEL__ = 1
const __ARM_FEATURE_CLZ = 1
const __ARM_FEATURE_DSP = 1
const __ARM_FEATURE_LDREX = 15
const __ARM_FEATURE_QBIT = 1
const __ARM_FEATURE_SAT = 1
const __ARM_FEATURE_SIMD32 = 1
const __ARM_FEATURE_UNALIGNED = 1
const __ARM_FP = 12
const __ARM_NEON_FP = 4
const __ARM_PCS_VFP = 1
const __ARM_SIZEOF_MINIMAL_ENUM = 4
const __ARM_SIZEOF_WCHAR_T = 4
#endif
const __ORDER_BIG_ENDIAN__ = 4321
const __ORDER_LITTLE_ENDIAN__ = 1234
const __ORDER_PDP_ENDIAN__ = 3412
const __BYTE_ORDER__ = __ORDER_LITTLE_ENDIAN__
const __FLOAT_WORD_ORDER__ = __ORDER_LITTLE_ENDIAN__
const __LITTLE_ENDIAN__ = 1
const __CHAR_BIT__ = 8
const __SIZEOF_SHORT__ = 2
const __SIZEOF_INT__ = 4
#if (defined(__FB_WIN32__) and defined(__FB_64BIT__)) or defined(__FB_DOS__) or ((not defined(__FB_64BIT__)) and (defined(__FB_WIN32__) or defined(__FB_UNIX__)))
const __SIZEOF_LONG__ = 4
#endif
#if defined(__FB_DOS__) or ((not defined(__FB_64BIT__)) and (defined(__FB_DARWIN__) or defined(__FB_WIN32__) or defined(__FB_CYGWIN__) or ((not defined(__FB_ARM__)) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__)))))
const __SIZEOF_LONG_DOUBLE__ = 12
#elseif (not defined(__FB_64BIT__)) and defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
const __SIZEOF_LONG_DOUBLE__ = 8
#endif
#if defined(__FB_DOS__) or ((not defined(__FB_64BIT__)) and (defined(__FB_WIN32__) or defined(__FB_UNIX__)))
const __SIZEOF_POINTER__ = 4
const __SIZEOF_PTRDIFF_T__ = 4
const __SIZEOF_SIZE_T__ = 4
#elseif defined(__FB_64BIT__) and defined(__FB_UNIX__)
const __SIZEOF_LONG__ = 8
#endif
#if defined(__FB_64BIT__) and (defined(__FB_WIN32__) or defined(__FB_UNIX__))
const __SIZEOF_LONG_DOUBLE__ = 16
const __SIZEOF_POINTER__ = 8
const __SIZEOF_PTRDIFF_T__ = 8
const __SIZEOF_SIZE_T__ = 8
#endif
const __SIZEOF_LONG_LONG__ = 8
const __SIZEOF_INT128__ = 16
const __SIZEOF_FLOAT__ = 4
const __SIZEOF_DOUBLE__ = 8
#if (not defined(__FB_64BIT__)) and defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
const __BIGGEST_ALIGNMENT__ = 8
#else
const __BIGGEST_ALIGNMENT__ = 16
#endif
type __INT8_TYPE__ as byte
const __INT8_MAX__ = 127
type __UINT8_TYPE__ as ubyte
const __UINT8_MAX__ = 255
type __INT16_TYPE__ as short
const __INT16_MAX__ = 32767
type __UINT16_TYPE__ as ushort
const __UINT16_MAX__ = 65535
type __INT32_TYPE__ as long
const __INT32_MAX__ = 2147483647
type __UINT32_TYPE__ as ulong
const __UINT32_MAX__ = 4294967295u
type __INT64_TYPE__ as longint
const __INT64_MAX__ = 9223372036854775807ll
type __UINT64_TYPE__ as ulongint
const __UINT64_MAX__ = 18446744073709551615ull
const __SCHAR_MAX__ = __INT8_MAX__
const __SHRT_MAX__ = __INT16_MAX__
const __INT_MAX__ = __INT32_MAX__
const __LONG_LONG_MAX__ = __INT64_MAX__
type __INTMAX_TYPE__ as __INT64_TYPE__
const __INTMAX_MAX__ = __INT64_MAX__
type __UINTMAX_TYPE__ as __UINT64_TYPE__
const __UINTMAX_MAX__ = __UINT64_MAX__
#if (defined(__FB_WIN32__) and defined(__FB_64BIT__)) or defined(__FB_DOS__) or ((not defined(__FB_64BIT__)) and (defined(__FB_WIN32__) or defined(__FB_UNIX__)))
const __LONG_MAX__ = __INT32_MAX__
#endif
#if defined(__FB_DOS__) or ((not defined(__FB_64BIT__)) and (defined(__FB_WIN32__) or defined(__FB_UNIX__)))
type __SIZE_TYPE__ as __UINT32_TYPE__
const __SIZE_MAX__ = __UINT32_MAX__
type __PTRDIFF_TYPE__ as __INT32_TYPE__
const __PTRDIFF_MAX__ = __INT32_MAX__
type __INTPTR_TYPE__ as __INT32_TYPE__
const __INTPTR_MAX__ = __INT32_MAX__
type __UINTPTR_TYPE__ as __UINT32_TYPE__
const __UINTPTR_MAX__ = __UINT32_MAX__
#elseif defined(__FB_64BIT__) and defined(__FB_UNIX__)
const __LONG_MAX__ = __INT64_MAX__
#endif
#if defined(__FB_64BIT__) and (defined(__FB_WIN32__) or defined(__FB_UNIX__))
type __SIZE_TYPE__ as __UINT64_TYPE__
const __SIZE_MAX__ = __UINT64_MAX__
type __PTRDIFF_TYPE__ as __INT64_TYPE__
const __PTRDIFF_MAX__ = __INT64_MAX__
type __INTPTR_TYPE__ as __INT64_TYPE__
const __INTPTR_MAX__ = __INT64_MAX__
type __UINTPTR_TYPE__ as __UINT64_TYPE__
const __UINTPTR_MAX__ = __UINT64_MAX__
#endif
#if defined(__FB_DARWIN__) or defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__)
const __SIZEOF_WCHAR_T__ = 4
#endif
#if ((not defined(__FB_ARM__)) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))) or defined(__FB_DARWIN__)
type __WCHAR_TYPE__ as __INT32_TYPE__
#define __WCHAR_MIN__ ((-__WCHAR_MAX__) - 1)
const __WCHAR_MAX__ = __INT32_MAX__
#elseif defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
type __WCHAR_TYPE__ as __UINT32_TYPE__
#elseif defined(__FB_CYGWIN__)
const __SIZEOF_WCHAR_T__ = 2
type __WCHAR_TYPE__ as __UINT16_TYPE__
#endif
#if (defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))) or defined(__FB_CYGWIN__)
const __WCHAR_MIN__ = 0u
#endif
#if defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))
const __WCHAR_MAX__ = __UINT32_MAX__
#elseif defined(__FB_CYGWIN__)
const __WCHAR_MAX__ = __UINT16_MAX__
#endif
#ifdef __FB_UNIX__
const __SIZEOF_WINT_T__ = 4
#endif
#if (defined(__FB_ARM__) and (defined(__FB_LINUX__) or defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))) or (defined(__FB_LINUX__) and (not defined(__FB_ARM__))) or defined(__FB_CYGWIN__)
type __WINT_TYPE__ as __UINT32_TYPE__
const __WINT_MIN__ = 0u
const __WINT_MAX__ = __UINT32_MAX__
#elseif ((not defined(__FB_ARM__)) and (defined(__FB_FREEBSD__) or defined(__FB_OPENBSD__) or defined(__FB_NETBSD__))) or defined(__FB_DARWIN__)
type __WINT_TYPE__ as __INT32_TYPE__
#define __WINT_MIN__ ((-__WINT_MAX__) - 1)
const __WINT_MAX__ = __INT32_MAX__
#else
const __SIZEOF_WCHAR_T__ = 2
type __WCHAR_TYPE__ as __UINT16_TYPE__
const __WCHAR_MIN__ = 0
const __WCHAR_MAX__ = __UINT16_MAX__
#endif
#ifdef __FB_WIN32__
const __SIZEOF_WINT_T__ = 2
type __WINT_TYPE__ as __UINT16_TYPE__
const __WINT_MIN__ = 0
const __WINT_MAX__ = __UINT16_MAX__
#elseif defined(__FB_DOS__)
const __SIZEOF_WINT_T__ = 4
type __WINT_TYPE__ as __INT32_TYPE__
#define __WINT_MIN__ ((-__WINT_MAX__) - 1)
const __WINT_MAX__ = __INT32_MAX__
#endif
type __SIG_ATOMIC_TYPE__ as __INT32_TYPE__
#define __SIG_ATOMIC_MIN__ ((-__SIG_ATOMIC_MAX__) - 1)
const __SIG_ATOMIC_MAX__ = __INT32_MAX__
const __FLT_MIN__ = 1.17549435082228750797e-38f
const __FLT_MAX__ = 3.40282346638528859812e+38f
'' TODO: #define __DBL_MIN__ ((double)2.22507385850720138309e-308L)
'' TODO: #define __DBL_MAX__ ((double)1.79769313486231570815e+308L)
'' TODO: #define __LDBL_MIN__ 3.36210314311209350626e-4932L
'' TODO: #define __LDBL_MAX__ 1.18973149535723176502e+4932L
type __CHAR16_TYPE__ as __UINT16_TYPE__
type __CHAR32_TYPE__ as __UINT32_TYPE__
#if defined(__FB_DOS__) or defined(__FB_LINUX__) or defined(__FB_WIN32__) or defined(__FB_CYGWIN__)
type __INT_FAST8_TYPE__ as __INT8_TYPE__
const __INT_FAST8_MAX__ = __INT8_MAX__
type __UINT_FAST8_TYPE__ as __UINT8_TYPE__
const __UINT_FAST8_MAX__ = __UINT8_MAX__
#endif
#if (not defined(__FB_64BIT__)) and (defined(__FB_CYGWIN__) or defined(__FB_LINUX__))
type __INT_FAST16_TYPE__ as long
const __INT_FAST16_MAX__ = __INT32_MAX__
type __UINT_FAST16_TYPE__ as __UINT32_TYPE__
const __UINT_FAST16_MAX__ = __UINT32_MAX__
#elseif defined(__FB_DOS__) or defined(__FB_WIN32__)
type __INT_FAST16_TYPE__ as __INT16_TYPE__
const __INT_FAST16_MAX__ = __INT16_MAX__
type __UINT_FAST16_TYPE__ as __UINT16_TYPE__
const __UINT_FAST16_MAX__ = __UINT16_MAX__
#endif
#if (defined(__FB_WIN32__) and defined(__FB_64BIT__)) or defined(__FB_DOS__) or ((not defined(__FB_64BIT__)) and (defined(__FB_WIN32__) or defined(__FB_CYGWIN__) or defined(__FB_LINUX__)))
type __INT_FAST32_TYPE__ as long
const __INT_FAST32_MAX__ = __INT32_MAX__
type __UINT_FAST32_TYPE__ as __UINT32_TYPE__
const __UINT_FAST32_MAX__ = __UINT32_MAX__
#elseif defined(__FB_64BIT__) and (defined(__FB_CYGWIN__) or defined(__FB_LINUX__))
type __INT_FAST16_TYPE__ as __INT64_TYPE__
const __INT_FAST16_MAX__ = __INT64_MAX__
type __UINT_FAST16_TYPE__ as __UINT64_TYPE__
const __UINT_FAST16_MAX__ = __UINT64_MAX__
type __INT_FAST32_TYPE__ as __INT64_TYPE__
const __INT_FAST32_MAX__ = __INT64_MAX__
type __UINT_FAST32_TYPE__ as __UINT64_TYPE__
const __UINT_FAST32_MAX__ = __UINT64_MAX__
#endif
#if defined(__FB_DOS__) or defined(__FB_LINUX__) or defined(__FB_WIN32__) or defined(__FB_CYGWIN__)
type __INT_FAST64_TYPE__ as __INT64_TYPE__
const __INT_FAST64_MAX__ = __INT64_MAX__
type __UINT_FAST64_TYPE__ as __UINT64_TYPE__
const __UINT_FAST64_MAX__ = __UINT64_MAX__
type __INT_LEAST8_TYPE__ as __INT8_TYPE__
const __INT_LEAST8_MAX__ = __INT8_MAX__
type __UINT_LEAST8_TYPE__ as __UINT8_TYPE__
const __UINT_LEAST8_MAX__ = __UINT8_MAX__
type __INT_LEAST16_TYPE__ as __INT16_TYPE__
const __INT_LEAST16_MAX__ = __INT16_MAX__
type __UINT_LEAST16_TYPE__ as __UINT16_TYPE__
const __UINT_LEAST16_MAX__ = __UINT16_MAX__
type __INT_LEAST32_TYPE__ as long
const __INT_LEAST32_MAX__ = __INT32_MAX__
type __UINT_LEAST32_TYPE__ as __UINT32_TYPE__
const __UINT_LEAST32_MAX__ = __UINT32_MAX__
type __INT_LEAST64_TYPE__ as __INT64_TYPE__
const __INT_LEAST64_MAX__ = __INT64_MAX__
type __UINT_LEAST64_TYPE__ as __UINT64_TYPE__
const __UINT_LEAST64_MAX__ = __UINT64_MAX__
#endif
#define __INT8_C(c) c
#define __INT16_C(c) c
#define __INT32_C(c) c
#define __INT64_C(c) c##LL
#define __INTMAX_C(c) c##LL
#define __UINT8_C(c) c
#define __UINT16_C(c) c
#define __UINT32_C(c) c##U
#define __UINT64_C(c) c##ULL
#define __UINTMAX_C(c) c##ULL
#ifdef __FB_WIN32__
const _INTEGRAL_MAX_BITS = 64
const _REENTRANT = 1
#endif
#define __extension__
#define register
#define __has_feature(x) 0
end extern
把civetweb.bi拷贝到Compile\expand\inc文件夹
创建一个标准exe项目,并在起始模块加入
#include onece "civetweb.bi"
在窗体里面加入
Sub Form1_Shown(hWndForm As hWnd,UserData As Integer)
Dim ctx As mg_context
mg_init_library(0)
ctx = mg_start(NULL, 0, NULL)
mg_set_request_handler(ctx, "/hello", @helloHandler, 0)
End Sub
Function helloHandler cdecl(conn As mg_connection, ignored As Any Ptr) As Integer
Debug.Print "来访" & Timer()
Dim strMsg As String = "Hello world"
Dim nLen As Long = Len(strMsg)
Sleep(2000)
mg_send_http_ok(conn, "text/plain", nLen)
mg_write(conn, StrPtr(strMsg), nLen)
Return 200
End Function
在演示代码里面,我人为的让程序停止执行2秒钟,然后在客户端不停的刷新页面,最终结果如下
说明默认是多线程的,不会对主线程进行堵塞,也同时能支持多个并发