cjson
fuzzing
inputs
test1 test10 test11 test2 test3 test3.bu test3.uf test3.uu test4 test5 test6 test7 test8 test9library_config
cJSONConfig.cmake.in cJSONConfigVersion.cmake.in libcjson.pc.in libcjson_utils.pc.in uninstall.cmaketests
inputs
test1 test1.expected test10 test10.expected test11 test11.expected test2 test2.expected test3 test3.expected test4 test4.expected test5 test5.expected test6 test7 test7.expected test8 test8.expected test9 test9.expectedjson-patch-tests
.editorconfig .gitignore .npmignore README.md cjson-utils-tests.json package.json spec_tests.json tests.jsonunity
auto
colour_prompt.rb colour_reporter.rb generate_config.yml generate_module.rb generate_test_runner.rb parse_output.rb stylize_as_junit.rb test_file_filter.rb type_sanitizer.rb unity_test_summary.py unity_test_summary.rb unity_to_junit.pydocs
ThrowTheSwitchCodingStandard.md UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf UnityAssertionsReference.md UnityConfigurationGuide.md UnityGettingStartedGuide.md UnityHelperScriptsGuide.md license.txtexamples
unity_config.hcurl
.github
scripts
cleancmd.pl cmp-config.pl cmp-pkg-config.sh codespell-ignore.words codespell.sh distfiles.sh pyspelling.words pyspelling.yaml randcurl.pl requirements-docs.txt requirements-proselint.txt requirements.txt shellcheck-ci.sh shellcheck.sh spellcheck.curl trimmarkdownheader.pl typos.sh typos.toml verify-examples.pl verify-synopsis.pl yamlcheck.sh yamlcheck.yamlworkflows
appveyor-status.yml checkdocs.yml checksrc.yml checkurls.yml codeql.yml configure-vs-cmake.yml curl-for-win.yml distcheck.yml fuzz.yml http3-linux.yml label.yml linux-old.yml linux.yml macos.yml non-native.yml windows.ymlCMake
CurlSymbolHiding.cmake CurlTests.c FindBrotli.cmake FindCares.cmake FindGSS.cmake FindGnuTLS.cmake FindLDAP.cmake FindLibbacktrace.cmake FindLibgsasl.cmake FindLibidn2.cmake FindLibpsl.cmake FindLibssh.cmake FindLibssh2.cmake FindLibuv.cmake FindMbedTLS.cmake FindNGHTTP2.cmake FindNGHTTP3.cmake FindNGTCP2.cmake FindNettle.cmake FindQuiche.cmake FindRustls.cmake FindWolfSSL.cmake FindZstd.cmake Macros.cmake OtherTests.cmake PickyWarnings.cmake Utilities.cmake cmake_uninstall.in.cmake curl-config.in.cmake unix-cache.cmake win32-cache.cmakedocs
cmdline-opts
.gitignore CMakeLists.txt MANPAGE.md Makefile.am Makefile.inc _AUTHORS.md _BUGS.md _DESCRIPTION.md _ENVIRONMENT.md _EXITCODES.md _FILES.md _GLOBBING.md _NAME.md _OPTIONS.md _OUTPUT.md _PROGRESS.md _PROTOCOLS.md _PROXYPREFIX.md _SEEALSO.md _SYNOPSIS.md _URL.md _VARIABLES.md _VERSION.md _WWW.md abstract-unix-socket.md alt-svc.md anyauth.md append.md aws-sigv4.md basic.md ca-native.md cacert.md capath.md cert-status.md cert-type.md cert.md ciphers.md compressed-ssh.md compressed.md config.md connect-timeout.md connect-to.md continue-at.md cookie-jar.md cookie.md create-dirs.md create-file-mode.md crlf.md crlfile.md curves.md data-ascii.md data-binary.md data-raw.md data-urlencode.md data.md delegation.md digest.md disable-eprt.md disable-epsv.md disable.md disallow-username-in-url.md dns-interface.md dns-ipv4-addr.md dns-ipv6-addr.md dns-servers.md doh-cert-status.md doh-insecure.md doh-url.md dump-ca-embed.md dump-header.md ech.md egd-file.md engine.md etag-compare.md etag-save.md expect100-timeout.md fail-early.md fail-with-body.md fail.md false-start.md follow.md form-escape.md form-string.md form.md ftp-account.md ftp-alternative-to-user.md ftp-create-dirs.md ftp-method.md ftp-pasv.md ftp-port.md ftp-pret.md ftp-skip-pasv-ip.md ftp-ssl-ccc-mode.md ftp-ssl-ccc.md ftp-ssl-control.md get.md globoff.md happy-eyeballs-timeout-ms.md haproxy-clientip.md haproxy-protocol.md head.md header.md help.md hostpubmd5.md hostpubsha256.md hsts.md http0.9.md http1.0.md http1.1.md http2-prior-knowledge.md http2.md http3-only.md http3.md ignore-content-length.md insecure.md interface.md ip-tos.md ipfs-gateway.md ipv4.md ipv6.md json.md junk-session-cookies.md keepalive-cnt.md keepalive-time.md key-type.md key.md knownhosts.md krb.md libcurl.md limit-rate.md list-only.md local-port.md location-trusted.md location.md login-options.md mail-auth.md mail-from.md mail-rcpt-allowfails.md mail-rcpt.md mainpage.idx manual.md max-filesize.md max-redirs.md max-time.md metalink.md mptcp.md negotiate.md netrc-file.md netrc-optional.md netrc.md next.md no-alpn.md no-buffer.md no-clobber.md no-keepalive.md no-npn.md no-progress-meter.md no-sessionid.md noproxy.md ntlm-wb.md ntlm.md oauth2-bearer.md out-null.md output-dir.md output.md parallel-immediate.md parallel-max-host.md parallel-max.md parallel.md pass.md path-as-is.md pinnedpubkey.md post301.md post302.md post303.md preproxy.md progress-bar.md proto-default.md proto-redir.md proto.md proxy-anyauth.md proxy-basic.md proxy-ca-native.md proxy-cacert.md proxy-capath.md proxy-cert-type.md proxy-cert.md proxy-ciphers.md proxy-crlfile.md proxy-digest.md proxy-header.md proxy-http2.md proxy-insecure.md proxy-key-type.md proxy-key.md proxy-negotiate.md proxy-ntlm.md proxy-pass.md proxy-pinnedpubkey.md proxy-service-name.md proxy-ssl-allow-beast.md proxy-ssl-auto-client-cert.md proxy-tls13-ciphers.md proxy-tlsauthtype.md proxy-tlspassword.md proxy-tlsuser.md proxy-tlsv1.md proxy-user.md proxy.md proxy1.0.md proxytunnel.md pubkey.md quote.md random-file.md range.md rate.md raw.md referer.md remote-header-name.md remote-name-all.md remote-name.md remote-time.md remove-on-error.md request-target.md request.md resolve.md retry-all-errors.md retry-connrefused.md retry-delay.md retry-max-time.md retry.md sasl-authzid.md sasl-ir.md service-name.md show-error.md show-headers.md sigalgs.md silent.md skip-existing.md socks4.md socks4a.md socks5-basic.md socks5-gssapi-nec.md socks5-gssapi-service.md socks5-gssapi.md socks5-hostname.md socks5.md speed-limit.md speed-time.md ssl-allow-beast.md ssl-auto-client-cert.md ssl-no-revoke.md ssl-reqd.md ssl-revoke-best-effort.md ssl-sessions.md ssl.md sslv2.md sslv3.md stderr.md styled-output.md suppress-connect-headers.md tcp-fastopen.md tcp-nodelay.md telnet-option.md tftp-blksize.md tftp-no-options.md time-cond.md tls-earlydata.md tls-max.md tls13-ciphers.md tlsauthtype.md tlspassword.md tlsuser.md tlsv1.0.md tlsv1.1.md tlsv1.2.md tlsv1.3.md tlsv1.md tr-encoding.md trace-ascii.md trace-config.md trace-ids.md trace-time.md trace.md unix-socket.md upload-file.md upload-flags.md url-query.md url.md use-ascii.md user-agent.md user.md variable.md verbose.md version.md vlan-priority.md write-out.md xattr.mdexamples
.checksrc .gitignore 10-at-a-time.c CMakeLists.txt Makefile.am Makefile.example Makefile.inc README.md adddocsref.pl address-scope.c altsvc.c anyauthput.c block_ip.c cacertinmem.c certinfo.c chkspeed.c connect-to.c cookie_interface.c crawler.c debug.c default-scheme.c ephiperfifo.c evhiperfifo.c externalsocket.c fileupload.c ftp-delete.c ftp-wildcard.c ftpget.c ftpgetinfo.c ftpgetresp.c ftpsget.c ftpupload.c ftpuploadfrommem.c ftpuploadresume.c getinfo.c getinmemory.c getredirect.c getreferrer.c ghiper.c headerapi.c hiperfifo.c hsts-preload.c htmltidy.c htmltitle.cpp http-options.c http-post.c http2-download.c http2-pushinmemory.c http2-serverpush.c http2-upload.c http3-present.c http3.c httpcustomheader.c httpput-postfields.c httpput.c https.c imap-append.c imap-authzid.c imap-copy.c imap-create.c imap-delete.c imap-examine.c imap-fetch.c imap-list.c imap-lsub.c imap-multi.c imap-noop.c imap-search.c imap-ssl.c imap-store.c imap-tls.c interface.c ipv6.c keepalive.c localport.c log_failed_transfers.c maxconnects.c multi-app.c multi-debugcallback.c multi-double.c multi-event.c multi-formadd.c multi-legacy.c multi-post.c multi-single.c multi-uv.c netrc.c parseurl.c persistent.c pop3-authzid.c pop3-dele.c pop3-list.c pop3-multi.c pop3-noop.c pop3-retr.c pop3-ssl.c pop3-stat.c pop3-tls.c pop3-top.c pop3-uidl.c post-callback.c postinmemory.c postit2-formadd.c postit2.c progressfunc.c protofeats.c range.c resolve.c rtsp-options.c sendrecv.c sepheaders.c sessioninfo.c sftpget.c sftpuploadresume.c shared-connection-cache.c simple.c simplepost.c simplessl.c smooth-gtk-thread.c smtp-authzid.c smtp-expn.c smtp-mail.c smtp-mime.c smtp-multi.c smtp-ssl.c smtp-tls.c smtp-vrfy.c sslbackend.c synctime.c threaded.c unixsocket.c url2file.c urlapi.c usercertinmem.c version-check.pl websocket-cb.c websocket-updown.c websocket.c xmlstream.cinternals
BUFQ.md BUFREF.md CHECKSRC.md CLIENT-READERS.md CLIENT-WRITERS.md CODE_STYLE.md CONNECTION-FILTERS.md CREDENTIALS.md CURLX.md DYNBUF.md HASH.md LLIST.md MID.md MQTT.md MULTI-EV.md NEW-PROTOCOL.md PEERS.md PORTING.md RATELIMITS.md README.md SCORECARD.md SPLAY.md STRPARSE.md THRDPOOL-AND-QUEUE.md TIME-KEEPING.md TLS-SESSIONS.md UINT_SETS.md WEBSOCKET.mdlibcurl
opts
CMakeLists.txt CURLINFO_ACTIVESOCKET.md CURLINFO_APPCONNECT_TIME.md CURLINFO_APPCONNECT_TIME_T.md CURLINFO_CAINFO.md CURLINFO_CAPATH.md CURLINFO_CERTINFO.md CURLINFO_CONDITION_UNMET.md CURLINFO_CONNECT_TIME.md CURLINFO_CONNECT_TIME_T.md CURLINFO_CONN_ID.md CURLINFO_CONTENT_LENGTH_DOWNLOAD.md CURLINFO_CONTENT_LENGTH_DOWNLOAD_T.md CURLINFO_CONTENT_LENGTH_UPLOAD.md CURLINFO_CONTENT_LENGTH_UPLOAD_T.md CURLINFO_CONTENT_TYPE.md CURLINFO_COOKIELIST.md CURLINFO_EARLYDATA_SENT_T.md CURLINFO_EFFECTIVE_METHOD.md CURLINFO_EFFECTIVE_URL.md CURLINFO_FILETIME.md CURLINFO_FILETIME_T.md CURLINFO_FTP_ENTRY_PATH.md CURLINFO_HEADER_SIZE.md CURLINFO_HTTPAUTH_AVAIL.md CURLINFO_HTTPAUTH_USED.md CURLINFO_HTTP_CONNECTCODE.md CURLINFO_HTTP_VERSION.md CURLINFO_LASTSOCKET.md CURLINFO_LOCAL_IP.md CURLINFO_LOCAL_PORT.md CURLINFO_NAMELOOKUP_TIME.md CURLINFO_NAMELOOKUP_TIME_T.md CURLINFO_NUM_CONNECTS.md CURLINFO_OS_ERRNO.md CURLINFO_POSTTRANSFER_TIME_T.md CURLINFO_PRETRANSFER_TIME.md CURLINFO_PRETRANSFER_TIME_T.md CURLINFO_PRIMARY_IP.md CURLINFO_PRIMARY_PORT.md CURLINFO_PRIVATE.md CURLINFO_PROTOCOL.md CURLINFO_PROXYAUTH_AVAIL.md CURLINFO_PROXYAUTH_USED.md CURLINFO_PROXY_ERROR.md CURLINFO_PROXY_SSL_VERIFYRESULT.md CURLINFO_QUEUE_TIME_T.md CURLINFO_REDIRECT_COUNT.md CURLINFO_REDIRECT_TIME.md CURLINFO_REDIRECT_TIME_T.md CURLINFO_REDIRECT_URL.md CURLINFO_REFERER.md CURLINFO_REQUEST_SIZE.md CURLINFO_RESPONSE_CODE.md CURLINFO_RETRY_AFTER.md CURLINFO_RTSP_CLIENT_CSEQ.md CURLINFO_RTSP_CSEQ_RECV.md CURLINFO_RTSP_SERVER_CSEQ.md CURLINFO_RTSP_SESSION_ID.md CURLINFO_SCHEME.md CURLINFO_SIZE_DELIVERED.md CURLINFO_SIZE_DOWNLOAD.md CURLINFO_SIZE_DOWNLOAD_T.md CURLINFO_SIZE_UPLOAD.md CURLINFO_SIZE_UPLOAD_T.md CURLINFO_SPEED_DOWNLOAD.md CURLINFO_SPEED_DOWNLOAD_T.md CURLINFO_SPEED_UPLOAD.md CURLINFO_SPEED_UPLOAD_T.md CURLINFO_SSL_ENGINES.md CURLINFO_SSL_VERIFYRESULT.md CURLINFO_STARTTRANSFER_TIME.md CURLINFO_STARTTRANSFER_TIME_T.md CURLINFO_TLS_SESSION.md CURLINFO_TLS_SSL_PTR.md CURLINFO_TOTAL_TIME.md CURLINFO_TOTAL_TIME_T.md CURLINFO_USED_PROXY.md CURLINFO_XFER_ID.md CURLMINFO_XFERS_ADDED.md CURLMINFO_XFERS_CURRENT.md CURLMINFO_XFERS_DONE.md CURLMINFO_XFERS_PENDING.md CURLMINFO_XFERS_RUNNING.md CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE.md CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE.md CURLMOPT_MAXCONNECTS.md CURLMOPT_MAX_CONCURRENT_STREAMS.md CURLMOPT_MAX_HOST_CONNECTIONS.md CURLMOPT_MAX_PIPELINE_LENGTH.md CURLMOPT_MAX_TOTAL_CONNECTIONS.md CURLMOPT_NETWORK_CHANGED.md CURLMOPT_NOTIFYDATA.md CURLMOPT_NOTIFYFUNCTION.md CURLMOPT_PIPELINING.md CURLMOPT_PIPELINING_SERVER_BL.md CURLMOPT_PIPELINING_SITE_BL.md CURLMOPT_PUSHDATA.md CURLMOPT_PUSHFUNCTION.md CURLMOPT_QUICK_EXIT.md CURLMOPT_RESOLVE_THREADS_MAX.md CURLMOPT_SOCKETDATA.md CURLMOPT_SOCKETFUNCTION.md CURLMOPT_TIMERDATA.md CURLMOPT_TIMERFUNCTION.md CURLOPT_ABSTRACT_UNIX_SOCKET.md CURLOPT_ACCEPTTIMEOUT_MS.md CURLOPT_ACCEPT_ENCODING.md CURLOPT_ADDRESS_SCOPE.md CURLOPT_ALTSVC.md CURLOPT_ALTSVC_CTRL.md CURLOPT_APPEND.md CURLOPT_AUTOREFERER.md CURLOPT_AWS_SIGV4.md CURLOPT_BUFFERSIZE.md CURLOPT_CAINFO.md CURLOPT_CAINFO_BLOB.md CURLOPT_CAPATH.md CURLOPT_CA_CACHE_TIMEOUT.md CURLOPT_CERTINFO.md CURLOPT_CHUNK_BGN_FUNCTION.md CURLOPT_CHUNK_DATA.md CURLOPT_CHUNK_END_FUNCTION.md CURLOPT_CLOSESOCKETDATA.md CURLOPT_CLOSESOCKETFUNCTION.md CURLOPT_CONNECTTIMEOUT.md CURLOPT_CONNECTTIMEOUT_MS.md CURLOPT_CONNECT_ONLY.md CURLOPT_CONNECT_TO.md CURLOPT_CONV_FROM_NETWORK_FUNCTION.md CURLOPT_CONV_FROM_UTF8_FUNCTION.md CURLOPT_CONV_TO_NETWORK_FUNCTION.md CURLOPT_COOKIE.md CURLOPT_COOKIEFILE.md CURLOPT_COOKIEJAR.md CURLOPT_COOKIELIST.md CURLOPT_COOKIESESSION.md CURLOPT_COPYPOSTFIELDS.md CURLOPT_CRLF.md CURLOPT_CRLFILE.md CURLOPT_CURLU.md CURLOPT_CUSTOMREQUEST.md CURLOPT_DEBUGDATA.md CURLOPT_DEBUGFUNCTION.md CURLOPT_DEFAULT_PROTOCOL.md CURLOPT_DIRLISTONLY.md CURLOPT_DISALLOW_USERNAME_IN_URL.md CURLOPT_DNS_CACHE_TIMEOUT.md CURLOPT_DNS_INTERFACE.md CURLOPT_DNS_LOCAL_IP4.md CURLOPT_DNS_LOCAL_IP6.md CURLOPT_DNS_SERVERS.md CURLOPT_DNS_SHUFFLE_ADDRESSES.md CURLOPT_DNS_USE_GLOBAL_CACHE.md CURLOPT_DOH_SSL_VERIFYHOST.md CURLOPT_DOH_SSL_VERIFYPEER.md CURLOPT_DOH_SSL_VERIFYSTATUS.md CURLOPT_DOH_URL.md CURLOPT_ECH.md CURLOPT_EGDSOCKET.md CURLOPT_ERRORBUFFER.md CURLOPT_EXPECT_100_TIMEOUT_MS.md CURLOPT_FAILONERROR.md CURLOPT_FILETIME.md CURLOPT_FNMATCH_DATA.md CURLOPT_FNMATCH_FUNCTION.md CURLOPT_FOLLOWLOCATION.md CURLOPT_FORBID_REUSE.md CURLOPT_FRESH_CONNECT.md CURLOPT_FTPPORT.md CURLOPT_FTPSSLAUTH.md CURLOPT_FTP_ACCOUNT.md CURLOPT_FTP_ALTERNATIVE_TO_USER.md CURLOPT_FTP_CREATE_MISSING_DIRS.md CURLOPT_FTP_FILEMETHOD.md CURLOPT_FTP_SKIP_PASV_IP.md CURLOPT_FTP_SSL_CCC.md CURLOPT_FTP_USE_EPRT.md CURLOPT_FTP_USE_EPSV.md CURLOPT_FTP_USE_PRET.md CURLOPT_GSSAPI_DELEGATION.md CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.md CURLOPT_HAPROXYPROTOCOL.md CURLOPT_HAPROXY_CLIENT_IP.md CURLOPT_HEADER.md CURLOPT_HEADERDATA.md CURLOPT_HEADERFUNCTION.md CURLOPT_HEADEROPT.md CURLOPT_HSTS.md CURLOPT_HSTSREADDATA.md CURLOPT_HSTSREADFUNCTION.md CURLOPT_HSTSWRITEDATA.md CURLOPT_HSTSWRITEFUNCTION.md CURLOPT_HSTS_CTRL.md CURLOPT_HTTP09_ALLOWED.md CURLOPT_HTTP200ALIASES.md CURLOPT_HTTPAUTH.md CURLOPT_HTTPGET.md CURLOPT_HTTPHEADER.md CURLOPT_HTTPPOST.md CURLOPT_HTTPPROXYTUNNEL.md CURLOPT_HTTP_CONTENT_DECODING.md CURLOPT_HTTP_TRANSFER_DECODING.md CURLOPT_HTTP_VERSION.md CURLOPT_IGNORE_CONTENT_LENGTH.md CURLOPT_INFILESIZE.md CURLOPT_INFILESIZE_LARGE.md CURLOPT_INTERFACE.md CURLOPT_INTERLEAVEDATA.md CURLOPT_INTERLEAVEFUNCTION.md CURLOPT_IOCTLDATA.md CURLOPT_IOCTLFUNCTION.md CURLOPT_IPRESOLVE.md CURLOPT_ISSUERCERT.md CURLOPT_ISSUERCERT_BLOB.md CURLOPT_KEEP_SENDING_ON_ERROR.md CURLOPT_KEYPASSWD.md CURLOPT_KRBLEVEL.md CURLOPT_LOCALPORT.md CURLOPT_LOCALPORTRANGE.md CURLOPT_LOGIN_OPTIONS.md CURLOPT_LOW_SPEED_LIMIT.md CURLOPT_LOW_SPEED_TIME.md CURLOPT_MAIL_AUTH.md CURLOPT_MAIL_FROM.md CURLOPT_MAIL_RCPT.md CURLOPT_MAIL_RCPT_ALLOWFAILS.md CURLOPT_MAXAGE_CONN.md CURLOPT_MAXCONNECTS.md CURLOPT_MAXFILESIZE.md CURLOPT_MAXFILESIZE_LARGE.md CURLOPT_MAXLIFETIME_CONN.md CURLOPT_MAXREDIRS.md CURLOPT_MAX_RECV_SPEED_LARGE.md CURLOPT_MAX_SEND_SPEED_LARGE.md CURLOPT_MIMEPOST.md CURLOPT_MIME_OPTIONS.md CURLOPT_NETRC.md CURLOPT_NETRC_FILE.md CURLOPT_NEW_DIRECTORY_PERMS.md CURLOPT_NEW_FILE_PERMS.md CURLOPT_NOBODY.md CURLOPT_NOPROGRESS.md CURLOPT_NOPROXY.md CURLOPT_NOSIGNAL.md CURLOPT_OPENSOCKETDATA.md CURLOPT_OPENSOCKETFUNCTION.md CURLOPT_PASSWORD.md CURLOPT_PATH_AS_IS.md CURLOPT_PINNEDPUBLICKEY.md CURLOPT_PIPEWAIT.md CURLOPT_PORT.md CURLOPT_POST.md CURLOPT_POSTFIELDS.md CURLOPT_POSTFIELDSIZE.md CURLOPT_POSTFIELDSIZE_LARGE.md CURLOPT_POSTQUOTE.md CURLOPT_POSTREDIR.md CURLOPT_PREQUOTE.md CURLOPT_PREREQDATA.md CURLOPT_PREREQFUNCTION.md CURLOPT_PRE_PROXY.md CURLOPT_PRIVATE.md CURLOPT_PROGRESSDATA.md CURLOPT_PROGRESSFUNCTION.md CURLOPT_PROTOCOLS.md CURLOPT_PROTOCOLS_STR.md CURLOPT_PROXY.md CURLOPT_PROXYAUTH.md CURLOPT_PROXYHEADER.md CURLOPT_PROXYPASSWORD.md CURLOPT_PROXYPORT.md CURLOPT_PROXYTYPE.md CURLOPT_PROXYUSERNAME.md CURLOPT_PROXYUSERPWD.md CURLOPT_PROXY_CAINFO.md CURLOPT_PROXY_CAINFO_BLOB.md CURLOPT_PROXY_CAPATH.md CURLOPT_PROXY_CRLFILE.md CURLOPT_PROXY_ISSUERCERT.md CURLOPT_PROXY_ISSUERCERT_BLOB.md CURLOPT_PROXY_KEYPASSWD.md CURLOPT_PROXY_PINNEDPUBLICKEY.md CURLOPT_PROXY_SERVICE_NAME.md CURLOPT_PROXY_SSLCERT.md CURLOPT_PROXY_SSLCERTTYPE.md CURLOPT_PROXY_SSLCERT_BLOB.md CURLOPT_PROXY_SSLKEY.md CURLOPT_PROXY_SSLKEYTYPE.md CURLOPT_PROXY_SSLKEY_BLOB.md CURLOPT_PROXY_SSLVERSION.md CURLOPT_PROXY_SSL_CIPHER_LIST.md CURLOPT_PROXY_SSL_OPTIONS.md CURLOPT_PROXY_SSL_VERIFYHOST.md CURLOPT_PROXY_SSL_VERIFYPEER.md CURLOPT_PROXY_TLS13_CIPHERS.md CURLOPT_PROXY_TLSAUTH_PASSWORD.md CURLOPT_PROXY_TLSAUTH_TYPE.md CURLOPT_PROXY_TLSAUTH_USERNAME.md CURLOPT_PROXY_TRANSFER_MODE.md CURLOPT_PUT.md CURLOPT_QUICK_EXIT.md CURLOPT_QUOTE.md CURLOPT_RANDOM_FILE.md CURLOPT_RANGE.md CURLOPT_READDATA.md CURLOPT_READFUNCTION.md CURLOPT_REDIR_PROTOCOLS.md CURLOPT_REDIR_PROTOCOLS_STR.md CURLOPT_REFERER.md CURLOPT_REQUEST_TARGET.md CURLOPT_RESOLVE.md CURLOPT_RESOLVER_START_DATA.md CURLOPT_RESOLVER_START_FUNCTION.md CURLOPT_RESUME_FROM.md CURLOPT_RESUME_FROM_LARGE.md CURLOPT_RTSP_CLIENT_CSEQ.md CURLOPT_RTSP_REQUEST.md CURLOPT_RTSP_SERVER_CSEQ.md CURLOPT_RTSP_SESSION_ID.md CURLOPT_RTSP_STREAM_URI.md CURLOPT_RTSP_TRANSPORT.md CURLOPT_SASL_AUTHZID.md CURLOPT_SASL_IR.md CURLOPT_SEEKDATA.md CURLOPT_SEEKFUNCTION.md CURLOPT_SERVER_RESPONSE_TIMEOUT.md CURLOPT_SERVER_RESPONSE_TIMEOUT_MS.md CURLOPT_SERVICE_NAME.md CURLOPT_SHARE.md CURLOPT_SOCKOPTDATA.md CURLOPT_SOCKOPTFUNCTION.md CURLOPT_SOCKS5_AUTH.md CURLOPT_SOCKS5_GSSAPI_NEC.md CURLOPT_SOCKS5_GSSAPI_SERVICE.md CURLOPT_SSH_AUTH_TYPES.md CURLOPT_SSH_COMPRESSION.md CURLOPT_SSH_HOSTKEYDATA.md CURLOPT_SSH_HOSTKEYFUNCTION.md CURLOPT_SSH_HOST_PUBLIC_KEY_MD5.md CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256.md CURLOPT_SSH_KEYDATA.md CURLOPT_SSH_KEYFUNCTION.md CURLOPT_SSH_KNOWNHOSTS.md CURLOPT_SSH_PRIVATE_KEYFILE.md CURLOPT_SSH_PUBLIC_KEYFILE.md CURLOPT_SSLCERT.md CURLOPT_SSLCERTTYPE.md CURLOPT_SSLCERT_BLOB.md CURLOPT_SSLENGINE.md CURLOPT_SSLENGINE_DEFAULT.md CURLOPT_SSLKEY.md CURLOPT_SSLKEYTYPE.md CURLOPT_SSLKEY_BLOB.md CURLOPT_SSLVERSION.md CURLOPT_SSL_CIPHER_LIST.md CURLOPT_SSL_CTX_DATA.md CURLOPT_SSL_CTX_FUNCTION.md CURLOPT_SSL_EC_CURVES.md CURLOPT_SSL_ENABLE_ALPN.md CURLOPT_SSL_ENABLE_NPN.md CURLOPT_SSL_FALSESTART.md CURLOPT_SSL_OPTIONS.md CURLOPT_SSL_SESSIONID_CACHE.md CURLOPT_SSL_SIGNATURE_ALGORITHMS.md CURLOPT_SSL_VERIFYHOST.md CURLOPT_SSL_VERIFYPEER.md CURLOPT_SSL_VERIFYSTATUS.md CURLOPT_STDERR.md CURLOPT_STREAM_DEPENDS.md CURLOPT_STREAM_DEPENDS_E.md CURLOPT_STREAM_WEIGHT.md CURLOPT_SUPPRESS_CONNECT_HEADERS.md CURLOPT_TCP_FASTOPEN.md CURLOPT_TCP_KEEPALIVE.md CURLOPT_TCP_KEEPCNT.md CURLOPT_TCP_KEEPIDLE.md CURLOPT_TCP_KEEPINTVL.md CURLOPT_TCP_NODELAY.md CURLOPT_TELNETOPTIONS.md CURLOPT_TFTP_BLKSIZE.md CURLOPT_TFTP_NO_OPTIONS.md CURLOPT_TIMECONDITION.md CURLOPT_TIMEOUT.md CURLOPT_TIMEOUT_MS.md CURLOPT_TIMEVALUE.md CURLOPT_TIMEVALUE_LARGE.md CURLOPT_TLS13_CIPHERS.md CURLOPT_TLSAUTH_PASSWORD.md CURLOPT_TLSAUTH_TYPE.md CURLOPT_TLSAUTH_USERNAME.md CURLOPT_TRAILERDATA.md CURLOPT_TRAILERFUNCTION.md CURLOPT_TRANSFERTEXT.md CURLOPT_TRANSFER_ENCODING.md CURLOPT_UNIX_SOCKET_PATH.md CURLOPT_UNRESTRICTED_AUTH.md CURLOPT_UPKEEP_INTERVAL_MS.md CURLOPT_UPLOAD.md CURLOPT_UPLOAD_BUFFERSIZE.md CURLOPT_UPLOAD_FLAGS.md CURLOPT_URL.md CURLOPT_USERAGENT.md CURLOPT_USERNAME.md CURLOPT_USERPWD.md CURLOPT_USE_SSL.md CURLOPT_VERBOSE.md CURLOPT_WILDCARDMATCH.md CURLOPT_WRITEDATA.md CURLOPT_WRITEFUNCTION.md CURLOPT_WS_OPTIONS.md CURLOPT_XFERINFODATA.md CURLOPT_XFERINFOFUNCTION.md CURLOPT_XOAUTH2_BEARER.md CURLSHOPT_LOCKFUNC.md CURLSHOPT_SHARE.md CURLSHOPT_UNLOCKFUNC.md CURLSHOPT_UNSHARE.md CURLSHOPT_USERDATA.md Makefile.am Makefile.incinclude
curl
Makefile.am curl.h curlver.h easy.h header.h mprintf.h multi.h options.h stdcheaders.h system.h typecheck-gcc.h urlapi.h websockets.hlib
curlx
base64.c base64.h basename.c basename.h dynbuf.c dynbuf.h fopen.c fopen.h inet_ntop.c inet_ntop.h inet_pton.c inet_pton.h multibyte.c multibyte.h nonblock.c nonblock.h snprintf.c snprintf.h strcopy.c strcopy.h strdup.c strdup.h strerr.c strerr.h strparse.c strparse.h timediff.c timediff.h timeval.c timeval.h version_win32.c version_win32.h wait.c wait.h warnless.c warnless.h winapi.c winapi.hvauth
cleartext.c cram.c digest.c digest.h digest_sspi.c gsasl.c krb5_gssapi.c krb5_sspi.c ntlm.c ntlm_sspi.c oauth2.c spnego_gssapi.c spnego_sspi.c vauth.c vauth.hvquic
curl_ngtcp2.c curl_ngtcp2.h curl_quiche.c curl_quiche.h vquic-tls.c vquic-tls.h vquic.c vquic.h vquic_int.hvtls
apple.c apple.h cipher_suite.c cipher_suite.h gtls.c gtls.h hostcheck.c hostcheck.h keylog.c keylog.h mbedtls.c mbedtls.h openssl.c openssl.h rustls.c rustls.h schannel.c schannel.h schannel_int.h schannel_verify.c vtls.c vtls.h vtls_int.h vtls_scache.c vtls_scache.h vtls_spack.c vtls_spack.h wolfssl.c wolfssl.h x509asn1.c x509asn1.hm4
.gitignore curl-amissl.m4 curl-apple-sectrust.m4 curl-compilers.m4 curl-confopts.m4 curl-functions.m4 curl-gnutls.m4 curl-mbedtls.m4 curl-openssl.m4 curl-override.m4 curl-reentrant.m4 curl-rustls.m4 curl-schannel.m4 curl-sysconfig.m4 curl-wolfssl.m4 xc-am-iface.m4 xc-cc-check.m4 xc-lt-iface.m4 xc-val-flgs.m4 zz40-xc-ovr.m4 zz50-xc-ovr.m4projects
OS400
.checksrc README.OS400 ccsidcurl.c ccsidcurl.h config400.default curl.cmd curl.inc.in curlcl.c curlmain.c initscript.sh make-docs.sh make-include.sh make-lib.sh make-src.sh make-tests.sh makefile.sh os400sys.c os400sys.hWindows
tmpl
.gitattributes README.txt curl-all.sln curl.sln curl.vcxproj curl.vcxproj.filters libcurl.sln libcurl.vcxproj libcurl.vcxproj.filtersvms
Makefile.am backup_gnv_curl_src.com build_curl-config_script.com build_gnv_curl.com build_gnv_curl_pcsi_desc.com build_gnv_curl_pcsi_text.com build_gnv_curl_release_notes.com build_libcurl_pc.com build_vms.com clean_gnv_curl.com compare_curl_source.com config_h.com curl_crtl_init.c curl_gnv_build_steps.txt curl_release_note_start.txt curl_startup.com curlmsg.h curlmsg.msg curlmsg.sdl curlmsg_vms.h generate_config_vms_h_curl.com generate_vax_transfer.com gnv_conftest.c_first gnv_curl_configure.sh gnv_libcurl_symbols.opt gnv_link_curl.com macro32_exactcase.patch make_gnv_curl_install.sh make_pcsi_curl_kit_name.com pcsi_gnv_curl_file_list.txt pcsi_product_gnv_curl.com readme report_openssl_version.c setup_gnv_curl_build.com stage_curl_install.com vms_eco_level.hscripts
.checksrc CMakeLists.txt Makefile.am badwords badwords-all badwords.txt cd2cd cd2nroff cdall checksrc-all.pl checksrc.pl cmakelint.sh completion.pl contributors.sh contrithanks.sh coverage.sh delta dmaketgz extract-unit-protos firefox-db2pem.sh installcheck.sh maketgz managen mdlinkcheck mk-ca-bundle.pl mk-unity.pl nroff2cd perlcheck.sh pythonlint.sh randdisable release-notes.pl release-tools.sh schemetable.c singleuse.pl spacecheck.pl top-complexity top-length verify-release wcurlsrc
.checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc config2setopts.c config2setopts.h curl.rc curlinfo.c mk-file-embed.pl mkhelp.pl slist_wc.c slist_wc.h terminal.c terminal.h tool_cb_dbg.c tool_cb_dbg.h tool_cb_hdr.c tool_cb_hdr.h tool_cb_prg.c tool_cb_prg.h tool_cb_rea.c tool_cb_rea.h tool_cb_see.c tool_cb_see.h tool_cb_soc.c tool_cb_soc.h tool_cb_wrt.c tool_cb_wrt.h tool_cfgable.c tool_cfgable.h tool_dirhie.c tool_dirhie.h tool_doswin.c tool_doswin.h tool_easysrc.c tool_easysrc.h tool_filetime.c tool_filetime.h tool_findfile.c tool_findfile.h tool_formparse.c tool_formparse.h tool_getparam.c tool_getparam.h tool_getpass.c tool_getpass.h tool_help.c tool_help.h tool_helpers.c tool_helpers.h tool_hugehelp.h tool_ipfs.c tool_ipfs.h tool_libinfo.c tool_libinfo.h tool_listhelp.c tool_main.c tool_main.h tool_msgs.c tool_msgs.h tool_operate.c tool_operate.h tool_operhlp.c tool_operhlp.h tool_paramhlp.c tool_paramhlp.h tool_parsecfg.c tool_parsecfg.h tool_progress.c tool_progress.h tool_sdecls.h tool_setopt.c tool_setopt.h tool_setup.h tool_ssls.c tool_ssls.h tool_stderr.c tool_stderr.h tool_urlglob.c tool_urlglob.h tool_util.c tool_util.h tool_version.h tool_vms.c tool_vms.h tool_writeout.c tool_writeout.h tool_writeout_json.c tool_writeout_json.h tool_xattr.c tool_xattr.h var.c var.htests
certs
.gitignore CMakeLists.txt Makefile.am Makefile.inc genserv.pl srp-verifier-conf srp-verifier-db test-ca.cnf test-ca.prm test-client-cert.prm test-client-eku-only.prm test-localhost-san-first.prm test-localhost-san-last.prm test-localhost.nn.prm test-localhost.prm test-localhost0h.prmdata
.gitignore DISABLED Makefile.am data-xml1 data1400.c data1401.c data1402.c data1403.c data1404.c data1405.c data1406.c data1407.c data1420.c data1461.txt data1463.txt data1465.c data1481.c data1705-1.md data1705-2.md data1705-3.md data1705-4.md data1705-stdout.1 data1706-1.md data1706-2.md data1706-3.md data1706-4.md data1706-stdout.txt data320.html test1 test10 test100 test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 test1008 test1009 test101 test1010 test1011 test1012 test1013 test1014 test1015 test1016 test1017 test1018 test1019 test102 test1020 test1021 test1022 test1023 test1024 test1025 test1026 test1027 test1028 test1029 test103 test1030 test1031 test1032 test1033 test1034 test1035 test1036 test1037 test1038 test1039 test104 test1040 test1041 test1042 test1043 test1044 test1045 test1046 test1047 test1048 test1049 test105 test1050 test1051 test1052 test1053 test1054 test1055 test1056 test1057 test1058 test1059 test106 test1060 test1061 test1062 test1063 test1064 test1065 test1066 test1067 test1068 test1069 test107 test1070 test1071 test1072 test1073 test1074 test1075 test1076 test1077 test1078 test1079 test108 test1080 test1081 test1082 test1083 test1084 test1085 test1086 test1087 test1088 test1089 test109 test1090 test1091 test1092 test1093 test1094 test1095 test1096 test1097 test1098 test1099 test11 test110 test1100 test1101 test1102 test1103 test1104 test1105 test1106 test1107 test1108 test1109 test111 test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117 test1118 test1119 test112 test1120 test1121 test1122 test1123 test1124 test1125 test1126 test1127 test1128 test1129 test113 test1130 test1131 test1132 test1133 test1134 test1135 test1136 test1137 test1138 test1139 test114 test1140 test1141 test1142 test1143 test1144 test1145 test1146 test1147 test1148 test1149 test115 test1150 test1151 test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 test116 test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1167 test1168 test1169 test117 test1170 test1171 test1172 test1173 test1174 test1175 test1176 test1177 test1178 test1179 test118 test1180 test1181 test1182 test1183 test1184 test1185 test1186 test1187 test1188 test1189 test119 test1190 test1191 test1192 test1193 test1194 test1195 test1196 test1197 test1198 test1199 test12 test120 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 test1208 test1209 test121 test1210 test1211 test1212 test1213 test1214 test1215 test1216 test1217 test1218 test1219 test122 test1220 test1221 test1222 test1223 test1224 test1225 test1226 test1227 test1228 test1229 test123 test1230 test1231 test1232 test1233 test1234 test1235 test1236 test1237 test1238 test1239 test124 test1240 test1241 test1242 test1243 test1244 test1245 test1246 test1247 test1248 test1249 test125 test1250 test1251 test1252 test1253 test1254 test1255 test1256 test1257 test1258 test1259 test126 test1260 test1261 test1262 test1263 test1264 test1265 test1266 test1267 test1268 test1269 test127 test1270 test1271 test1272 test1273 test1274 test1275 test1276 test1277 test1278 test1279 test128 test1280 test1281 test1282 test1283 test1284 test1285 test1286 test1287 test1288 test1289 test129 test1290 test1291 test1292 test1293 test1294 test1295 test1296 test1297 test1298 test1299 test13 test130 test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 test1308 test1309 test131 test1310 test1311 test1312 test1313 test1314 test1315 test1316 test1317 test1318 test1319 test132 test1320 test1321 test1322 test1323 test1324 test1325 test1326 test1327 test1328 test1329 test133 test1330 test1331 test1332 test1333 test1334 test1335 test1336 test1337 test1338 test1339 test134 test1340 test1341 test1342 test1343 test1344 test1345 test1346 test1347 test1348 test1349 test135 test1350 test1351 test1352 test1353 test1354 test1355 test1356 test1357 test1358 test1359 test136 test1360 test1361 test1362 test1363 test1364 test1365 test1366 test1367 test1368 test1369 test137 test1370 test1371 test1372 test1373 test1374 test1375 test1376 test1377 test1378 test1379 test138 test1380 test1381 test1382 test1383 test1384 test1385 test1386 test1387 test1388 test1389 test139 test1390 test1391 test1392 test1393 test1394 test1395 test1396 test1397 test1398 test1399 test14 test140 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 test1408 test1409 test141 test1410 test1411 test1412 test1413 test1414 test1415 test1416 test1417 test1418 test1419 test142 test1420 test1421 test1422 test1423 test1424 test1425 test1426 test1427 test1428 test1429 test143 test1430 test1431 test1432 test1433 test1434 test1435 test1436 test1437 test1438 test1439 test144 test1440 test1441 test1442 test1443 test1444 test1445 test1446 test1447 test1448 test1449 test145 test1450 test1451 test1452 test1453 test1454 test1455 test1456 test1457 test1458 test1459 test146 test1460 test1461 test1462 test1463 test1464 test1465 test1466 test1467 test1468 test1469 test147 test1470 test1471 test1472 test1473 test1474 test1475 test1476 test1477 test1478 test1479 test148 test1480 test1481 test1482 test1483 test1484 test1485 test1486 test1487 test1488 test1489 test149 test1490 test1491 test1492 test1493 test1494 test1495 test1496 test1497 test1498 test1499 test15 test150 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 test1508 test1509 test151 test1510 test1511 test1512 test1513 test1514 test1515 test1516 test1517 test1518 test1519 test152 test1520 test1521 test1522 test1523 test1524 test1525 test1526 test1527 test1528 test1529 test153 test1530 test1531 test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 test154 test1540 test1541 test1542 test1543 test1544 test1545 test1546 test1547 test1548 test1549 test155 test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 test1558 test1559 test156 test1560 test1561 test1562 test1563 test1564 test1565 test1566 test1567 test1568 test1569 test157 test1570 test1571 test1572 test1573 test1574 test1575 test1576 test1577 test1578 test1579 test158 test1580 test1581 test1582 test1583 test1584 test1585 test1586 test1587 test1588 test1589 test159 test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 test1598 test1599 test16 test160 test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 test1608 test1609 test161 test1610 test1611 test1612 test1613 test1614 test1615 test1616 test1617 test1618 test1619 test162 test1620 test1621 test1622 test1623 test1624 test1625 test1626 test1627 test1628 test1629 test163 test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 test1638 test1639 test164 test1640 test1641 test1642 test1643 test1644 test1645 test165 test1650 test1651 test1652 test1653 test1654 test1655 test1656 test1657 test1658 test1659 test166 test1660 test1661 test1662 test1663 test1664 test1665 test1666 test1667 test1668 test1669 test167 test1670 test1671 test1672 test1673 test1674 test1675 test1676 test168 test1680 test1681 test1682 test1683 test1684 test1685 test169 test17 test170 test1700 test1701 test1702 test1703 test1704 test1705 test1706 test1707 test1708 test1709 test171 test1710 test1711 test1712 test1713 test1714 test1715 test172 test1720 test1721 test173 test174 test175 test176 test177 test178 test179 test18 test180 test1800 test1801 test1802 test181 test182 test183 test184 test1847 test1848 test1849 test185 test1850 test1851 test186 test187 test188 test189 test19 test190 test1900 test1901 test1902 test1903 test1904 test1905 test1906 test1907 test1908 test1909 test191 test1910 test1911 test1912 test1913 test1914 test1915 test1916 test1917 test1918 test1919 test192 test1920 test1921 test193 test1933 test1934 test1935 test1936 test1937 test1938 test1939 test194 test1940 test1941 test1942 test1943 test1944 test1945 test1946 test1947 test1948 test195 test1955 test1956 test1957 test1958 test1959 test196 test1960 test1964 test1965 test1966 test197 test1970 test1971 test1972 test1973 test1974 test1975 test1976 test1977 test1978 test1979 test198 test1980 test1981 test1982 test1983 test1984 test199 test2 test20 test200 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 test2008 test2009 test201 test2010 test2011 test2012 test2013 test2014 test202 test2023 test2024 test2025 test2026 test2027 test2028 test2029 test203 test2030 test2031 test2032 test2033 test2034 test2035 test2037 test2038 test2039 test204 test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 test2048 test2049 test205 test2050 test2051 test2052 test2053 test2054 test2055 test2056 test2057 test2058 test2059 test206 test2060 test2061 test2062 test2063 test2064 test2065 test2066 test2067 test2068 test2069 test207 test2070 test2071 test2072 test2073 test2074 test2075 test2076 test2077 test2078 test2079 test208 test2080 test2081 test2082 test2083 test2084 test2085 test2086 test2087 test2088 test2089 test209 test2090 test2091 test2092 test21 test210 test2100 test2101 test2102 test2103 test2104 test211 test212 test213 test214 test215 test216 test217 test218 test219 test22 test220 test2200 test2201 test2202 test2203 test2204 test2205 test2206 test2207 test221 test222 test223 test224 test225 test226 test227 test228 test229 test23 test230 test2300 test2301 test2302 test2303 test2304 test2306 test2307 test2308 test2309 test231 test232 test233 test234 test235 test236 test237 test238 test239 test24 test240 test2400 test2401 test2402 test2403 test2404 test2405 test2406 test2407 test2408 test2409 test241 test2410 test2411 test242 test243 test244 test245 test246 test247 test248 test249 test25 test250 test2500 test2501 test2502 test2503 test2504 test2505 test2506 test251 test252 test253 test254 test255 test256 test257 test258 test259 test26 test260 test2600 test2601 test2602 test2603 test2604 test2605 test261 test262 test263 test264 test265 test266 test267 test268 test269 test27 test270 test2700 test2701 test2702 test2703 test2704 test2705 test2706 test2707 test2708 test2709 test271 test2710 test2711 test2712 test2713 test2714 test2715 test2716 test2717 test2718 test2719 test272 test2720 test2721 test2722 test2723 test273 test274 test275 test276 test277 test278 test279 test28 test280 test281 test282 test283 test284 test285 test286 test287 test288 test289 test29 test290 test291 test292 test293 test294 test295 test296 test297 test298 test299 test3 test30 test300 test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 test3008 test3009 test301 test3010 test3011 test3012 test3013 test3014 test3015 test3016 test3017 test3018 test3019 test302 test3020 test3021 test3022 test3023 test3024 test3025 test3026 test3027 test3028 test3029 test303 test3030 test3031 test3032 test3033 test3034 test3035 test3036 test304 test305 test306 test307 test308 test309 test31 test310 test3100 test3101 test3102 test3103 test3104 test3105 test3106 test311 test312 test313 test314 test315 test316 test317 test318 test319 test32 test320 test3200 test3201 test3202 test3203 test3204 test3205 test3206 test3207 test3208 test3209 test321 test3210 test3211 test3212 test3213 test3214 test3215 test3216 test3217 test3218 test3219 test322 test3220 test323 test324 test325 test326 test327 test328 test329 test33 test330 test3300 test3301 test3302 test331 test332 test333 test334 test335 test336 test337 test338 test339 test34 test340 test341 test342 test343 test344 test345 test346 test347 test348 test349 test35 test350 test351 test352 test353 test354 test355 test356 test357 test358 test359 test36 test360 test361 test362 test363 test364 test365 test366 test367 test368 test369 test37 test370 test371 test372 test373 test374 test375 test376 test378 test379 test38 test380 test381 test383 test384 test385 test386 test387 test388 test389 test39 test390 test391 test392 test393 test394 test395 test396 test397 test398 test399 test4 test40 test400 test4000 test4001 test401 test402 test403 test404 test405 test406 test407 test408 test409 test41 test410 test411 test412 test413 test414 test415 test416 test417 test418 test419 test42 test420 test421 test422 test423 test424 test425 test426 test427 test428 test429 test43 test430 test431 test432 test433 test434 test435 test436 test437 test438 test439 test44 test440 test441 test442 test443 test444 test445 test446 test447 test448 test449 test45 test450 test451 test452 test453 test454 test455 test456 test457 test458 test459 test46 test460 test461 test462 test463 test467 test468 test469 test47 test470 test471 test472 test473 test474 test475 test476 test477 test478 test479 test48 test480 test481 test482 test483 test484 test485 test486 test487 test488 test489 test49 test490 test491 test492 test493 test494 test495 test496 test497 test498 test499 test5 test50 test500 test501 test502 test503 test504 test505 test506 test507 test508 test509 test51 test510 test511 test512 test513 test514 test515 test516 test517 test518 test519 test52 test520 test521 test522 test523 test524 test525 test526 test527 test528 test529 test53 test530 test531 test532 test533 test534 test535 test536 test537 test538 test539 test54 test540 test541 test542 test543 test544 test545 test546 test547 test548 test549 test55 test550 test551 test552 test553 test554 test555 test556 test557 test558 test559 test56 test560 test561 test562 test563 test564 test565 test566 test567 test568 test569 test57 test570 test571 test572 test573 test574 test575 test576 test577 test578 test579 test58 test580 test581 test582 test583 test584 test585 test586 test587 test588 test589 test59 test590 test591 test592 test593 test594 test595 test596 test597 test598 test599 test6 test60 test600 test601 test602 test603 test604 test605 test606 test607 test608 test609 test61 test610 test611 test612 test613 test614 test615 test616 test617 test618 test619 test62 test620 test621 test622 test623 test624 test625 test626 test627 test628 test629 test63 test630 test631 test632 test633 test634 test635 test636 test637 test638 test639 test64 test640 test641 test642 test643 test644 test645 test646 test647 test648 test649 test65 test650 test651 test652 test653 test654 test655 test656 test658 test659 test66 test660 test661 test662 test663 test664 test665 test666 test667 test668 test669 test67 test670 test671 test672 test673 test674 test675 test676 test677 test678 test679 test68 test680 test681 test682 test683 test684 test685 test686 test687 test688 test689 test69 test690 test691 test692 test693 test694 test695 test696 test697 test698 test699 test7 test70 test700 test701 test702 test703 test704 test705 test706 test707 test708 test709 test71 test710 test711 test712 test713 test714 test715 test716 test717 test718 test719 test72 test720 test721 test722 test723 test724 test725 test726 test727 test728 test729 test73 test730 test731 test732 test733 test734 test735 test736 test737 test738 test739 test74 test740 test741 test742 test743 test744 test745 test746 test747 test748 test749 test75 test750 test751 test752 test753 test754 test755 test756 test757 test758 test759 test76 test760 test761 test762 test763 test764 test765 test766 test767 test768 test769 test77 test770 test771 test772 test773 test774 test775 test776 test777 test778 test779 test78 test780 test781 test782 test783 test784 test785 test786 test787 test788 test789 test79 test790 test791 test792 test793 test794 test795 test796 test797 test798 test799 test8 test80 test800 test801 test802 test803 test804 test805 test806 test807 test808 test809 test81 test810 test811 test812 test813 test814 test815 test816 test817 test818 test819 test82 test820 test821 test822 test823 test824 test825 test826 test827 test828 test829 test83 test830 test831 test832 test833 test834 test835 test836 test837 test838 test839 test84 test840 test841 test842 test843 test844 test845 test846 test847 test848 test849 test85 test850 test851 test852 test853 test854 test855 test856 test857 test858 test859 test86 test860 test861 test862 test863 test864 test865 test866 test867 test868 test869 test87 test870 test871 test872 test873 test874 test875 test876 test877 test878 test879 test88 test880 test881 test882 test883 test884 test885 test886 test887 test888 test889 test89 test890 test891 test892 test893 test894 test895 test896 test897 test898 test899 test9 test90 test900 test901 test902 test903 test904 test905 test906 test907 test908 test909 test91 test910 test911 test912 test913 test914 test915 test916 test917 test918 test919 test92 test920 test921 test922 test923 test924 test925 test926 test927 test928 test929 test93 test930 test931 test932 test933 test934 test935 test936 test937 test938 test939 test94 test940 test941 test942 test943 test944 test945 test946 test947 test948 test949 test95 test950 test951 test952 test953 test954 test955 test956 test957 test958 test959 test96 test960 test961 test962 test963 test964 test965 test966 test967 test968 test969 test97 test970 test971 test972 test973 test974 test975 test976 test977 test978 test979 test98 test980 test981 test982 test983 test984 test985 test986 test987 test988 test989 test99 test990 test991 test992 test993 test994 test995 test996 test997 test998 test999http
testenv
__init__.py caddy.py certs.py client.py curl.py dante.py dnsd.py env.py httpd.py nghttpx.py ports.py sshd.py vsftpd.py ws_echo_server.pylibtest
.gitignore CMakeLists.txt Makefile.am Makefile.inc cli_ftp_upload.c cli_h2_pausing.c cli_h2_serverpush.c cli_h2_upgrade_extreme.c cli_hx_download.c cli_hx_upload.c cli_tls_session_reuse.c cli_upload_pausing.c cli_ws_data.c cli_ws_pingpong.c first.c first.h lib1156.c lib1301.c lib1308.c lib1485.c lib1500.c lib1501.c lib1502.c lib1506.c lib1507.c lib1508.c lib1509.c lib1510.c lib1511.c lib1512.c lib1513.c lib1514.c lib1515.c lib1517.c lib1518.c lib1520.c lib1522.c lib1523.c lib1525.c lib1526.c lib1527.c lib1528.c lib1529.c lib1530.c lib1531.c lib1532.c lib1533.c lib1534.c lib1535.c lib1536.c lib1537.c lib1538.c lib1540.c lib1541.c lib1542.c lib1545.c lib1549.c lib1550.c lib1551.c lib1552.c lib1553.c lib1554.c lib1555.c lib1556.c lib1557.c lib1558.c lib1559.c lib1560.c lib1564.c lib1565.c lib1567.c lib1568.c lib1569.c lib1571.c lib1576.c lib1582.c lib1587.c lib1588.c lib1589.c lib1591.c lib1592.c lib1593.c lib1594.c lib1597.c lib1598.c lib1599.c lib1662.c lib1900.c lib1901.c lib1902.c lib1903.c lib1905.c lib1906.c lib1907.c lib1908.c lib1910.c lib1911.c lib1912.c lib1913.c lib1915.c lib1916.c lib1918.c lib1919.c lib1920.c lib1921.c lib1933.c lib1934.c lib1935.c lib1936.c lib1937.c lib1938.c lib1939.c lib1940.c lib1945.c lib1947.c lib1948.c lib1955.c lib1956.c lib1957.c lib1958.c lib1959.c lib1960.c lib1964.c lib1965.c lib1970.c lib1971.c lib1972.c lib1973.c lib1974.c lib1975.c lib1977.c lib1978.c lib2023.c lib2032.c lib2082.c lib2301.c lib2302.c lib2304.c lib2306.c lib2308.c lib2309.c lib2402.c lib2404.c lib2405.c lib2502.c lib2504.c lib2505.c lib2506.c lib2700.c lib3010.c lib3025.c lib3026.c lib3027.c lib3033.c lib3034.c lib3100.c lib3101.c lib3102.c lib3103.c lib3104.c lib3105.c lib3207.c lib3208.c lib500.c lib501.c lib502.c lib503.c lib504.c lib505.c lib506.c lib507.c lib508.c lib509.c lib510.c lib511.c lib512.c lib513.c lib514.c lib515.c lib516.c lib517.c lib518.c lib519.c lib520.c lib521.c lib523.c lib524.c lib525.c lib526.c lib530.c lib533.c lib536.c lib537.c lib539.c lib540.c lib541.c lib542.c lib543.c lib544.c lib547.c lib549.c lib552.c lib553.c lib554.c lib555.c lib556.c lib557.c lib558.c lib559.c lib560.c lib562.c lib564.c lib566.c lib567.c lib568.c lib569.c lib570.c lib571.c lib572.c lib573.c lib574.c lib575.c lib576.c lib578.c lib579.c lib582.c lib583.c lib586.c lib589.c lib590.c lib591.c lib597.c lib598.c lib599.c lib643.c lib650.c lib651.c lib652.c lib653.c lib654.c lib655.c lib658.c lib659.c lib661.c lib666.c lib667.c lib668.c lib670.c lib674.c lib676.c lib677.c lib678.c lib694.c lib695.c lib751.c lib753.c lib757.c lib758.c lib766.c memptr.c mk-lib1521.pl test1013.pl test1022.pl test307.pl test610.pl test613.pl testtrace.c testtrace.h testutil.c testutil.h unitcheck.hserver
.checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc dnsd.c first.c first.h getpart.c mqttd.c resolve.c rtspd.c sockfilt.c socksd.c sws.c tftpd.c util.ctunit
.gitignore CMakeLists.txt Makefile.am Makefile.inc README.md tool1394.c tool1604.c tool1621.c tool1622.c tool1623.c tool1720.cunit
.gitignore CMakeLists.txt Makefile.am Makefile.inc README.md unit1300.c unit1302.c unit1303.c unit1304.c unit1305.c unit1307.c unit1309.c unit1323.c unit1330.c unit1395.c unit1396.c unit1397.c unit1398.c unit1399.c unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c unit1615.c unit1616.c unit1620.c unit1625.c unit1626.c unit1627.c unit1636.c unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c unit1657.c unit1658.c unit1660.c unit1661.c unit1663.c unit1664.c unit1666.c unit1667.c unit1668.c unit1669.c unit1674.c unit1675.c unit1676.c unit1979.c unit1980.c unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c unit2605.c unit3200.c unit3205.c unit3211.c unit3212.c unit3213.c unit3214.c unit3216.c unit3219.c unit3300.c unit3301.c unit3302.cexamples
.env config.ini crypto_test.lua env_test.lua fs_example.lua http_server.lua https_test.lua ini_example.lua json.lua log.lua path_fs_example.lua process_example.lua request_download.lua request_test.lua run_all.lua sqlite_example.lua sqlite_http_template.lua stash_test.lua template_test.lua timer.lua websocket.luainiparser
example
iniexample.c iniwrite.c parse.c twisted-errors.ini twisted-genhuge.py twisted-ofkey.ini twisted-ofval.ini twisted.initest
CMakeLists.txt test_dictionary.c test_iniparser.c unity-config.yml unity_config.hjinjac
libjinjac
src
CMakeLists.txt ast.c ast.h block_statement.c block_statement.h buffer.c buffer.h buildin.c buildin.h common.h convert.c convert.h flex_decl.h jfunction.c jfunction.h jinja_expression.l jinja_expression.y jinjac_parse.c jinjac_parse.h jinjac_stream.c jinjac_stream.h jlist.c jlist.h jobject.c jobject.h parameter.c parameter.h str_obj.c str_obj.h trace.c trace.htest
.gitignore CMakeLists.txt autotest.rb test_01.expected test_01.jinja test_01b.expected test_01b.jinja test_01c.expected test_01c.jinja test_01d.expected test_01d.jinja test_02.expected test_02.jinja test_03.expected test_03.jinja test_04.expected test_04.jinja test_05.expected test_05.jinja test_06.expected test_06.jinja test_07.expected test_07.jinja test_08.expected test_08.jinja test_08b.expected test_08b.jinja test_09.expected test_09.jinja test_10.expected test_10.jinja test_11.expected test_11.jinja test_12.expected test_12.jinja test_13.expected test_13.jinja test_14.expected test_14.jinja test_15.expected test_15.jinja test_16.expected test_16.jinja test_17.expected test_17.jinja test_18.expected test_18.jinja test_18b.expected test_18b.jinja test_18c.expected test_18c.jinja test_19.expected test_19.jinja test_19b.expected test_19b.jinja test_19c.expected test_19c.jinja test_19d.expected test_19d.jinja test_19e.expected test_19e.jinja test_19f.expected test_19f.jinja test_20.expected test_20.jinja test_21.expected test_21.jinja test_22.expected test_22.jinja test_22a.expected test_22a.jinja test_22b.expected test_22b.jinja test_23.expected test_23.jinja test_24.expected test_24.jinjalibev
Changes LICENSE Makefile Makefile.am Makefile.in README Symbols.ev Symbols.event aclocal.m4 autogen.sh compile config.guess config.h config.h.in config.status config.sub configure configure.ac depcomp ev++.h ev.3 ev.c ev.h ev.pod ev_epoll.c ev_kqueue.c ev_poll.c ev_port.c ev_select.c ev_vars.h ev_win32.c ev_wrap.h event.c event.h install-sh libev.m4 libtool ltmain.sh missing mkinstalldirs stamp-h1luajit
doc
bluequad-print.css bluequad.css contact.html ext_buffer.html ext_c_api.html ext_ffi.html ext_ffi_api.html ext_ffi_semantics.html ext_ffi_tutorial.html ext_jit.html ext_profiler.html extensions.html install.html luajit.html running.htmldynasm
dasm_arm.h dasm_arm.lua dasm_arm64.h dasm_arm64.lua dasm_mips.h dasm_mips.lua dasm_mips64.lua dasm_ppc.h dasm_ppc.lua dasm_proto.h dasm_x64.lua dasm_x86.h dasm_x86.lua dynasm.luasrc
host
.gitignore README buildvm.c buildvm.h buildvm_asm.c buildvm_fold.c buildvm_lib.c buildvm_libbc.h buildvm_peobj.c genlibbc.lua genminilua.lua genversion.lua minilua.cjit
.gitignore bc.lua bcsave.lua dis_arm.lua dis_arm64.lua dis_arm64be.lua dis_mips.lua dis_mips64.lua dis_mips64el.lua dis_mips64r6.lua dis_mips64r6el.lua dis_mipsel.lua dis_ppc.lua dis_x64.lua dis_x86.lua dump.lua p.lua v.lua zone.luawolfssl
.github
workflows
ada.yml arduino.yml async-examples.yml async.yml atecc608-sim.yml bind.yml cmake-autoconf.yml cmake.yml codespell.yml coverity-scan-fixes.yml cryptocb-only.yml curl.yml cyrus-sasl.yml disable-pk-algs.yml docker-Espressif.yml docker-OpenWrt.yml emnet-nonblock.yml fil-c.yml freertos-mem-track.yml gencertbuf.yml grpc.yml haproxy.yml hostap-vm.yml intelasm-c-fallback.yml ipmitool.yml jwt-cpp.yml krb5.yml libspdm.yml libssh2.yml libvncserver.yml linuxkm.yml macos-apple-native-cert-validation.yml mbedtls.sh mbedtls.yml membrowse-comment.yml membrowse-onboard.yml membrowse-report.yml memcached.sh memcached.yml mono.yml mosquitto.yml msmtp.yml msys2.yml multi-arch.yml multi-compiler.yml net-snmp.yml nginx.yml no-malloc.yml no-tls.yml nss.sh nss.yml ntp.yml ocsp.yml openldap.yml openssh.yml openssl-ech.yml opensslcoexist.yml openvpn.yml os-check.yml packaging.yml pam-ipmi.yml pq-all.yml pr-commit-check.yml psk.yml puf.yml python.yml rng-tools.yml rust-wrapper.yml se050-sim.yml smallStackSize.yml socat.yml softhsm.yml sssd.yml stm32-sim.yml stsafe-a120-sim.yml stunnel.yml symbol-prefixes.yml threadx.yml tls-anvil.yml trackmemory.yml watcomc.yml win-csharp-test.yml wolfCrypt-Wconversion.yml wolfboot-integration.yml wolfsm.yml xcode.yml zephyr-4.x.yml zephyr.ymlIDE
ARDUINO
Arduino_README_prepend.md README.md include.am keywords.txt library.properties.template wolfssl-arduino.cpp wolfssl-arduino.sh wolfssl.hECLIPSE
Espressif
ESP-IDF
examples
template
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266wolfssl_benchmark
VisualGDB
wolfssl_benchmark_IDF_v4.4_ESP32.sln wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32.sln wolfssl_benchmark_IDF_v5_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32C3.sln wolfssl_benchmark_IDF_v5_ESP32C3.vgdbproj wolfssl_benchmark_IDF_v5_ESP32S3.sln wolfssl_benchmark_IDF_v5_ESP32S3.vgdbprojwolfssl_client
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_client_ESP8266.vgdbprojwolfssl_server
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_server_ESP8266.vgdbprojwolfssl_test
VisualGDB
wolfssl_test-IDF_v5_ESP32.sln wolfssl_test-IDF_v5_ESP32.vgdbproj wolfssl_test-IDF_v5_ESP32C3.sln wolfssl_test-IDF_v5_ESP32C3.vgdbproj wolfssl_test-IDF_v5_ESP32C6.sln wolfssl_test-IDF_v5_ESP32C6.vgdbproj wolfssl_test_IDF_v5_ESP32S3.sln wolfssl_test_IDF_v5_ESP32S3.vgdbprojGCC-ARM
Makefile Makefile.bench Makefile.client Makefile.common Makefile.server Makefile.static Makefile.test README.md include.am linker.ld linker_fips.ldIAR-EWARM
embOS
SAMV71_XULT
embOS_SAMV71_XULT_user_settings
user_settings.h user_settings_simple_example.h user_settings_verbose_example.hembOS_wolfcrypt_benchmark_SAMV71_XULT
README_wolfcrypt_benchmark wolfcrypt_benchmark.ewd wolfcrypt_benchmark.ewpINTIME-RTOS
Makefile README.md include.am libwolfssl.c libwolfssl.vcxproj user_settings.h wolfExamples.c wolfExamples.h wolfExamples.sln wolfExamples.vcxproj wolfssl-lib.sln wolfssl-lib.vcxprojMQX
Makefile README-jp.md README.md client-tls.c include.am server-tls.c user_config.h user_settings.hMSVS-2019-AZSPHERE
wolfssl_new_azsphere
.gitignore CMakeLists.txt CMakeSettings.json app_manifest.json applibs_versions.h launch.vs.json main.cNETOS
Makefile.wolfcrypt.inc README.md include.am user_settings.h user_settings.h-cert2425 user_settings.h-cert3389 wolfssl_netos_custom.cPlatformIO
examples
wolfssl_benchmark
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_benchmark.code-workspaceROWLEY-CROSSWORKS-ARM
Kinetis_FlashPlacement.xml README.md arm_startup.c benchmark_main.c hw.h include.am kinetis_hw.c retarget.c test_main.c user_settings.h wolfssl.hzp wolfssl_ltc.hzpRenesas
e2studio
RA6M3
README.md README_APRA6M_en.md README_APRA6M_jp.md include.amRX72N
EnvisionKit
Simple
README_EN.md README_JP.mdwolfssl_demo
key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h wolfssl_tsip_unit_test.cSTM32Cube
README.md STM32_Benchmarks.md default_conf.ftl include.am main.c wolfssl_example.c wolfssl_example.hWIN
README.txt include.am test.vcxproj user_settings.h user_settings_dtls.h wolfssl-fips.sln wolfssl-fips.vcxprojWIN-SRTP-KDF-140-3
README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxprojWIN10
README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxprojXCODE
Benchmark
include.amXilinxSDK
README.md bench.sh combine.sh eclipse_formatter_profile.xml graph.sh include.am user_settings.h wolfssl_example.capple-universal
wolfssl-multiplatform
iotsafe
Makefile README.md ca-cert.c devices.c devices.h include.am main.c memory-tls.c startup.c target.ld user_settings.hmynewt
README.md apps.wolfcrypttest.pkg.yml crypto.wolfssl.pkg.yml crypto.wolfssl.syscfg.yml include.am setup.shcerts
1024
ca-cert.der ca-cert.pem ca-key.der ca-key.pem client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der dh1024.der dh1024.pem dsa-pub-1024.pem dsa1024.der dsa1024.pem include.am rsa1024.der server-cert.der server-cert.pem server-key.der server-key.pemcrl
extra-crls
ca-int-cert-revoked.pem claim-root.pem crl_critical_entry.pem crlnum_57oct.pem crlnum_64oct.pem general-server-crl.pem large_crlnum.pem large_crlnum2.pemdilithium
bench_dilithium_level2_key.der bench_dilithium_level3_key.der bench_dilithium_level5_key.der include.amecc
bp256r1-key.der bp256r1-key.pem ca-secp256k1-cert.pem ca-secp256k1-key.pem client-bp256r1-cert.der client-bp256r1-cert.pem client-secp256k1-cert.der client-secp256k1-cert.pem genecc.sh include.am secp256k1-key.der secp256k1-key.pem secp256k1-param.pem secp256k1-privkey.der secp256k1-privkey.pem server-bp256r1-cert.der server-bp256r1-cert.pem server-secp256k1-cert.der server-secp256k1-cert.pem server2-secp256k1-cert.der server2-secp256k1-cert.pem wolfssl.cnf wolfssl_384.cnfed25519
ca-ed25519-key.der ca-ed25519-key.pem ca-ed25519-priv.der ca-ed25519-priv.pem ca-ed25519.der ca-ed25519.pem client-ed25519-key.der client-ed25519-key.pem client-ed25519-priv.der client-ed25519-priv.pem client-ed25519.der client-ed25519.pem eddsa-ed25519.der eddsa-ed25519.pem gen-ed25519-certs.sh gen-ed25519-keys.sh gen-ed25519.sh include.am root-ed25519-key.der root-ed25519-key.pem root-ed25519-priv.der root-ed25519-priv.pem root-ed25519.der root-ed25519.pem server-ed25519-cert.pem server-ed25519-key.der server-ed25519-key.pem server-ed25519-priv.der server-ed25519-priv.pem server-ed25519.der server-ed25519.pemed448
ca-ed448-key.der ca-ed448-key.pem ca-ed448-priv.der ca-ed448-priv.pem ca-ed448.der ca-ed448.pem client-ed448-key.der client-ed448-key.pem client-ed448-priv.der client-ed448-priv.pem client-ed448.der client-ed448.pem gen-ed448-certs.sh gen-ed448-keys.sh include.am root-ed448-key.der root-ed448-key.pem root-ed448-priv.der root-ed448-priv.pem root-ed448.der root-ed448.pem server-ed448-cert.pem server-ed448-key.der server-ed448-key.pem server-ed448-priv.der server-ed448-priv.pem server-ed448.der server-ed448.pemexternal
DigiCertGlobalRootCA.pem README.txt ca-digicert-ev.pem ca-globalsign-root.pem ca-google-root.pem ca_collection.pem include.amintermediate
ca_false_intermediate
gentestcert.sh int_ca.key server.key test_ca.key test_ca.pem test_int_not_cacert.pem test_sign_bynoca_srv.pem wolfssl_base.conf wolfssl_srv.conflms
bc_hss_L2_H5_W8_root.der bc_hss_L3_H5_W4_root.der bc_lms_chain_ca.der bc_lms_chain_leaf.der bc_lms_native_bc_root.der bc_lms_sha256_h10_w8_root.der bc_lms_sha256_h5_w4_root.der include.ammldsa
README.txt include.am mldsa44-cert.der mldsa44-cert.pem mldsa44-key.pem mldsa44_bare-priv.der mldsa44_bare-seed.der mldsa44_oqskeypair.der mldsa44_priv-only.der mldsa44_pub-spki.der mldsa44_seed-only.der mldsa44_seed-priv.der mldsa65-cert.der mldsa65-cert.pem mldsa65-key.pem mldsa65_bare-priv.der mldsa65_bare-seed.der mldsa65_oqskeypair.der mldsa65_priv-only.der mldsa65_pub-spki.der mldsa65_seed-only.der mldsa65_seed-priv.der mldsa87-cert.der mldsa87-cert.pem mldsa87-key.pem mldsa87_bare-priv.der mldsa87_bare-seed.der mldsa87_oqskeypair.der mldsa87_priv-only.der mldsa87_pub-spki.der mldsa87_seed-only.der mldsa87_seed-priv.derocsp
imposter-root-ca-cert.der imposter-root-ca-cert.pem imposter-root-ca-key.der imposter-root-ca-key.pem include.am index-ca-and-intermediate-cas.txt index-ca-and-intermediate-cas.txt.attr index-intermediate1-ca-issued-certs.txt index-intermediate1-ca-issued-certs.txt.attr index-intermediate2-ca-issued-certs.txt index-intermediate2-ca-issued-certs.txt.attr index-intermediate3-ca-issued-certs.txt index-intermediate3-ca-issued-certs.txt.attr intermediate1-ca-cert.der intermediate1-ca-cert.pem intermediate1-ca-key.der intermediate1-ca-key.pem intermediate2-ca-cert.der intermediate2-ca-cert.pem intermediate2-ca-key.der intermediate2-ca-key.pem intermediate3-ca-cert.der intermediate3-ca-cert.pem intermediate3-ca-key.der intermediate3-ca-key.pem ocsp-responder-cert.der ocsp-responder-cert.pem ocsp-responder-key.der ocsp-responder-key.pem openssl.cnf renewcerts-for-test.sh renewcerts.sh root-ca-cert.der root-ca-cert.pem root-ca-crl.pem root-ca-key.der root-ca-key.pem server1-cert.der server1-cert.pem server1-chain-noroot.pem server1-key.der server1-key.pem server2-cert.der server2-cert.pem server2-key.der server2-key.pem server3-cert.der server3-cert.pem server3-key.der server3-key.pem server4-cert.der server4-cert.pem server4-key.der server4-key.pem server5-cert.der server5-cert.pem server5-key.der server5-key.pem test-leaf-response.der test-multi-response.der test-response-nointern.der test-response-rsapss.der test-response.derp521
ca-p521-key.der ca-p521-key.pem ca-p521-priv.der ca-p521-priv.pem ca-p521.der ca-p521.pem client-p521-key.der client-p521-key.pem client-p521-priv.der client-p521-priv.pem client-p521.der client-p521.pem gen-p521-certs.sh gen-p521-keys.sh include.am root-p521-key.der root-p521-key.pem root-p521-priv.der root-p521-priv.pem root-p521.der root-p521.pem server-p521-cert.pem server-p521-key.der server-p521-key.pem server-p521-priv.der server-p521-priv.pem server-p521.der server-p521.pemrpk
client-cert-rpk.der client-ecc-cert-rpk.der include.am server-cert-rpk.der server-ecc-cert-rpk.derrsapss
ca-3072-rsapss-key.der ca-3072-rsapss-key.pem ca-3072-rsapss-priv.der ca-3072-rsapss-priv.pem ca-3072-rsapss.der ca-3072-rsapss.pem ca-rsapss-key.der ca-rsapss-key.pem ca-rsapss-priv.der ca-rsapss-priv.pem ca-rsapss.der ca-rsapss.pem client-3072-rsapss-key.der client-3072-rsapss-key.pem client-3072-rsapss-priv.der client-3072-rsapss-priv.pem client-3072-rsapss.der client-3072-rsapss.pem client-rsapss-key.der client-rsapss-key.pem client-rsapss-priv.der client-rsapss-priv.pem client-rsapss.der client-rsapss.pem gen-rsapss-keys.sh include.am renew-rsapss-certs.sh root-3072-rsapss-key.der root-3072-rsapss-key.pem root-3072-rsapss-priv.der root-3072-rsapss-priv.pem root-3072-rsapss.der root-3072-rsapss.pem root-rsapss-key.der root-rsapss-key.pem root-rsapss-priv.der root-rsapss-priv.pem root-rsapss.der root-rsapss.pem server-3072-rsapss-cert.pem server-3072-rsapss-key.der server-3072-rsapss-key.pem server-3072-rsapss-priv.der server-3072-rsapss-priv.pem server-3072-rsapss.der server-3072-rsapss.pem server-mix-rsapss-cert.pem server-rsapss-cert.pem server-rsapss-key.der server-rsapss-key.pem server-rsapss-priv.der server-rsapss-priv.pem server-rsapss.der server-rsapss.pemslhdsa
bench_slhdsa_sha2_128f_key.der bench_slhdsa_sha2_128s_key.der bench_slhdsa_sha2_192f_key.der bench_slhdsa_sha2_192s_key.der bench_slhdsa_sha2_256f_key.der bench_slhdsa_sha2_256s_key.der bench_slhdsa_shake128f_key.der bench_slhdsa_shake128s_key.der bench_slhdsa_shake192f_key.der bench_slhdsa_shake192s_key.der bench_slhdsa_shake256f_key.der bench_slhdsa_shake256s_key.der client-mldsa44-priv.pem client-mldsa44-sha2.der client-mldsa44-sha2.pem client-mldsa44-shake.der client-mldsa44-shake.pem gen-slhdsa-mldsa-certs.sh include.am root-slhdsa-sha2-128s-priv.der root-slhdsa-sha2-128s-priv.pem root-slhdsa-sha2-128s.der root-slhdsa-sha2-128s.pem root-slhdsa-shake-128s-priv.der root-slhdsa-shake-128s-priv.pem root-slhdsa-shake-128s.der root-slhdsa-shake-128s.pem server-mldsa44-priv.pem server-mldsa44-sha2.der server-mldsa44-sha2.pem server-mldsa44-shake.der server-mldsa44-shake.pemsm2
ca-sm2-key.der ca-sm2-key.pem ca-sm2-priv.der ca-sm2-priv.pem ca-sm2.der ca-sm2.pem client-sm2-key.der client-sm2-key.pem client-sm2-priv.der client-sm2-priv.pem client-sm2.der client-sm2.pem fix_sm2_spki.py gen-sm2-certs.sh gen-sm2-keys.sh include.am root-sm2-key.der root-sm2-key.pem root-sm2-priv.der root-sm2-priv.pem root-sm2.der root-sm2.pem self-sm2-cert.pem self-sm2-key.pem self-sm2-priv.pem server-sm2-cert.der server-sm2-cert.pem server-sm2-key.der server-sm2-key.pem server-sm2-priv.der server-sm2-priv.pem server-sm2.der server-sm2.pemstatickeys
dh-ffdhe2048-params.pem dh-ffdhe2048-pub.der dh-ffdhe2048-pub.pem dh-ffdhe2048.der dh-ffdhe2048.pem ecc-secp256r1.der ecc-secp256r1.pem gen-static.sh include.am x25519-pub.der x25519-pub.pem x25519.der x25519.pemtest
catalog.txt cert-bad-neg-int.der cert-bad-oid.der cert-bad-utf8.der cert-ext-ia.cfg cert-ext-ia.der cert-ext-ia.pem cert-ext-joi.cfg cert-ext-joi.der cert-ext-joi.pem cert-ext-mnc.der cert-ext-multiple.cfg cert-ext-multiple.der cert-ext-multiple.pem cert-ext-nc-combined.der cert-ext-nc-combined.pem cert-ext-nc.cfg cert-ext-nc.der cert-ext-nc.pem cert-ext-ncdns.der cert-ext-ncdns.pem cert-ext-ncip.der cert-ext-ncip.pem cert-ext-ncmixed.der cert-ext-ncmulti.der cert-ext-ncmulti.pem cert-ext-ncrid.der cert-ext-ncrid.pem cert-ext-nct.cfg cert-ext-nct.der cert-ext-nct.pem cert-ext-ndir-exc.cfg cert-ext-ndir-exc.der cert-ext-ndir-exc.pem cert-ext-ndir.cfg cert-ext-ndir.der cert-ext-ndir.pem cert-ext-ns.der cert-over-max-altnames.cfg cert-over-max-altnames.der cert-over-max-altnames.pem cert-over-max-nc.cfg cert-over-max-nc.der cert-over-max-nc.pem client-ecc-cert-ski.hex cn-ip-literal.der cn-ip-wildcard.der crit-cert.pem crit-key.pem dh1024.der dh1024.pem dh512.der dh512.pem digsigku.pem encrypteddata.msg gen-badsig.sh gen-ext-certs.sh gen-testcerts.sh include.am kari-keyid-cms.msg ktri-keyid-cms.msg ossl-trusted-cert.pem server-badaltname.der server-badaltname.pem server-badaltnull.der server-badaltnull.pem server-badcn.der server-badcn.pem server-badcnnull.der server-badcnnull.pem server-cert-ecc-badsig.der server-cert-ecc-badsig.pem server-cert-rsa-badsig.der server-cert-rsa-badsig.pem server-duplicate-policy.pem server-garbage.der server-garbage.pem server-goodalt.der server-goodalt.pem server-goodaltwild.der server-goodaltwild.pem server-goodcn.der server-goodcn.pem server-goodcnwild.der server-goodcnwild.pem server-localhost.der server-localhost.pem smime-test-canon.p7s smime-test-multipart-badsig.p7s smime-test-multipart.p7s smime-test.p7stest-pathlen
assemble-chains.sh chainA-ICA1-key.pem chainA-ICA1-pathlen0.pem chainA-assembled.pem chainA-entity-key.pem chainA-entity.pem chainB-ICA1-key.pem chainB-ICA1-pathlen0.pem chainB-ICA2-key.pem chainB-ICA2-pathlen1.pem chainB-assembled.pem chainB-entity-key.pem chainB-entity.pem chainC-ICA1-key.pem chainC-ICA1-pathlen1.pem chainC-assembled.pem chainC-entity-key.pem chainC-entity.pem chainD-ICA1-key.pem chainD-ICA1-pathlen127.pem chainD-assembled.pem chainD-entity-key.pem chainD-entity.pem chainE-ICA1-key.pem chainE-ICA1-pathlen128.pem chainE-assembled.pem chainE-entity-key.pem chainE-entity.pem chainF-ICA1-key.pem chainF-ICA1-pathlen1.pem chainF-ICA2-key.pem chainF-ICA2-pathlen0.pem chainF-assembled.pem chainF-entity-key.pem chainF-entity.pem chainG-ICA1-key.pem chainG-ICA1-pathlen0.pem chainG-ICA2-key.pem chainG-ICA2-pathlen1.pem chainG-ICA3-key.pem chainG-ICA3-pathlen99.pem chainG-ICA4-key.pem chainG-ICA4-pathlen5.pem chainG-ICA5-key.pem chainG-ICA5-pathlen20.pem chainG-ICA6-key.pem chainG-ICA6-pathlen10.pem chainG-ICA7-key.pem chainG-ICA7-pathlen100.pem chainG-assembled.pem chainG-entity-key.pem chainG-entity.pem chainH-ICA1-key.pem chainH-ICA1-pathlen0.pem chainH-ICA2-key.pem chainH-ICA2-pathlen2.pem chainH-ICA3-key.pem chainH-ICA3-pathlen2.pem chainH-ICA4-key.pem chainH-ICA4-pathlen2.pem chainH-assembled.pem chainH-entity-key.pem chainH-entity.pem chainI-ICA1-key.pem chainI-ICA1-no_pathlen.pem chainI-ICA2-key.pem chainI-ICA2-no_pathlen.pem chainI-ICA3-key.pem chainI-ICA3-pathlen2.pem chainI-assembled.pem chainI-entity-key.pem chainI-entity.pem chainJ-ICA1-key.pem chainJ-ICA1-no_pathlen.pem chainJ-ICA2-key.pem chainJ-ICA2-no_pathlen.pem chainJ-ICA3-key.pem chainJ-ICA3-no_pathlen.pem chainJ-ICA4-key.pem chainJ-ICA4-pathlen2.pem chainJ-assembled.pem chainJ-entity-key.pem chainJ-entity.pem include.am refreshkeys.shtest-serial0
ee_normal.pem ee_serial0.pem generate_certs.sh include.am intermediate_serial0.pem root_serial0.pem root_serial0_key.pem selfsigned_nonca_serial0.pemxmss
bc_xmss_chain_ca.der bc_xmss_chain_leaf.der bc_xmss_sha2_10_256_root.der bc_xmss_sha2_16_256_root.der bc_xmssmt_sha2_20_2_256_root.der bc_xmssmt_sha2_20_4_256_root.der bc_xmssmt_sha2_40_8_256_root.der include.amcmake
Config.cmake.in README.md config.in functions.cmake include.am options.h.in wolfssl-config-version.cmake.in wolfssl-targets.cmake.indebian
changelog.in control.in copyright include.am libwolfssl-dev.install libwolfssl.install rules.indoc
dox_comments
header_files
aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h puf.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wc_she.h wc_slhdsa.h wolfio.hheader_files-ja
aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wolfio.hexamples
async
Makefile README.md async_client.c async_server.c async_tls.c async_tls.h include.am user_settings.hconfigs
README.md include.am user_settings_EBSnet.h user_settings_all.h user_settings_arduino.h user_settings_baremetal.h user_settings_ca.h user_settings_curve25519nonblock.h user_settings_dtls13.h user_settings_eccnonblock.h user_settings_espressif.h user_settings_fipsv2.h user_settings_fipsv5.h user_settings_min_ecc.h user_settings_openssl_compat.h user_settings_pkcs7.h user_settings_platformio.h user_settings_pq.h user_settings_rsa_only.h user_settings_stm32.h user_settings_template.h user_settings_tls12.h user_settings_tls13.h user_settings_wolfboot_keytools.h user_settings_wolfssh.h user_settings_wolftpm.hechoclient
echoclient.c echoclient.h echoclient.sln echoclient.vcproj echoclient.vcxproj include.am quitlinuxkm
Kbuild Makefile README.md get_thread_size.c include.am linuxkm-fips-hash-wrapper.sh linuxkm-fips-hash.c linuxkm_memory.c linuxkm_memory.h linuxkm_wc_port.h lkcapi_aes_glue.c lkcapi_dh_glue.c lkcapi_ecdh_glue.c lkcapi_ecdsa_glue.c lkcapi_glue.c lkcapi_rsa_glue.c lkcapi_sha_glue.c module_exports.c.template module_hooks.c pie_redirect_table.c wolfcrypt.lds x86_vector_register_glue.cm4
ax_add_am_macro.m4 ax_am_jobserver.m4 ax_am_macros.m4 ax_append_compile_flags.m4 ax_append_flag.m4 ax_append_link_flags.m4 ax_append_to_file.m4 ax_atomic.m4 ax_bsdkm.m4 ax_check_compile_flag.m4 ax_check_link_flag.m4 ax_compiler_version.m4 ax_count_cpus.m4 ax_create_generic_config.m4 ax_debug.m4 ax_file_escapes.m4 ax_harden_compiler_flags.m4 ax_linuxkm.m4 ax_print_to_file.m4 ax_pthread.m4 ax_require_defined.m4 ax_tls.m4 ax_vcs_checkout.m4 hexversion.m4 lib_socket_nsl.m4 visibility.m4mqx
wolfcrypt_benchmark
ReferencedRSESystems.xml wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launchwolfcrypt_test
ReferencedRSESystems.xml wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launchwolfssl_client
ReferencedRSESystems.xml wolfssl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launchscripts
aria-cmake-build-test.sh asn1_oid_sum.pl benchmark.test benchmark_compare.sh cleanup_testfiles.sh crl-gen-openssl.test crl-revoked.test dertoc.pl dtls.test dtlscid.test external.test google.test include.am makedistsmall.sh memtest.sh ocsp-responder-openssl-interop.test ocsp-stapling-with-ca-as-responder.test ocsp-stapling-with-wolfssl-responder.test ocsp-stapling.test ocsp-stapling2.test ocsp-stapling_tls13multi.test ocsp.test openssl.test openssl_srtp.test pem.test ping.test pkcallbacks.test psk.test resume.test rsapss.test sniffer-gen.sh sniffer-ipv6.pcap sniffer-static-rsa.pcap sniffer-testsuite.test sniffer-tls12-keylog.out sniffer-tls12-keylog.pcap sniffer-tls12-keylog.sslkeylog sniffer-tls13-dh-resume.pcap sniffer-tls13-dh.pcap sniffer-tls13-ecc-resume.pcap sniffer-tls13-ecc.pcap sniffer-tls13-hrr.pcap sniffer-tls13-keylog.out sniffer-tls13-keylog.pcap sniffer-tls13-keylog.sslkeylog sniffer-tls13-x25519-resume.pcap sniffer-tls13-x25519.pcap stm32l4-v4_0_1_build.sh tls13.test trusted_peer.test unit.test.in user_settings_asm.shsrc
bio.c conf.c crl.c dtls.c dtls13.c include.am internal.c keys.c ocsp.c pk.c pk_ec.c pk_rsa.c quic.c sniffer.c ssl.c ssl_api_cert.c ssl_api_crl_ocsp.c ssl_api_pk.c ssl_asn1.c ssl_bn.c ssl_certman.c ssl_crypto.c ssl_ech.c ssl_load.c ssl_misc.c ssl_p7p12.c ssl_sess.c ssl_sk.c tls.c tls13.c wolfio.c x509.c x509_str.ctests
api
api.h api_decl.h create_ocsp_test_blobs.py include.am test_aes.c test_aes.h test_arc4.c test_arc4.h test_ascon.c test_ascon.h test_ascon_kats.h test_asn.c test_asn.h test_blake2.c test_blake2.h test_camellia.c test_camellia.h test_certman.c test_certman.h test_chacha.c test_chacha.h test_chacha20_poly1305.c test_chacha20_poly1305.h test_cmac.c test_cmac.h test_curve25519.c test_curve25519.h test_curve448.c test_curve448.h test_des3.c test_des3.h test_dh.c test_dh.h test_digest.h test_dsa.c test_dsa.h test_dtls.c test_dtls.h test_ecc.c test_ecc.h test_ed25519.c test_ed25519.h test_ed448.c test_ed448.h test_evp.c test_evp.h test_evp_cipher.c test_evp_cipher.h test_evp_digest.c test_evp_digest.h test_evp_pkey.c test_evp_pkey.h test_hash.c test_hash.h test_hmac.c test_hmac.h test_md2.c test_md2.h test_md4.c test_md4.h test_md5.c test_md5.h test_mldsa.c test_mldsa.h test_mlkem.c test_mlkem.h test_ocsp.c test_ocsp.h test_ocsp_test_blobs.h test_ossl_asn1.c test_ossl_asn1.h test_ossl_bio.c test_ossl_bio.h test_ossl_bn.c test_ossl_bn.h test_ossl_cipher.c test_ossl_cipher.h test_ossl_dgst.c test_ossl_dgst.h test_ossl_dh.c test_ossl_dh.h test_ossl_dsa.c test_ossl_dsa.h test_ossl_ec.c test_ossl_ec.h test_ossl_ecx.c test_ossl_ecx.h test_ossl_mac.c test_ossl_mac.h test_ossl_obj.c test_ossl_obj.h test_ossl_p7p12.c test_ossl_p7p12.h test_ossl_pem.c test_ossl_pem.h test_ossl_rand.c test_ossl_rand.h test_ossl_rsa.c test_ossl_rsa.h test_ossl_sk.c test_ossl_sk.h test_ossl_x509.c test_ossl_x509.h test_ossl_x509_acert.c test_ossl_x509_acert.h test_ossl_x509_crypto.c test_ossl_x509_crypto.h test_ossl_x509_ext.c test_ossl_x509_ext.h test_ossl_x509_info.c test_ossl_x509_info.h test_ossl_x509_io.c test_ossl_x509_io.h test_ossl_x509_lu.c test_ossl_x509_lu.h test_ossl_x509_name.c test_ossl_x509_name.h test_ossl_x509_pk.c test_ossl_x509_pk.h test_ossl_x509_str.c test_ossl_x509_str.h test_ossl_x509_vp.c test_ossl_x509_vp.h test_pkcs12.c test_pkcs12.h test_pkcs7.c test_pkcs7.h test_poly1305.c test_poly1305.h test_random.c test_random.h test_rc2.c test_rc2.h test_ripemd.c test_ripemd.h test_rsa.c test_rsa.h test_sha.c test_sha.h test_sha256.c test_sha256.h test_sha3.c test_sha3.h test_sha512.c test_sha512.h test_she.c test_she.h test_signature.c test_signature.h test_slhdsa.c test_slhdsa.h test_sm2.c test_sm2.h test_sm3.c test_sm3.h test_sm4.c test_sm4.h test_tls.c test_tls.h test_tls13.c test_tls13.h test_tls_ext.c test_tls_ext.h test_wc_encrypt.c test_wc_encrypt.h test_wolfmath.c test_wolfmath.h test_x509.c test_x509.hwolfcrypt
benchmark
README.md benchmark-VS2022.sln benchmark-VS2022.vcxproj benchmark-VS2022.vcxproj.user benchmark.c benchmark.h benchmark.sln benchmark.vcproj benchmark.vcxproj include.amsrc
port
Espressif
esp_crt_bundle
README.md cacrt_all.pem cacrt_deprecated.pem cacrt_local.pem esp_crt_bundle.c gen_crt_bundle.py pio_install_cryptography.pyRenesas
README.md renesas_common.c renesas_fspsm_aes.c renesas_fspsm_rsa.c renesas_fspsm_sha.c renesas_fspsm_util.c renesas_rx64_hw_sha.c renesas_rx64_hw_util.c renesas_tsip_aes.c renesas_tsip_rsa.c renesas_tsip_sha.c renesas_tsip_util.carm
armv8-32-aes-asm.S armv8-32-aes-asm_c.c armv8-32-chacha-asm.S armv8-32-chacha-asm_c.c armv8-32-curve25519.S armv8-32-curve25519_c.c armv8-32-mlkem-asm.S armv8-32-mlkem-asm_c.c armv8-32-poly1305-asm.S armv8-32-poly1305-asm_c.c armv8-32-sha256-asm.S armv8-32-sha256-asm_c.c armv8-32-sha3-asm.S armv8-32-sha3-asm_c.c armv8-32-sha512-asm.S armv8-32-sha512-asm_c.c armv8-aes-asm.S armv8-aes-asm_c.c armv8-aes.c armv8-chacha-asm.S armv8-chacha-asm_c.c armv8-curve25519.S armv8-curve25519_c.c armv8-mlkem-asm.S armv8-mlkem-asm_c.c armv8-poly1305-asm.S armv8-poly1305-asm_c.c armv8-sha256-asm.S armv8-sha256-asm_c.c armv8-sha256.c armv8-sha3-asm.S armv8-sha3-asm_c.c armv8-sha512-asm.S armv8-sha512-asm_c.c armv8-sha512.c cryptoCell.c cryptoCellHash.c thumb2-aes-asm.S thumb2-aes-asm_c.c thumb2-chacha-asm.S thumb2-chacha-asm_c.c thumb2-curve25519.S thumb2-curve25519_c.c thumb2-mlkem-asm.S thumb2-mlkem-asm_c.c thumb2-poly1305-asm.S thumb2-poly1305-asm_c.c thumb2-sha256-asm.S thumb2-sha256-asm_c.c thumb2-sha3-asm.S thumb2-sha3-asm_c.c thumb2-sha512-asm.S thumb2-sha512-asm_c.ccaam
README.md caam_aes.c caam_doc.pdf caam_driver.c caam_error.c caam_integrity.c caam_qnx.c caam_sha.c wolfcaam_aes.c wolfcaam_cmac.c wolfcaam_ecdsa.c wolfcaam_fsl_nxp.c wolfcaam_hash.c wolfcaam_hmac.c wolfcaam_init.c wolfcaam_qnx.c wolfcaam_rsa.c wolfcaam_seco.c wolfcaam_x25519.cdevcrypto
README.md devcrypto_aes.c devcrypto_ecdsa.c devcrypto_hash.c devcrypto_hmac.c devcrypto_rsa.c devcrypto_x25519.c wc_devcrypto.criscv
riscv-64-aes.c riscv-64-chacha.c riscv-64-poly1305.c riscv-64-sha256.c riscv-64-sha3.c riscv-64-sha512.cwolfssl
openssl
aes.h asn1.h asn1t.h bio.h bn.h buffer.h camellia.h cmac.h cms.h compat_types.h conf.h crypto.h des.h dh.h dsa.h ec.h ec25519.h ec448.h ecdh.h ecdsa.h ed25519.h ed448.h engine.h err.h evp.h fips_rand.h hmac.h include.am kdf.h lhash.h md4.h md5.h modes.h obj_mac.h objects.h ocsp.h opensslconf.h opensslv.h ossl_typ.h pem.h pkcs12.h pkcs7.h rand.h rc4.h ripemd.h rsa.h safestack.h sha.h sha3.h srp.h ssl.h ssl23.h stack.h tls1.h txt_db.h ui.h x509.h x509_vfy.h x509v3.hwolfcrypt
port
Renesas
renesas-fspsm-crypt.h renesas-fspsm-types.h renesas-rx64-hw-crypt.h renesas-tsip-crypt.h renesas_cmn.h renesas_fspsm_internal.h renesas_sync.h renesas_tsip_internal.h renesas_tsip_types.hcaam
caam_driver.h caam_error.h caam_qnx.h wolfcaam.h wolfcaam_aes.h wolfcaam_cmac.h wolfcaam_ecdsa.h wolfcaam_fsl_nxp.h wolfcaam_hash.h wolfcaam_qnx.h wolfcaam_rsa.h wolfcaam_seco.h wolfcaam_sha.h wolfcaam_x25519.hwrapper
Ada
examples
src
aes_verify_main.adb rsa_verify_main.adb sha256_main.adb spark_sockets.adb spark_sockets.ads spark_terminal.adb spark_terminal.ads tls_client.adb tls_client.ads tls_client_main.adb tls_server.adb tls_server.ads tls_server_main.adbtests
src
aes_bindings_tests.adb aes_bindings_tests.ads rsa_verify_bindings_tests.adb rsa_verify_bindings_tests.ads sha256_bindings_tests.adb sha256_bindings_tests.ads tests.adbCSharp
wolfSSL-Example-IOCallbacks
App.config wolfSSL-Example-IOCallbacks.cs wolfSSL-Example-IOCallbacks.csprojwolfSSL-TLS-ServerThreaded
App.config wolfSSL-TLS-ServerThreaded.cs wolfSSL-TLS-ServerThreaded.csprojrust
wolfssl-wolfcrypt
src
aes.rs blake2.rs chacha20_poly1305.rs cmac.rs cmac_mac.rs curve25519.rs dh.rs dilithium.rs ecc.rs ecdsa.rs ed25519.rs ed448.rs fips.rs hkdf.rs hmac.rs hmac_mac.rs kdf.rs lib.rs lms.rs mlkem.rs mlkem_kem.rs pbkdf2_password_hash.rs prf.rs random.rs rsa.rs rsa_pkcs1v15.rs sha.rs sha_digest.rs sys.rstests
test_aes.rs test_blake2.rs test_chacha20_poly1305.rs test_cmac.rs test_cmac_mac.rs test_curve25519.rs test_dh.rs test_dilithium.rs test_ecc.rs test_ecdsa.rs test_ed25519.rs test_ed448.rs test_hkdf.rs test_hmac.rs test_hmac_mac.rs test_kdf.rs test_lms.rs test_mlkem.rs test_mlkem_kem.rs test_pbkdf2_password_hash.rs test_prf.rs test_random.rs test_rsa.rs test_rsa_pkcs1v15.rs test_sha.rs test_sha_digest.rs test_wolfcrypt.rszephyr
samples
wolfssl_benchmark
CMakeLists.txt README install_test.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.confwolfssl_test
CMakeLists.txt README install_test.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
libev/ev.3
raw
1.\" -*- mode: troff; coding: utf-8 -*-
2.\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3.\"
4.\" Standard preamble:
5.\" ========================================================================
6.de Sp \" Vertical space (when we can't use .PP)
7.if t .sp .5v
8.if n .sp
9..
10.de Vb \" Begin verbatim text
11.ft CW
12.nf
13.ne \\$1
14..
15.de Ve \" End verbatim text
16.ft R
17.fi
18..
19.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20.ie n \{\
21. ds C` ""
22. ds C' ""
23'br\}
24.el\{\
25. ds C`
26. ds C'
27'br\}
28.\"
29.\" Escape single quotes in literal strings from groff's Unicode transform.
30.ie \n(.g .ds Aq \(aq
31.el .ds Aq '
32.\"
33.\" If the F register is >0, we'll generate index entries on stderr for
34.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35.\" entries marked with X<> in POD. Of course, you'll have to process the
36.\" output yourself in some meaningful fashion.
37.\"
38.\" Avoid warning from groff about undefined register 'F'.
39.de IX
40..
41.nr rF 0
42.if \n(.g .if rF .nr rF 1
43.if (\n(rF:(\n(.g==0)) \{\
44. if \nF \{\
45. de IX
46. tm Index:\\$1\t\\n%\t"\\$2"
47..
48. if !\nF==2 \{\
49. nr % 0
50. nr F 2
51. \}
52. \}
53.\}
54.rr rF
55.\"
56.\" Required to disable full justification in groff 1.23.0.
57.if n .ds AD l
58.\" ========================================================================
59.\"
60.IX Title "LIBEV 3"
61.TH LIBEV 3 2026-05-15 libev-4.22 "libev - high performance full featured event loop"
62.\" For nroff, turn off justification. Always turn off hyphenation; it makes
63.\" way too many mistakes in technical documents.
64.if n .ad l
65.nh
66.SH NAME
67libev \- a high performance full\-featured event loop written in C
68.SH SYNOPSIS
69.IX Header "SYNOPSIS"
70.Vb 1
71\& #include <ev.h>
72.Ve
73.SS "EXAMPLE PROGRAM"
74.IX Subsection "EXAMPLE PROGRAM"
75.Vb 2
76\& // a single header file is required
77\& #include <ev.h>
78\&
79\& #include <stdio.h> // for puts
80\&
81\& // every watcher type has its own typedef\*(Aqd struct
82\& // with the name ev_TYPE
83\& ev_io stdin_watcher;
84\& ev_timer timeout_watcher;
85\&
86\& // all watcher callbacks have a similar signature
87\& // this callback is called when data is readable on stdin
88\& static void
89\& stdin_cb (EV_P_ ev_io *w, int revents)
90\& {
91\& puts ("stdin ready");
92\& // for one\-shot events, one must manually stop the watcher
93\& // with its corresponding stop function.
94\& ev_io_stop (EV_A_ w);
95\&
96\& // this causes all nested ev_run\*(Aqs to stop iterating
97\& ev_break (EV_A_ EVBREAK_ALL);
98\& }
99\&
100\& // another callback, this time for a time\-out
101\& static void
102\& timeout_cb (EV_P_ ev_timer *w, int revents)
103\& {
104\& puts ("timeout");
105\& // this causes the innermost ev_run to stop iterating
106\& ev_break (EV_A_ EVBREAK_ONE);
107\& }
108\&
109\& int
110\& main (void)
111\& {
112\& // use the default event loop unless you have special needs
113\& struct ev_loop *loop = EV_DEFAULT;
114\&
115\& // initialise an io watcher, then start it
116\& // this one will watch for stdin to become readable
117\& ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
118\& ev_io_start (loop, &stdin_watcher);
119\&
120\& // initialise a timer watcher, then start it
121\& // simple non\-repeating 5.5 second timeout
122\& ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.);
123\& ev_timer_start (loop, &timeout_watcher);
124\&
125\& // now wait for events to arrive
126\& ev_run (loop, 0);
127\&
128\& // break was called, so exit
129\& return 0;
130\& }
131.Ve
132.SH "ABOUT THIS DOCUMENT"
133.IX Header "ABOUT THIS DOCUMENT"
134This document documents the libev software package.
135.PP
136The newest version of this document is also available as an html\-formatted
137web page you might find easier to navigate when reading it for the first
138time: <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod>.
139.PP
140While this document tries to be as complete as possible in documenting
141libev, its usage and the rationale behind its design, it is not a tutorial
142on event\-based programming, nor will it introduce event\-based programming
143with libev.
144.PP
145Familiarity with event based programming techniques in general is assumed
146throughout this document.
147.SH "WHAT TO READ WHEN IN A HURRY"
148.IX Header "WHAT TO READ WHEN IN A HURRY"
149This manual tries to be very detailed, but unfortunately, this also makes
150it very long. If you just want to know the basics of libev, I suggest
151reading "ANATOMY OF A WATCHER", then the "EXAMPLE PROGRAM" above and
152look up the missing functions in "GLOBAL FUNCTIONS" and the \f(CW\*(C`ev_io\*(C'\fR and
153\&\f(CW\*(C`ev_timer\*(C'\fR sections in "WATCHER TYPES".
154.SH "ABOUT LIBEV"
155.IX Header "ABOUT LIBEV"
156Libev is an event loop: you register interest in certain events (such as a
157file descriptor being readable or a timeout occurring), and it will manage
158these event sources and provide your program with events.
159.PP
160To do this, it must take more or less complete control over your process
161(or thread) by executing the \fIevent loop\fR handler, and will then
162communicate events via a callback mechanism.
163.PP
164You register interest in certain events by registering so\-called \fIevent
165watchers\fR, which are relatively small C structures you initialise with the
166details of the event, and then hand it over to libev by \fIstarting\fR the
167watcher.
168.SS FEATURES
169.IX Subsection "FEATURES"
170Libev supports \f(CW\*(C`select\*(C'\fR, \f(CW\*(C`poll\*(C'\fR, the Linux\-specific \f(CW\*(C`epoll\*(C'\fR, the
171BSD\-specific \f(CW\*(C`kqueue\*(C'\fR and the Solaris\-specific event port mechanisms
172for file descriptor events (\f(CW\*(C`ev_io\*(C'\fR), the Linux \f(CW\*(C`inotify\*(C'\fR interface
173(for \f(CW\*(C`ev_stat\*(C'\fR), Linux eventfd/signalfd (for faster and cleaner
174inter\-thread wakeup (\f(CW\*(C`ev_async\*(C'\fR)/signal handling (\f(CW\*(C`ev_signal\*(C'\fR)) relative
175timers (\f(CW\*(C`ev_timer\*(C'\fR), absolute timers with customised rescheduling
176(\f(CW\*(C`ev_periodic\*(C'\fR), synchronous signals (\f(CW\*(C`ev_signal\*(C'\fR), process status
177change events (\f(CW\*(C`ev_child\*(C'\fR), and event watchers dealing with the event
178loop mechanism itself (\f(CW\*(C`ev_idle\*(C'\fR, \f(CW\*(C`ev_embed\*(C'\fR, \f(CW\*(C`ev_prepare\*(C'\fR and
179\&\f(CW\*(C`ev_check\*(C'\fR watchers) as well as file watchers (\f(CW\*(C`ev_stat\*(C'\fR) and even
180limited support for fork events (\f(CW\*(C`ev_fork\*(C'\fR).
181.PP
182It also is quite fast (see this
183benchmark <http://libev.schmorp.de/bench.html> comparing it to libevent
184for example).
185.SS CONVENTIONS
186.IX Subsection "CONVENTIONS"
187Libev is very configurable. In this manual the default (and most common)
188configuration will be described, which supports multiple event loops. For
189more info about various configuration options please have a look at
190\&\fBEMBED\fR section in this manual. If libev was configured without support
191for multiple event loops, then all functions taking an initial argument of
192name \f(CW\*(C`loop\*(C'\fR (which is always of type \f(CW\*(C`struct ev_loop *\*(C'\fR) will not have
193this argument.
194.SS "TIME REPRESENTATION"
195.IX Subsection "TIME REPRESENTATION"
196Libev represents time as a single floating point number, representing
197the (fractional) number of seconds since the (POSIX) epoch (in practice
198somewhere near the beginning of 1970, details are complicated, don\*(Aqt
199ask). This type is called \f(CW\*(C`ev_tstamp\*(C'\fR, which is what you should use
200too. It usually aliases to the \f(CW\*(C`double\*(C'\fR type in C. When you need to do
201any calculations on it, you should treat it as some floating point value.
202.PP
203Unlike the name component \f(CW\*(C`stamp\*(C'\fR might indicate, it is also used for
204time differences (e.g. delays) throughout libev.
205.SH "ERROR HANDLING"
206.IX Header "ERROR HANDLING"
207Libev knows three classes of errors: operating system errors, usage errors
208and internal errors (bugs).
209.PP
210When libev catches an operating system error it cannot handle (for example
211a system call indicating a condition libev cannot fix), it calls the callback
212set via \f(CW\*(C`ev_set_syserr_cb\*(C'\fR, which is supposed to fix the problem or
213abort. The default is to print a diagnostic message and to call \f(CW\*(C`abort
214()\*(C'\fR.
215.PP
216When libev detects a usage error such as a negative timer interval, then
217it will print a diagnostic message and abort (via the \f(CW\*(C`assert\*(C'\fR mechanism,
218so \f(CW\*(C`NDEBUG\*(C'\fR will disable this checking): these are programming errors in
219the libev caller and need to be fixed there.
220.PP
221Libev also has a few internal error\-checking \f(CW\*(C`assert\*(C'\fRions, and also has
222extensive consistency checking code. These do not trigger under normal
223circumstances, as they indicate either a bug in libev or worse.
224.SH "GLOBAL FUNCTIONS"
225.IX Header "GLOBAL FUNCTIONS"
226These functions can be called anytime, even before initialising the
227library in any way.
228.IP "ev_tstamp ev_time ()" 4
229.IX Item "ev_tstamp ev_time ()"
230Returns the current time as libev would use it. Please note that the
231\&\f(CW\*(C`ev_now\*(C'\fR function is usually faster and also often returns the timestamp
232you actually want to know. Also interesting is the combination of
233\&\f(CW\*(C`ev_now_update\*(C'\fR and \f(CW\*(C`ev_now\*(C'\fR.
234.IP "ev_sleep (ev_tstamp interval)" 4
235.IX Item "ev_sleep (ev_tstamp interval)"
236Sleep for the given interval: The current thread will be blocked
237until either it is interrupted or the given time interval has
238passed (approximately \- it might return a bit earlier even if not
239interrupted). Returns immediately if \f(CW\*(C`interval <= 0\*(C'\fR.
240.Sp
241Basically this is a sub\-second\-resolution \f(CW\*(C`sleep ()\*(C'\fR.
242.Sp
243The range of the \f(CW\*(C`interval\*(C'\fR is limited \- libev only guarantees to work
244with sleep times of up to one day (\f(CW\*(C`interval <= 86400\*(C'\fR).
245.IP "int ev_version_major ()" 4
246.IX Item "int ev_version_major ()"
247.PD 0
248.IP "int ev_version_minor ()" 4
249.IX Item "int ev_version_minor ()"
250.PD
251You can find out the major and minor ABI version numbers of the library
252you linked against by calling the functions \f(CW\*(C`ev_version_major\*(C'\fR and
253\&\f(CW\*(C`ev_version_minor\*(C'\fR. If you want, you can compare against the global
254symbols \f(CW\*(C`EV_VERSION_MAJOR\*(C'\fR and \f(CW\*(C`EV_VERSION_MINOR\*(C'\fR, which specify the
255version of the library your program was compiled against.
256.Sp
257These version numbers refer to the ABI version of the library, not the
258release version.
259.Sp
260Usually, it\*(Aqs a good idea to terminate if the major versions mismatch,
261as this indicates an incompatible change. Minor versions are usually
262compatible to older versions, so a larger minor version alone is usually
263not a problem.
264.Sp
265Example: Make sure we haven\*(Aqt accidentally been linked against the wrong
266version (note, however, that this will not detect other ABI mismatches,
267such as LFS or reentrancy).
268.Sp
269.Vb 3
270\& assert (("libev version mismatch",
271\& ev_version_major () == EV_VERSION_MAJOR
272\& && ev_version_minor () >= EV_VERSION_MINOR));
273.Ve
274.IP "unsigned int ev_supported_backends ()" 4
275.IX Item "unsigned int ev_supported_backends ()"
276Return the set of all backends (i.e. their corresponding \f(CW\*(C`EV_BACKEND_*\*(C'\fR
277value) compiled into this binary of libev (independent of their
278availability on the system you are running on). See \f(CW\*(C`ev_default_loop\*(C'\fR for
279a description of the set values.
280.Sp
281Example: make sure we have the epoll method, because yeah this is cool and
282a must have and can we have a torrent of it please!!!11
283.Sp
284.Vb 2
285\& assert (("sorry, no epoll, no sex",
286\& ev_supported_backends () & EVBACKEND_EPOLL));
287.Ve
288.IP "unsigned int ev_recommended_backends ()" 4
289.IX Item "unsigned int ev_recommended_backends ()"
290Return the set of all backends compiled into this binary of libev and
291also recommended for this platform, meaning it will work for most file
292descriptor types. This set is often smaller than the one returned by
293\&\f(CW\*(C`ev_supported_backends\*(C'\fR, as for example kqueue is broken on most BSDs
294and will not be auto\-detected unless you explicitly request it (assuming
295you know what you are doing). This is the set of backends that libev will
296probe for if you specify no backends explicitly.
297.IP "unsigned int ev_embeddable_backends ()" 4
298.IX Item "unsigned int ev_embeddable_backends ()"
299Returns the set of backends that are embeddable in other event loops. This
300value is platform\-specific but can include backends not available on the
301current system. To find which embeddable backends might be supported on
302the current system, you would need to look at \f(CW\*(C`ev_embeddable_backends ()
303& ev_supported_backends ()\*(C'\fR, likewise for recommended ones.
304.Sp
305See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info.
306.IP "ev_set_allocator (void *(*cb)(void *ptr, long size) throw ())" 4
307.IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size) throw ())"
308Sets the allocation function to use (the prototype is similar \- the
309semantics are identical to the \f(CW\*(C`realloc\*(C'\fR C89/SuS/POSIX function). It is
310used to allocate and free memory (no surprises here). If it returns zero
311when memory needs to be allocated (\f(CW\*(C`size != 0\*(C'\fR), the library might abort
312or take some potentially destructive action.
313.Sp
314Since some systems (at least OpenBSD and Darwin) fail to implement
315correct \f(CW\*(C`realloc\*(C'\fR semantics, libev will use a wrapper around the system
316\&\f(CW\*(C`realloc\*(C'\fR and \f(CW\*(C`free\*(C'\fR functions by default.
317.Sp
318You could override this function in high\-availability programs to, say,
319free some memory if it cannot allocate memory, to use a special allocator,
320or even to sleep a while and retry until some memory is available.
321.Sp
322Example: Replace the libev allocator with one that waits a bit and then
323retries (example requires a standards\-compliant \f(CW\*(C`realloc\*(C'\fR).
324.Sp
325.Vb 6
326\& static void *
327\& persistent_realloc (void *ptr, size_t size)
328\& {
329\& for (;;)
330\& {
331\& void *newptr = realloc (ptr, size);
332\&
333\& if (newptr)
334\& return newptr;
335\&
336\& sleep (60);
337\& }
338\& }
339\&
340\& ...
341\& ev_set_allocator (persistent_realloc);
342.Ve
343.IP "ev_set_syserr_cb (void (*cb)(const char *msg) throw ())" 4
344.IX Item "ev_set_syserr_cb (void (*cb)(const char *msg) throw ())"
345Set the callback function to call on a retryable system call error (such
346as failed select, poll, epoll_wait). The message is a printable string
347indicating the system call or subsystem causing the problem. If this
348callback is set, then libev will expect it to remedy the situation, no
349matter what, when it returns. That is, libev will generally retry the
350requested operation, or, if the condition doesn\*(Aqt go away, do bad stuff
351(such as abort).
352.Sp
353Example: This is basically the same thing that libev does internally, too.
354.Sp
355.Vb 6
356\& static void
357\& fatal_error (const char *msg)
358\& {
359\& perror (msg);
360\& abort ();
361\& }
362\&
363\& ...
364\& ev_set_syserr_cb (fatal_error);
365.Ve
366.IP "ev_feed_signal (int signum)" 4
367.IX Item "ev_feed_signal (int signum)"
368This function can be used to "simulate" a signal receive. It is completely
369safe to call this function at any time, from any context, including signal
370handlers or random threads.
371.Sp
372Its main use is to customise signal handling in your process, especially
373in the presence of threads. For example, you could block signals
374by default in all threads (and specifying \f(CW\*(C`EVFLAG_NOSIGMASK\*(C'\fR when
375creating any loops), and in one thread, use \f(CW\*(C`sigwait\*(C'\fR or any other
376mechanism to wait for signals, then "deliver" them to libev by calling
377\&\f(CW\*(C`ev_feed_signal\*(C'\fR.
378.SH "FUNCTIONS CONTROLLING EVENT LOOPS"
379.IX Header "FUNCTIONS CONTROLLING EVENT LOOPS"
380An event loop is described by a \f(CW\*(C`struct ev_loop *\*(C'\fR (the \f(CW\*(C`struct\*(C'\fR is
381\&\fInot\fR optional in this case unless libev 3 compatibility is disabled, as
382libev 3 had an \f(CW\*(C`ev_loop\*(C'\fR function colliding with the struct name).
383.PP
384The library knows two types of such loops, the \fIdefault\fR loop, which
385supports child process events, and dynamically created event loops which
386do not.
387.IP "struct ev_loop *ev_default_loop (unsigned int flags)" 4
388.IX Item "struct ev_loop *ev_default_loop (unsigned int flags)"
389This returns the "default" event loop object, which is what you should
390normally use when you just need "the event loop". Event loop objects and
391the \f(CW\*(C`flags\*(C'\fR parameter are described in more detail in the entry for
392\&\f(CW\*(C`ev_loop_new\*(C'\fR.
393.Sp
394If the default loop is already initialised then this function simply
395returns it (and ignores the flags. If that is troubling you, check
396\&\f(CW\*(C`ev_backend ()\*(C'\fR afterwards). Otherwise it will create it with the given
397flags, which should almost always be \f(CW0\fR, unless the caller is also the
398one calling \f(CW\*(C`ev_run\*(C'\fR or otherwise qualifies as "the main program".
399.Sp
400If you don\*(Aqt know what event loop to use, use the one returned from this
401function (or via the \f(CW\*(C`EV_DEFAULT\*(C'\fR macro).
402.Sp
403Note that this function is \fInot\fR thread\-safe, so if you want to use it
404from multiple threads, you have to employ some kind of mutex (note also
405that this case is unlikely, as loops cannot be shared easily between
406threads anyway).
407.Sp
408The default loop is the only loop that can handle \f(CW\*(C`ev_child\*(C'\fR watchers,
409and to do this, it always registers a handler for \f(CW\*(C`SIGCHLD\*(C'\fR. If this is
410a problem for your application you can either create a dynamic loop with
411\&\f(CW\*(C`ev_loop_new\*(C'\fR which doesn\*(Aqt do that, or you can simply overwrite the
412\&\f(CW\*(C`SIGCHLD\*(C'\fR signal handler \fIafter\fR calling \f(CW\*(C`ev_default_init\*(C'\fR.
413.Sp
414Example: This is the most typical usage.
415.Sp
416.Vb 2
417\& if (!ev_default_loop (0))
418\& fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?");
419.Ve
420.Sp
421Example: Restrict libev to the select and poll backends, and do not allow
422environment settings to be taken into account:
423.Sp
424.Vb 1
425\& ev_default_loop (EVBACKEND_POLL | EVBACKEND_SELECT | EVFLAG_NOENV);
426.Ve
427.IP "struct ev_loop *ev_loop_new (unsigned int flags)" 4
428.IX Item "struct ev_loop *ev_loop_new (unsigned int flags)"
429This will create and initialise a new event loop object. If the loop
430could not be initialised, returns false.
431.Sp
432This function is thread\-safe, and one common way to use libev with
433threads is indeed to create one loop per thread, and using the default
434loop in the "main" or "initial" thread.
435.Sp
436The flags argument can be used to specify special behaviour or specific
437backends to use, and is usually specified as \f(CW0\fR (or \f(CW\*(C`EVFLAG_AUTO\*(C'\fR).
438.Sp
439The following flags are supported:
440.RS 4
441.ie n .IP """EVFLAG_AUTO""" 4
442.el .IP \f(CWEVFLAG_AUTO\fR 4
443.IX Item "EVFLAG_AUTO"
444The default flags value. Use this if you have no clue (it\*(Aqs the right
445thing, believe me).
446.ie n .IP """EVFLAG_NOENV""" 4
447.el .IP \f(CWEVFLAG_NOENV\fR 4
448.IX Item "EVFLAG_NOENV"
449If this flag bit is or\*(Aqed into the flag value (or the program runs setuid
450or setgid) then libev will \fInot\fR look at the environment variable
451\&\f(CW\*(C`LIBEV_FLAGS\*(C'\fR. Otherwise (the default), this environment variable will
452override the flags completely if it is found in the environment. This is
453useful to try out specific backends to test their performance, to work
454around bugs, or to make libev threadsafe (accessing environment variables
455cannot be done in a threadsafe way, but usually it works if no other
456thread modifies them).
457.ie n .IP """EVFLAG_FORKCHECK""" 4
458.el .IP \f(CWEVFLAG_FORKCHECK\fR 4
459.IX Item "EVFLAG_FORKCHECK"
460Instead of calling \f(CW\*(C`ev_loop_fork\*(C'\fR manually after a fork, you can also
461make libev check for a fork in each iteration by enabling this flag.
462.Sp
463This works by calling \f(CW\*(C`getpid ()\*(C'\fR on every iteration of the loop,
464and thus this might slow down your event loop if you do a lot of loop
465iterations and little real work, but is usually not noticeable (on my
466GNU/Linux system for example, \f(CW\*(C`getpid\*(C'\fR is actually a simple 5\-insn sequence
467without a system call and thus \fIvery\fR fast, but my GNU/Linux system also has
468\&\f(CW\*(C`pthread_atfork\*(C'\fR which is even faster).
469.Sp
470The big advantage of this flag is that you can forget about fork (and
471forget about forgetting to tell libev about forking, although you still
472have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR) when you use this flag.
473.Sp
474This flag setting cannot be overridden or specified in the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR
475environment variable.
476.ie n .IP """EVFLAG_NOINOTIFY""" 4
477.el .IP \f(CWEVFLAG_NOINOTIFY\fR 4
478.IX Item "EVFLAG_NOINOTIFY"
479When this flag is specified, then libev will not attempt to use the
480\&\fIinotify\fR API for its \f(CW\*(C`ev_stat\*(C'\fR watchers. Apart from debugging and
481testing, this flag can be useful to conserve inotify file descriptors, as
482otherwise each loop using \f(CW\*(C`ev_stat\*(C'\fR watchers consumes one inotify handle.
483.ie n .IP """EVFLAG_SIGNALFD""" 4
484.el .IP \f(CWEVFLAG_SIGNALFD\fR 4
485.IX Item "EVFLAG_SIGNALFD"
486When this flag is specified, then libev will attempt to use the
487\&\fIsignalfd\fR API for its \f(CW\*(C`ev_signal\*(C'\fR (and \f(CW\*(C`ev_child\*(C'\fR) watchers. This API
488delivers signals synchronously, which makes it both faster and might make
489it possible to get the queued signal data. It can also simplify signal
490handling with threads, as long as you properly block signals in your
491threads that are not interested in handling them.
492.Sp
493Signalfd will not be used by default as this changes your signal mask, and
494there are a lot of shoddy libraries and programs (glib\*(Aqs threadpool for
495example) that can\*(Aqt properly initialise their signal masks.
496.ie n .IP """EVFLAG_NOSIGMASK""" 4
497.el .IP \f(CWEVFLAG_NOSIGMASK\fR 4
498.IX Item "EVFLAG_NOSIGMASK"
499When this flag is specified, then libev will avoid to modify the signal
500mask. Specifically, this means you have to make sure signals are unblocked
501when you want to receive them.
502.Sp
503This behaviour is useful when you want to do your own signal handling, or
504want to handle signals only in specific threads and want to avoid libev
505unblocking the signals.
506.Sp
507It\*(Aqs also required by POSIX in a threaded program, as libev calls
508\&\f(CW\*(C`sigprocmask\*(C'\fR, whose behaviour is officially unspecified.
509.Sp
510This flag\*(Aqs behaviour will become the default in future versions of libev.
511.ie n .IP """EVBACKEND_SELECT"" (value 1, portable select backend)" 4
512.el .IP "\f(CWEVBACKEND_SELECT\fR (value 1, portable select backend)" 4
513.IX Item "EVBACKEND_SELECT (value 1, portable select backend)"
514This is your standard \fBselect\fR\|(2) backend. Not \fIcompletely\fR standard, as
515libev tries to roll its own fd_set with no limits on the number of fds,
516but if that fails, expect a fairly low limit on the number of fds when
517using this backend. It doesn\*(Aqt scale too well (O(highest_fd)), but its
518usually the fastest backend for a low number of (low\-numbered :) fds.
519.Sp
520To get good performance out of this backend you need a high amount of
521parallelism (most of the file descriptors should be busy). If you are
522writing a server, you should \f(CW\*(C`accept ()\*(C'\fR in a loop to accept as many
523connections as possible during one iteration. You might also want to have
524a look at \f(CW\*(C`ev_set_io_collect_interval ()\*(C'\fR to increase the amount of
525readiness notifications you get per iteration.
526.Sp
527This backend maps \f(CW\*(C`EV_READ\*(C'\fR to the \f(CW\*(C`readfds\*(C'\fR set and \f(CW\*(C`EV_WRITE\*(C'\fR to the
528\&\f(CW\*(C`writefds\*(C'\fR set (and to work around Microsoft Windows bugs, also onto the
529\&\f(CW\*(C`exceptfds\*(C'\fR set on that platform).
530.ie n .IP """EVBACKEND_POLL"" (value 2, poll backend, available everywhere except on windows)" 4
531.el .IP "\f(CWEVBACKEND_POLL\fR (value 2, poll backend, available everywhere except on windows)" 4
532.IX Item "EVBACKEND_POLL (value 2, poll backend, available everywhere except on windows)"
533And this is your standard \fBpoll\fR\|(2) backend. It\*(Aqs more complicated
534than select, but handles sparse fds better and has no artificial
535limit on the number of fds you can use (except it will slow down
536considerably with a lot of inactive fds). It scales similarly to select,
537i.e. O(total_fds). See the entry for \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR, above, for
538performance tips.
539.Sp
540This backend maps \f(CW\*(C`EV_READ\*(C'\fR to \f(CW\*(C`POLLIN | POLLERR | POLLHUP\*(C'\fR, and
541\&\f(CW\*(C`EV_WRITE\*(C'\fR to \f(CW\*(C`POLLOUT | POLLERR | POLLHUP\*(C'\fR.
542.ie n .IP """EVBACKEND_EPOLL"" (value 4, Linux)" 4
543.el .IP "\f(CWEVBACKEND_EPOLL\fR (value 4, Linux)" 4
544.IX Item "EVBACKEND_EPOLL (value 4, Linux)"
545Use the linux\-specific \fBepoll\fR\|(7) interface (for both pre\- and post\-2.6.9
546kernels).
547.Sp
548For few fds, this backend is a bit little slower than poll and select, but
549it scales phenomenally better. While poll and select usually scale like
550O(total_fds) where total_fds is the total number of fds (or the highest
551fd), epoll scales either O(1) or O(active_fds).
552.Sp
553The epoll mechanism deserves honorable mention as the most misdesigned
554of the more advanced event mechanisms: mere annoyances include silently
555dropping file descriptors, requiring a system call per change per file
556descriptor (and unnecessary guessing of parameters), problems with dup,
557returning before the timeout value, resulting in additional iterations
558(and only giving 5ms accuracy while select on the same platform gives
5590.1ms) and so on. The biggest issue is fork races, however \- if a program
560forks then \fIboth\fR parent and child process have to recreate the epoll
561set, which can take considerable time (one syscall per file descriptor)
562and is of course hard to detect.
563.Sp
564Epoll is also notoriously buggy \- embedding epoll fds \fIshould\fR work,
565but of course \fIdoesn\*(Aqt\fR, and epoll just loves to report events for
566totally \fIdifferent\fR file descriptors (even already closed ones, so
567one cannot even remove them from the set) than registered in the set
568(especially on SMP systems). Libev tries to counter these spurious
569notifications by employing an additional generation counter and comparing
570that against the events to filter out spurious ones, recreating the set
571when required. Epoll also erroneously rounds down timeouts, but gives you
572no way to know when and by how much, so sometimes you have to busy\-wait
573because epoll returns immediately despite a nonzero timeout. And last
574not least, it also refuses to work with some file descriptors which work
575perfectly fine with \f(CW\*(C`select\*(C'\fR (files, many character devices...).
576.Sp
577Epoll is truly the train wreck among event poll mechanisms, a frankenpoll,
578cobbled together in a hurry, no thought to design or interaction with
579others. Oh, the pain, will it ever stop...
580.Sp
581While stopping, setting and starting an I/O watcher in the same iteration
582will result in some caching, there is still a system call per such
583incident (because the same \fIfile descriptor\fR could point to a different
584\&\fIfile description\fR now), so its best to avoid that. Also, \f(CW\*(C`dup ()\*(C'\fR\*(Aqed
585file descriptors might not work very well if you register events for both
586file descriptors.
587.Sp
588Best performance from this backend is achieved by not unregistering all
589watchers for a file descriptor until it has been closed, if possible,
590i.e. keep at least one watcher active per fd at all times. Stopping and
591starting a watcher (without re\-setting it) also usually doesn\*(Aqt cause
592extra overhead. A fork can both result in spurious notifications as well
593as in libev having to destroy and recreate the epoll object, which can
594take considerable time and thus should be avoided.
595.Sp
596All this means that, in practice, \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR can be as fast or
597faster than epoll for maybe up to a hundred file descriptors, depending on
598the usage. So sad.
599.Sp
600While nominally embeddable in other event loops, this feature is broken in
601all kernel versions tested so far.
602.Sp
603This backend maps \f(CW\*(C`EV_READ\*(C'\fR and \f(CW\*(C`EV_WRITE\*(C'\fR in the same way as
604\&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR.
605.ie n .IP """EVBACKEND_KQUEUE"" (value 8, most BSD clones)" 4
606.el .IP "\f(CWEVBACKEND_KQUEUE\fR (value 8, most BSD clones)" 4
607.IX Item "EVBACKEND_KQUEUE (value 8, most BSD clones)"
608Kqueue deserves special mention, as at the time of this writing, it
609was broken on all BSDs except NetBSD (usually it doesn\*(Aqt work reliably
610with anything but sockets and pipes, except on Darwin, where of course
611it\*(Aqs completely useless). Unlike epoll, however, whose brokenness
612is by design, these kqueue bugs can (and eventually will) be fixed
613without API changes to existing programs. For this reason it\*(Aqs not being
614"auto\-detected" unless you explicitly specify it in the flags (i.e. using
615\&\f(CW\*(C`EVBACKEND_KQUEUE\*(C'\fR) or libev was compiled on a known\-to\-be\-good (\-enough)
616system like NetBSD.
617.Sp
618You still can embed kqueue into a normal poll or select backend and use it
619only for sockets (after having made sure that sockets work with kqueue on
620the target platform). See \f(CW\*(C`ev_embed\*(C'\fR watchers for more info.
621.Sp
622It scales in the same way as the epoll backend, but the interface to the
623kernel is more efficient (which says nothing about its actual speed, of
624course). While stopping, setting and starting an I/O watcher does never
625cause an extra system call as with \f(CW\*(C`EVBACKEND_EPOLL\*(C'\fR, it still adds up to
626two event changes per incident. Support for \f(CW\*(C`fork ()\*(C'\fR is very bad (you
627might have to leak fd\*(Aqs on fork, but it\*(Aqs more sane than epoll) and it
628drops fds silently in similarly hard\-to\-detect cases.
629.Sp
630This backend usually performs well under most conditions.
631.Sp
632While nominally embeddable in other event loops, this doesn\*(Aqt work
633everywhere, so you might need to test for this. And since it is broken
634almost everywhere, you should only use it when you have a lot of sockets
635(for which it usually works), by embedding it into another event loop
636(e.g. \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR (but \f(CW\*(C`poll\*(C'\fR is of course
637also broken on OS X)) and, did I mention it, using it only for sockets.
638.Sp
639This backend maps \f(CW\*(C`EV_READ\*(C'\fR into an \f(CW\*(C`EVFILT_READ\*(C'\fR kevent with
640\&\f(CW\*(C`NOTE_EOF\*(C'\fR, and \f(CW\*(C`EV_WRITE\*(C'\fR into an \f(CW\*(C`EVFILT_WRITE\*(C'\fR kevent with
641\&\f(CW\*(C`NOTE_EOF\*(C'\fR.
642.ie n .IP """EVBACKEND_DEVPOLL"" (value 16, Solaris 8)" 4
643.el .IP "\f(CWEVBACKEND_DEVPOLL\fR (value 16, Solaris 8)" 4
644.IX Item "EVBACKEND_DEVPOLL (value 16, Solaris 8)"
645This is not implemented yet (and might never be, unless you send me an
646implementation). According to reports, \f(CW\*(C`/dev/poll\*(C'\fR only supports sockets
647and is not embeddable, which would limit the usefulness of this backend
648immensely.
649.ie n .IP """EVBACKEND_PORT"" (value 32, Solaris 10)" 4
650.el .IP "\f(CWEVBACKEND_PORT\fR (value 32, Solaris 10)" 4
651.IX Item "EVBACKEND_PORT (value 32, Solaris 10)"
652This uses the Solaris 10 event port mechanism. As with everything on Solaris,
653it\*(Aqs really slow, but it still scales very well (O(active_fds)).
654.Sp
655While this backend scales well, it requires one system call per active
656file descriptor per loop iteration. For small and medium numbers of file
657descriptors a "slow" \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR backend
658might perform better.
659.Sp
660On the positive side, this backend actually performed fully to
661specification in all tests and is fully embeddable, which is a rare feat
662among the OS\-specific backends (I vastly prefer correctness over speed
663hacks).
664.Sp
665On the negative side, the interface is \fIbizarre\fR \- so bizarre that
666even sun itself gets it wrong in their code examples: The event polling
667function sometimes returns events to the caller even though an error
668occurred, but with no indication whether it has done so or not (yes, it\*(Aqs
669even documented that way) \- deadly for edge\-triggered interfaces where you
670absolutely have to know whether an event occurred or not because you have
671to re\-arm the watcher.
672.Sp
673Fortunately libev seems to be able to work around these idiocies.
674.Sp
675This backend maps \f(CW\*(C`EV_READ\*(C'\fR and \f(CW\*(C`EV_WRITE\*(C'\fR in the same way as
676\&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR.
677.ie n .IP """EVBACKEND_ALL""" 4
678.el .IP \f(CWEVBACKEND_ALL\fR 4
679.IX Item "EVBACKEND_ALL"
680Try all backends (even potentially broken ones that wouldn\*(Aqt be tried
681with \f(CW\*(C`EVFLAG_AUTO\*(C'\fR). Since this is a mask, you can do stuff such as
682\&\f(CW\*(C`EVBACKEND_ALL & ~EVBACKEND_KQUEUE\*(C'\fR.
683.Sp
684It is definitely not recommended to use this flag, use whatever
685\&\f(CW\*(C`ev_recommended_backends ()\*(C'\fR returns, or simply do not specify a backend
686at all.
687.ie n .IP """EVBACKEND_MASK""" 4
688.el .IP \f(CWEVBACKEND_MASK\fR 4
689.IX Item "EVBACKEND_MASK"
690Not a backend at all, but a mask to select all backend bits from a
691\&\f(CW\*(C`flags\*(C'\fR value, in case you want to mask out any backends from a flags
692value (e.g. when modifying the \f(CW\*(C`LIBEV_FLAGS\*(C'\fR environment variable).
693.RE
694.RS 4
695.Sp
696If one or more of the backend flags are or\*(Aqed into the flags value,
697then only these backends will be tried (in the reverse order as listed
698here). If none are specified, all backends in \f(CW\*(C`ev_recommended_backends
699()\*(C'\fR will be tried.
700.Sp
701Example: Try to create a event loop that uses epoll and nothing else.
702.Sp
703.Vb 3
704\& struct ev_loop *epoller = ev_loop_new (EVBACKEND_EPOLL | EVFLAG_NOENV);
705\& if (!epoller)
706\& fatal ("no epoll found here, maybe it hides under your chair");
707.Ve
708.Sp
709Example: Use whatever libev has to offer, but make sure that kqueue is
710used if available.
711.Sp
712.Vb 1
713\& struct ev_loop *loop = ev_loop_new (ev_recommended_backends () | EVBACKEND_KQUEUE);
714.Ve
715.RE
716.IP "ev_loop_destroy (loop)" 4
717.IX Item "ev_loop_destroy (loop)"
718Destroys an event loop object (frees all memory and kernel state
719etc.). None of the active event watchers will be stopped in the normal
720sense, so e.g. \f(CW\*(C`ev_is_active\*(C'\fR might still return true. It is your
721responsibility to either stop all watchers cleanly yourself \fIbefore\fR
722calling this function, or cope with the fact afterwards (which is usually
723the easiest thing, you can just ignore the watchers and/or \f(CW\*(C`free ()\*(C'\fR them
724for example).
725.Sp
726Note that certain global state, such as signal state (and installed signal
727handlers), will not be freed by this function, and related watchers (such
728as signal and child watchers) would need to be stopped manually.
729.Sp
730This function is normally used on loop objects allocated by
731\&\f(CW\*(C`ev_loop_new\*(C'\fR, but it can also be used on the default loop returned by
732\&\f(CW\*(C`ev_default_loop\*(C'\fR, in which case it is not thread\-safe.
733.Sp
734Note that it is not advisable to call this function on the default loop
735except in the rare occasion where you really need to free its resources.
736If you need dynamically allocated loops it is better to use \f(CW\*(C`ev_loop_new\*(C'\fR
737and \f(CW\*(C`ev_loop_destroy\*(C'\fR.
738.IP "ev_loop_fork (loop)" 4
739.IX Item "ev_loop_fork (loop)"
740This function sets a flag that causes subsequent \f(CW\*(C`ev_run\*(C'\fR iterations
741to reinitialise the kernel state for backends that have one. Despite
742the name, you can call it anytime you are allowed to start or stop
743watchers (except inside an \f(CW\*(C`ev_prepare\*(C'\fR callback), but it makes most
744sense after forking, in the child process. You \fImust\fR call it (or use
745\&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR) in the child before resuming or calling \f(CW\*(C`ev_run\*(C'\fR.
746.Sp
747In addition, if you want to reuse a loop (via this function or
748\&\f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR), you \fIalso\fR have to ignore \f(CW\*(C`SIGPIPE\*(C'\fR.
749.Sp
750Again, you \fIhave\fR to call it on \fIany\fR loop that you want to re\-use after
751a fork, \fIeven if you do not plan to use the loop in the parent\fR. This is
752because some kernel interfaces *cough* \fIkqueue\fR *cough* do funny things
753during fork.
754.Sp
755On the other hand, you only need to call this function in the child
756process if and only if you want to use the event loop in the child. If
757you just fork+exec or create a new loop in the child, you don\*(Aqt have to
758call it at all (in fact, \f(CW\*(C`epoll\*(C'\fR is so badly broken that it makes a
759difference, but libev will usually detect this case on its own and do a
760costly reset of the backend).
761.Sp
762The function itself is quite fast and it\*(Aqs usually not a problem to call
763it just in case after a fork.
764.Sp
765Example: Automate calling \f(CW\*(C`ev_loop_fork\*(C'\fR on the default loop when
766using pthreads.
767.Sp
768.Vb 5
769\& static void
770\& post_fork_child (void)
771\& {
772\& ev_loop_fork (EV_DEFAULT);
773\& }
774\&
775\& ...
776\& pthread_atfork (0, 0, post_fork_child);
777.Ve
778.IP "int ev_is_default_loop (loop)" 4
779.IX Item "int ev_is_default_loop (loop)"
780Returns true when the given loop is, in fact, the default loop, and false
781otherwise.
782.IP "unsigned int ev_iteration (loop)" 4
783.IX Item "unsigned int ev_iteration (loop)"
784Returns the current iteration count for the event loop, which is identical
785to the number of times libev did poll for new events. It starts at \f(CW0\fR
786and happily wraps around with enough iterations.
787.Sp
788This value can sometimes be useful as a generation counter of sorts (it
789"ticks" the number of loop iterations), as it roughly corresponds with
790\&\f(CW\*(C`ev_prepare\*(C'\fR and \f(CW\*(C`ev_check\*(C'\fR calls \- and is incremented between the
791prepare and check phases.
792.IP "unsigned int ev_depth (loop)" 4
793.IX Item "unsigned int ev_depth (loop)"
794Returns the number of times \f(CW\*(C`ev_run\*(C'\fR was entered minus the number of
795times \f(CW\*(C`ev_run\*(C'\fR was exited normally, in other words, the recursion depth.
796.Sp
797Outside \f(CW\*(C`ev_run\*(C'\fR, this number is zero. In a callback, this number is
798\&\f(CW1\fR, unless \f(CW\*(C`ev_run\*(C'\fR was invoked recursively (or from another thread),
799in which case it is higher.
800.Sp
801Leaving \f(CW\*(C`ev_run\*(C'\fR abnormally (setjmp/longjmp, cancelling the thread,
802throwing an exception etc.), doesn\*(Aqt count as "exit" \- consider this
803as a hint to avoid such ungentleman\-like behaviour unless it\*(Aqs really
804convenient, in which case it is fully supported.
805.IP "unsigned int ev_backend (loop)" 4
806.IX Item "unsigned int ev_backend (loop)"
807Returns one of the \f(CW\*(C`EVBACKEND_*\*(C'\fR flags indicating the event backend in
808use.
809.IP "ev_tstamp ev_now (loop)" 4
810.IX Item "ev_tstamp ev_now (loop)"
811Returns the current "event loop time", which is the time the event loop
812received events and started processing them. This timestamp does not
813change as long as callbacks are being processed, and this is also the base
814time used for relative timers. You can treat it as the timestamp of the
815event occurring (or more correctly, libev finding out about it).
816.IP "ev_now_update (loop)" 4
817.IX Item "ev_now_update (loop)"
818Establishes the current time by querying the kernel, updating the time
819returned by \f(CW\*(C`ev_now ()\*(C'\fR in the progress. This is a costly operation and
820is usually done automatically within \f(CW\*(C`ev_run ()\*(C'\fR.
821.Sp
822This function is rarely useful, but when some event callback runs for a
823very long time without entering the event loop, updating libev\*(Aqs idea of
824the current time is a good idea.
825.Sp
826See also "The special problem of time updates" in the \f(CW\*(C`ev_timer\*(C'\fR section.
827.IP "ev_suspend (loop)" 4
828.IX Item "ev_suspend (loop)"
829.PD 0
830.IP "ev_resume (loop)" 4
831.IX Item "ev_resume (loop)"
832.PD
833These two functions suspend and resume an event loop, for use when the
834loop is not used for a while and timeouts should not be processed.
835.Sp
836A typical use case would be an interactive program such as a game: When
837the user presses \f(CW\*(C`^Z\*(C'\fR to suspend the game and resumes it an hour later it
838would be best to handle timeouts as if no time had actually passed while
839the program was suspended. This can be achieved by calling \f(CW\*(C`ev_suspend\*(C'\fR
840in your \f(CW\*(C`SIGTSTP\*(C'\fR handler, sending yourself a \f(CW\*(C`SIGSTOP\*(C'\fR and calling
841\&\f(CW\*(C`ev_resume\*(C'\fR directly afterwards to resume timer processing.
842.Sp
843Effectively, all \f(CW\*(C`ev_timer\*(C'\fR watchers will be delayed by the time spend
844between \f(CW\*(C`ev_suspend\*(C'\fR and \f(CW\*(C`ev_resume\*(C'\fR, and all \f(CW\*(C`ev_periodic\*(C'\fR watchers
845will be rescheduled (that is, they will lose any events that would have
846occurred while suspended).
847.Sp
848After calling \f(CW\*(C`ev_suspend\*(C'\fR you \fBmust not\fR call \fIany\fR function on the
849given loop other than \f(CW\*(C`ev_resume\*(C'\fR, and you \fBmust not\fR call \f(CW\*(C`ev_resume\*(C'\fR
850without a previous call to \f(CW\*(C`ev_suspend\*(C'\fR.
851.Sp
852Calling \f(CW\*(C`ev_suspend\*(C'\fR/\f(CW\*(C`ev_resume\*(C'\fR has the side effect of updating the
853event loop time (see \f(CW\*(C`ev_now_update\*(C'\fR).
854.IP "bool ev_run (loop, int flags)" 4
855.IX Item "bool ev_run (loop, int flags)"
856Finally, this is it, the event handler. This function usually is called
857after you have initialised all your watchers and you want to start
858handling events. It will ask the operating system for any new events, call
859the watcher callbacks, and then repeat the whole process indefinitely: This
860is why event loops are called \fIloops\fR.
861.Sp
862If the flags argument is specified as \f(CW0\fR, it will keep handling events
863until either no event watchers are active anymore or \f(CW\*(C`ev_break\*(C'\fR was
864called.
865.Sp
866The return value is false if there are no more active watchers (which
867usually means "all jobs done" or "deadlock"), and true in all other cases
868(which usually means " you should call \f(CW\*(C`ev_run\*(C'\fR again").
869.Sp
870Please note that an explicit \f(CW\*(C`ev_break\*(C'\fR is usually better than
871relying on all watchers to be stopped when deciding when a program has
872finished (especially in interactive programs), but having a program
873that automatically loops as long as it has to and no longer by virtue
874of relying on its watchers stopping correctly, that is truly a thing of
875beauty.
876.Sp
877This function is \fImostly\fR exception\-safe \- you can break out of a
878\&\f(CW\*(C`ev_run\*(C'\fR call by calling \f(CW\*(C`longjmp\*(C'\fR in a callback, throwing a C++
879exception and so on. This does not decrement the \f(CW\*(C`ev_depth\*(C'\fR value, nor
880will it clear any outstanding \f(CW\*(C`EVBREAK_ONE\*(C'\fR breaks.
881.Sp
882A flags value of \f(CW\*(C`EVRUN_NOWAIT\*(C'\fR will look for new events, will handle
883those events and any already outstanding ones, but will not wait and
884block your process in case there are no events and will return after one
885iteration of the loop. This is sometimes useful to poll and handle new
886events while doing lengthy calculations, to keep the program responsive.
887.Sp
888A flags value of \f(CW\*(C`EVRUN_ONCE\*(C'\fR will look for new events (waiting if
889necessary) and will handle those and any already outstanding ones. It
890will block your process until at least one new event arrives (which could
891be an event internal to libev itself, so there is no guarantee that a
892user\-registered callback will be called), and will return after one
893iteration of the loop.
894.Sp
895This is useful if you are waiting for some external event in conjunction
896with something not expressible using other libev watchers (i.e. "roll your
897own \f(CW\*(C`ev_run\*(C'\fR"). However, a pair of \f(CW\*(C`ev_prepare\*(C'\fR/\f(CW\*(C`ev_check\*(C'\fR watchers is
898usually a better approach for this kind of thing.
899.Sp
900Here are the gory details of what \f(CW\*(C`ev_run\*(C'\fR does (this is for your
901understanding, not a guarantee that things will work exactly like this in
902future versions):
903.Sp
904.Vb 10
905\& \- Increment loop depth.
906\& \- Reset the ev_break status.
907\& \- Before the first iteration, call any pending watchers.
908\& LOOP:
909\& \- If EVFLAG_FORKCHECK was used, check for a fork.
910\& \- If a fork was detected (by any means), queue and call all fork watchers.
911\& \- Queue and call all prepare watchers.
912\& \- If ev_break was called, goto FINISH.
913\& \- If we have been forked, detach and recreate the kernel state
914\& as to not disturb the other process.
915\& \- Update the kernel state with all outstanding changes.
916\& \- Update the "event loop time" (ev_now ()).
917\& \- Calculate for how long to sleep or block, if at all
918\& (active idle watchers, EVRUN_NOWAIT or not having
919\& any active watchers at all will result in not sleeping).
920\& \- Sleep if the I/O and timer collect interval say so.
921\& \- Increment loop iteration counter.
922\& \- Block the process, waiting for any events.
923\& \- Queue all outstanding I/O (fd) events.
924\& \- Update the "event loop time" (ev_now ()), and do time jump adjustments.
925\& \- Queue all expired timers.
926\& \- Queue all expired periodics.
927\& \- Queue all idle watchers with priority higher than that of pending events.
928\& \- Queue all check watchers.
929\& \- Call all queued watchers in reverse order (i.e. check watchers first).
930\& Signals and child watchers are implemented as I/O watchers, and will
931\& be handled here by queueing them when their watcher gets executed.
932\& \- If ev_break has been called, or EVRUN_ONCE or EVRUN_NOWAIT
933\& were used, or there are no active watchers, goto FINISH, otherwise
934\& continue with step LOOP.
935\& FINISH:
936\& \- Reset the ev_break status iff it was EVBREAK_ONE.
937\& \- Decrement the loop depth.
938\& \- Return.
939.Ve
940.Sp
941Example: Queue some jobs and then loop until no events are outstanding
942anymore.
943.Sp
944.Vb 4
945\& ... queue jobs here, make sure they register event watchers as long
946\& ... as they still have work to do (even an idle watcher will do..)
947\& ev_run (my_loop, 0);
948\& ... jobs done or somebody called break. yeah!
949.Ve
950.IP "ev_break (loop, how)" 4
951.IX Item "ev_break (loop, how)"
952Can be used to make a call to \f(CW\*(C`ev_run\*(C'\fR return early (but only after it
953has processed all outstanding events). The \f(CW\*(C`how\*(C'\fR argument must be either
954\&\f(CW\*(C`EVBREAK_ONE\*(C'\fR, which will make the innermost \f(CW\*(C`ev_run\*(C'\fR call return, or
955\&\f(CW\*(C`EVBREAK_ALL\*(C'\fR, which will make all nested \f(CW\*(C`ev_run\*(C'\fR calls return.
956.Sp
957This "break state" will be cleared on the next call to \f(CW\*(C`ev_run\*(C'\fR.
958.Sp
959It is safe to call \f(CW\*(C`ev_break\*(C'\fR from outside any \f(CW\*(C`ev_run\*(C'\fR calls, too, in
960which case it will have no effect.
961.IP "ev_ref (loop)" 4
962.IX Item "ev_ref (loop)"
963.PD 0
964.IP "ev_unref (loop)" 4
965.IX Item "ev_unref (loop)"
966.PD
967Ref/unref can be used to add or remove a reference count on the event
968loop: Every watcher keeps one reference, and as long as the reference
969count is nonzero, \f(CW\*(C`ev_run\*(C'\fR will not return on its own.
970.Sp
971This is useful when you have a watcher that you never intend to
972unregister, but that nevertheless should not keep \f(CW\*(C`ev_run\*(C'\fR from
973returning. In such a case, call \f(CW\*(C`ev_unref\*(C'\fR after starting, and \f(CW\*(C`ev_ref\*(C'\fR
974before stopping it.
975.Sp
976As an example, libev itself uses this for its internal signal pipe: It
977is not visible to the libev user and should not keep \f(CW\*(C`ev_run\*(C'\fR from
978exiting if no event watchers registered by it are active. It is also an
979excellent way to do this for generic recurring timers or from within
980third\-party libraries. Just remember to \fIunref after start\fR and \fIref
981before stop\fR (but only if the watcher wasn\*(Aqt active before, or was active
982before, respectively. Note also that libev might stop watchers itself
983(e.g. non\-repeating timers) in which case you have to \f(CW\*(C`ev_ref\*(C'\fR
984in the callback).
985.Sp
986Example: Create a signal watcher, but keep it from keeping \f(CW\*(C`ev_run\*(C'\fR
987running when nothing else is active.
988.Sp
989.Vb 4
990\& ev_signal exitsig;
991\& ev_signal_init (&exitsig, sig_cb, SIGINT);
992\& ev_signal_start (loop, &exitsig);
993\& ev_unref (loop);
994.Ve
995.Sp
996Example: For some weird reason, unregister the above signal handler again.
997.Sp
998.Vb 2
999\& ev_ref (loop);
1000\& ev_signal_stop (loop, &exitsig);
1001.Ve
1002.IP "ev_set_io_collect_interval (loop, ev_tstamp interval)" 4
1003.IX Item "ev_set_io_collect_interval (loop, ev_tstamp interval)"
1004.PD 0
1005.IP "ev_set_timeout_collect_interval (loop, ev_tstamp interval)" 4
1006.IX Item "ev_set_timeout_collect_interval (loop, ev_tstamp interval)"
1007.PD
1008These advanced functions influence the time that libev will spend waiting
1009for events. Both time intervals are by default \f(CW0\fR, meaning that libev
1010will try to invoke timer/periodic callbacks and I/O callbacks with minimum
1011latency.
1012.Sp
1013Setting these to a higher value (the \f(CW\*(C`interval\*(C'\fR \fImust\fR be >= \f(CW0\fR)
1014allows libev to delay invocation of I/O and timer/periodic callbacks
1015to increase efficiency of loop iterations (or to increase power\-saving
1016opportunities).
1017.Sp
1018The idea is that sometimes your program runs just fast enough to handle
1019one (or very few) event(s) per loop iteration. While this makes the
1020program responsive, it also wastes a lot of CPU time to poll for new
1021events, especially with backends like \f(CW\*(C`select ()\*(C'\fR which have a high
1022overhead for the actual polling but can deliver many events at once.
1023.Sp
1024By setting a higher \fIio collect interval\fR you allow libev to spend more
1025time collecting I/O events, so you can handle more events per iteration,
1026at the cost of increasing latency. Timeouts (both \f(CW\*(C`ev_periodic\*(C'\fR and
1027\&\f(CW\*(C`ev_timer\*(C'\fR) will not be affected. Setting this to a non\-null value will
1028introduce an additional \f(CW\*(C`ev_sleep ()\*(C'\fR call into most loop iterations. The
1029sleep time ensures that libev will not poll for I/O events more often then
1030once per this interval, on average (as long as the host time resolution is
1031good enough).
1032.Sp
1033Likewise, by setting a higher \fItimeout collect interval\fR you allow libev
1034to spend more time collecting timeouts, at the expense of increased
1035latency/jitter/inexactness (the watcher callback will be called
1036later). \f(CW\*(C`ev_io\*(C'\fR watchers will not be affected. Setting this to a non\-null
1037value will not introduce any overhead in libev.
1038.Sp
1039Many (busy) programs can usually benefit by setting the I/O collect
1040interval to a value near \f(CW0.1\fR or so, which is often enough for
1041interactive servers (of course not for games), likewise for timeouts. It
1042usually doesn\*(Aqt make much sense to set it to a lower value than \f(CW0.01\fR,
1043as this approaches the timing granularity of most systems. Note that if
1044you do transactions with the outside world and you can\*(Aqt increase the
1045parallelity, then this setting will limit your transaction rate (if you
1046need to poll once per transaction and the I/O collect interval is 0.01,
1047then you can\*(Aqt do more than 100 transactions per second).
1048.Sp
1049Setting the \fItimeout collect interval\fR can improve the opportunity for
1050saving power, as the program will "bundle" timer callback invocations that
1051are "near" in time together, by delaying some, thus reducing the number of
1052times the process sleeps and wakes up again. Another useful technique to
1053reduce iterations/wake\-ups is to use \f(CW\*(C`ev_periodic\*(C'\fR watchers and make sure
1054they fire on, say, one\-second boundaries only.
1055.Sp
1056Example: we only need 0.1s timeout granularity, and we wish not to poll
1057more often than 100 times per second:
1058.Sp
1059.Vb 2
1060\& ev_set_timeout_collect_interval (EV_DEFAULT_UC_ 0.1);
1061\& ev_set_io_collect_interval (EV_DEFAULT_UC_ 0.01);
1062.Ve
1063.IP "ev_invoke_pending (loop)" 4
1064.IX Item "ev_invoke_pending (loop)"
1065This call will simply invoke all pending watchers while resetting their
1066pending state. Normally, \f(CW\*(C`ev_run\*(C'\fR does this automatically when required,
1067but when overriding the invoke callback this call comes handy. This
1068function can be invoked from a watcher \- this can be useful for example
1069when you want to do some lengthy calculation and want to pass further
1070event handling to another thread (you still have to make sure only one
1071thread executes within \f(CW\*(C`ev_invoke_pending\*(C'\fR or \f(CW\*(C`ev_run\*(C'\fR of course).
1072.IP "int ev_pending_count (loop)" 4
1073.IX Item "int ev_pending_count (loop)"
1074Returns the number of pending watchers \- zero indicates that no watchers
1075are pending.
1076.IP "ev_set_invoke_pending_cb (loop, void (*invoke_pending_cb)(EV_P))" 4
1077.IX Item "ev_set_invoke_pending_cb (loop, void (*invoke_pending_cb)(EV_P))"
1078This overrides the invoke pending functionality of the loop: Instead of
1079invoking all pending watchers when there are any, \f(CW\*(C`ev_run\*(C'\fR will call
1080this callback instead. This is useful, for example, when you want to
1081invoke the actual watchers inside another context (another thread etc.).
1082.Sp
1083If you want to reset the callback, use \f(CW\*(C`ev_invoke_pending\*(C'\fR as new
1084callback.
1085.IP "ev_set_loop_release_cb (loop, void (*release)(EV_P) throw (), void (*acquire)(EV_P) throw ())" 4
1086.IX Item "ev_set_loop_release_cb (loop, void (*release)(EV_P) throw (), void (*acquire)(EV_P) throw ())"
1087Sometimes you want to share the same loop between multiple threads. This
1088can be done relatively simply by putting mutex_lock/unlock calls around
1089each call to a libev function.
1090.Sp
1091However, \f(CW\*(C`ev_run\*(C'\fR can run an indefinite time, so it is not feasible
1092to wait for it to return. One way around this is to wake up the event
1093loop via \f(CW\*(C`ev_break\*(C'\fR and \f(CW\*(C`ev_async_send\*(C'\fR, another way is to set these
1094\&\fIrelease\fR and \fIacquire\fR callbacks on the loop.
1095.Sp
1096When set, then \f(CW\*(C`release\*(C'\fR will be called just before the thread is
1097suspended waiting for new events, and \f(CW\*(C`acquire\*(C'\fR is called just
1098afterwards.
1099.Sp
1100Ideally, \f(CW\*(C`release\*(C'\fR will just call your mutex_unlock function, and
1101\&\f(CW\*(C`acquire\*(C'\fR will just call the mutex_lock function again.
1102.Sp
1103While event loop modifications are allowed between invocations of
1104\&\f(CW\*(C`release\*(C'\fR and \f(CW\*(C`acquire\*(C'\fR (that\*(Aqs their only purpose after all), no
1105modifications done will affect the event loop, i.e. adding watchers will
1106have no effect on the set of file descriptors being watched, or the time
1107waited. Use an \f(CW\*(C`ev_async\*(C'\fR watcher to wake up \f(CW\*(C`ev_run\*(C'\fR when you want it
1108to take note of any changes you made.
1109.Sp
1110In theory, threads executing \f(CW\*(C`ev_run\*(C'\fR will be async\-cancel safe between
1111invocations of \f(CW\*(C`release\*(C'\fR and \f(CW\*(C`acquire\*(C'\fR.
1112.Sp
1113See also the locking example in the \f(CW\*(C`THREADS\*(C'\fR section later in this
1114document.
1115.IP "ev_set_userdata (loop, void *data)" 4
1116.IX Item "ev_set_userdata (loop, void *data)"
1117.PD 0
1118.IP "void *ev_userdata (loop)" 4
1119.IX Item "void *ev_userdata (loop)"
1120.PD
1121Set and retrieve a single \f(CW\*(C`void *\*(C'\fR associated with a loop. When
1122\&\f(CW\*(C`ev_set_userdata\*(C'\fR has never been called, then \f(CW\*(C`ev_userdata\*(C'\fR returns
1123\&\f(CW0\fR.
1124.Sp
1125These two functions can be used to associate arbitrary data with a loop,
1126and are intended solely for the \f(CW\*(C`invoke_pending_cb\*(C'\fR, \f(CW\*(C`release\*(C'\fR and
1127\&\f(CW\*(C`acquire\*(C'\fR callbacks described above, but of course can be (ab\-)used for
1128any other purpose as well.
1129.IP "ev_verify (loop)" 4
1130.IX Item "ev_verify (loop)"
1131This function only does something when \f(CW\*(C`EV_VERIFY\*(C'\fR support has been
1132compiled in, which is the default for non\-minimal builds. It tries to go
1133through all internal structures and checks them for validity. If anything
1134is found to be inconsistent, it will print an error message to standard
1135error and call \f(CW\*(C`abort ()\*(C'\fR.
1136.Sp
1137This can be used to catch bugs inside libev itself: under normal
1138circumstances, this function will never abort as of course libev keeps its
1139data structures consistent.
1140.SH "ANATOMY OF A WATCHER"
1141.IX Header "ANATOMY OF A WATCHER"
1142In the following description, uppercase \f(CW\*(C`TYPE\*(C'\fR in names stands for the
1143watcher type, e.g. \f(CW\*(C`ev_TYPE_start\*(C'\fR can mean \f(CW\*(C`ev_timer_start\*(C'\fR for timer
1144watchers and \f(CW\*(C`ev_io_start\*(C'\fR for I/O watchers.
1145.PP
1146A watcher is an opaque structure that you allocate and register to record
1147your interest in some event. To make a concrete example, imagine you want
1148to wait for STDIN to become readable, you would create an \f(CW\*(C`ev_io\*(C'\fR watcher
1149for that:
1150.PP
1151.Vb 5
1152\& static void my_cb (struct ev_loop *loop, ev_io *w, int revents)
1153\& {
1154\& ev_io_stop (w);
1155\& ev_break (loop, EVBREAK_ALL);
1156\& }
1157\&
1158\& struct ev_loop *loop = ev_default_loop (0);
1159\&
1160\& ev_io stdin_watcher;
1161\&
1162\& ev_init (&stdin_watcher, my_cb);
1163\& ev_io_set (&stdin_watcher, STDIN_FILENO, EV_READ);
1164\& ev_io_start (loop, &stdin_watcher);
1165\&
1166\& ev_run (loop, 0);
1167.Ve
1168.PP
1169As you can see, you are responsible for allocating the memory for your
1170watcher structures (and it is \fIusually\fR a bad idea to do this on the
1171stack).
1172.PP
1173Each watcher has an associated watcher structure (called \f(CW\*(C`struct ev_TYPE\*(C'\fR
1174or simply \f(CW\*(C`ev_TYPE\*(C'\fR, as typedefs are provided for all watcher structs).
1175.PP
1176Each watcher structure must be initialised by a call to \f(CW\*(C`ev_init (watcher
1177*, callback)\*(C'\fR, which expects a callback to be provided. This callback is
1178invoked each time the event occurs (or, in the case of I/O watchers, each
1179time the event loop detects that the file descriptor given is readable
1180and/or writable).
1181.PP
1182Each watcher type further has its own \f(CW\*(C`ev_TYPE_set (watcher *, ...)\*(C'\fR
1183macro to configure it, with arguments specific to the watcher type. There
1184is also a macro to combine initialisation and setting in one call: \f(CW\*(C`ev_TYPE_init (watcher *, callback, ...)\*(C'\fR.
1185.PP
1186To make the watcher actually watch out for events, you have to start it
1187with a watcher\-specific start function (\f(CW\*(C`ev_TYPE_start (loop, watcher
1188*)\*(C'\fR), and you can stop watching for events at any time by calling the
1189corresponding stop function (\f(CW\*(C`ev_TYPE_stop (loop, watcher *)\*(C'\fR.
1190.PP
1191As long as your watcher is active (has been started but not stopped) you
1192must not touch the values stored in it. Most specifically you must never
1193reinitialise it or call its \f(CW\*(C`ev_TYPE_set\*(C'\fR macro.
1194.PP
1195Each and every callback receives the event loop pointer as first, the
1196registered watcher structure as second, and a bitset of received events as
1197third argument.
1198.PP
1199The received events usually include a single bit per event type received
1200(you can receive multiple events at the same time). The possible bit masks
1201are:
1202.ie n .IP """EV_READ""" 4
1203.el .IP \f(CWEV_READ\fR 4
1204.IX Item "EV_READ"
1205.PD 0
1206.ie n .IP """EV_WRITE""" 4
1207.el .IP \f(CWEV_WRITE\fR 4
1208.IX Item "EV_WRITE"
1209.PD
1210The file descriptor in the \f(CW\*(C`ev_io\*(C'\fR watcher has become readable and/or
1211writable.
1212.ie n .IP """EV_TIMER""" 4
1213.el .IP \f(CWEV_TIMER\fR 4
1214.IX Item "EV_TIMER"
1215The \f(CW\*(C`ev_timer\*(C'\fR watcher has timed out.
1216.ie n .IP """EV_PERIODIC""" 4
1217.el .IP \f(CWEV_PERIODIC\fR 4
1218.IX Item "EV_PERIODIC"
1219The \f(CW\*(C`ev_periodic\*(C'\fR watcher has timed out.
1220.ie n .IP """EV_SIGNAL""" 4
1221.el .IP \f(CWEV_SIGNAL\fR 4
1222.IX Item "EV_SIGNAL"
1223The signal specified in the \f(CW\*(C`ev_signal\*(C'\fR watcher has been received by a thread.
1224.ie n .IP """EV_CHILD""" 4
1225.el .IP \f(CWEV_CHILD\fR 4
1226.IX Item "EV_CHILD"
1227The pid specified in the \f(CW\*(C`ev_child\*(C'\fR watcher has received a status change.
1228.ie n .IP """EV_STAT""" 4
1229.el .IP \f(CWEV_STAT\fR 4
1230.IX Item "EV_STAT"
1231The path specified in the \f(CW\*(C`ev_stat\*(C'\fR watcher changed its attributes somehow.
1232.ie n .IP """EV_IDLE""" 4
1233.el .IP \f(CWEV_IDLE\fR 4
1234.IX Item "EV_IDLE"
1235The \f(CW\*(C`ev_idle\*(C'\fR watcher has determined that you have nothing better to do.
1236.ie n .IP """EV_PREPARE""" 4
1237.el .IP \f(CWEV_PREPARE\fR 4
1238.IX Item "EV_PREPARE"
1239.PD 0
1240.ie n .IP """EV_CHECK""" 4
1241.el .IP \f(CWEV_CHECK\fR 4
1242.IX Item "EV_CHECK"
1243.PD
1244All \f(CW\*(C`ev_prepare\*(C'\fR watchers are invoked just \fIbefore\fR \f(CW\*(C`ev_run\*(C'\fR starts to
1245gather new events, and all \f(CW\*(C`ev_check\*(C'\fR watchers are queued (not invoked)
1246just after \f(CW\*(C`ev_run\*(C'\fR has gathered them, but before it queues any callbacks
1247for any received events. That means \f(CW\*(C`ev_prepare\*(C'\fR watchers are the last
1248watchers invoked before the event loop sleeps or polls for new events, and
1249\&\f(CW\*(C`ev_check\*(C'\fR watchers will be invoked before any other watchers of the same
1250or lower priority within an event loop iteration.
1251.Sp
1252Callbacks of both watcher types can start and stop as many watchers as
1253they want, and all of them will be taken into account (for example, a
1254\&\f(CW\*(C`ev_prepare\*(C'\fR watcher might start an idle watcher to keep \f(CW\*(C`ev_run\*(C'\fR from
1255blocking).
1256.ie n .IP """EV_EMBED""" 4
1257.el .IP \f(CWEV_EMBED\fR 4
1258.IX Item "EV_EMBED"
1259The embedded event loop specified in the \f(CW\*(C`ev_embed\*(C'\fR watcher needs attention.
1260.ie n .IP """EV_FORK""" 4
1261.el .IP \f(CWEV_FORK\fR 4
1262.IX Item "EV_FORK"
1263The event loop has been resumed in the child process after fork (see
1264\&\f(CW\*(C`ev_fork\*(C'\fR).
1265.ie n .IP """EV_CLEANUP""" 4
1266.el .IP \f(CWEV_CLEANUP\fR 4
1267.IX Item "EV_CLEANUP"
1268The event loop is about to be destroyed (see \f(CW\*(C`ev_cleanup\*(C'\fR).
1269.ie n .IP """EV_ASYNC""" 4
1270.el .IP \f(CWEV_ASYNC\fR 4
1271.IX Item "EV_ASYNC"
1272The given async watcher has been asynchronously notified (see \f(CW\*(C`ev_async\*(C'\fR).
1273.ie n .IP """EV_CUSTOM""" 4
1274.el .IP \f(CWEV_CUSTOM\fR 4
1275.IX Item "EV_CUSTOM"
1276Not ever sent (or otherwise used) by libev itself, but can be freely used
1277by libev users to signal watchers (e.g. via \f(CW\*(C`ev_feed_event\*(C'\fR).
1278.ie n .IP """EV_ERROR""" 4
1279.el .IP \f(CWEV_ERROR\fR 4
1280.IX Item "EV_ERROR"
1281An unspecified error has occurred, the watcher has been stopped. This might
1282happen because the watcher could not be properly started because libev
1283ran out of memory, a file descriptor was found to be closed or any other
1284problem. Libev considers these application bugs.
1285.Sp
1286You best act on it by reporting the problem and somehow coping with the
1287watcher being stopped. Note that well\-written programs should not receive
1288an error ever, so when your watcher receives it, this usually indicates a
1289bug in your program.
1290.Sp
1291Libev will usually signal a few "dummy" events together with an error, for
1292example it might indicate that a fd is readable or writable, and if your
1293callbacks is well\-written it can just attempt the operation and cope with
1294the error from \fBread()\fR or \fBwrite()\fR. This will not work in multi\-threaded
1295programs, though, as the fd could already be closed and reused for another
1296thing, so beware.
1297.SS "GENERIC WATCHER FUNCTIONS"
1298.IX Subsection "GENERIC WATCHER FUNCTIONS"
1299.ie n .IP """ev_init"" (ev_TYPE *watcher, callback)" 4
1300.el .IP "\f(CWev_init\fR (ev_TYPE *watcher, callback)" 4
1301.IX Item "ev_init (ev_TYPE *watcher, callback)"
1302This macro initialises the generic portion of a watcher. The contents
1303of the watcher object can be arbitrary (so \f(CW\*(C`malloc\*(C'\fR will do). Only
1304the generic parts of the watcher are initialised, you \fIneed\fR to call
1305the type\-specific \f(CW\*(C`ev_TYPE_set\*(C'\fR macro afterwards to initialise the
1306type\-specific parts. For each type there is also a \f(CW\*(C`ev_TYPE_init\*(C'\fR macro
1307which rolls both calls into one.
1308.Sp
1309You can reinitialise a watcher at any time as long as it has been stopped
1310(or never started) and there are no pending events outstanding.
1311.Sp
1312The callback is always of type \f(CW\*(C`void (*)(struct ev_loop *loop, ev_TYPE *watcher,
1313int revents)\*(C'\fR.
1314.Sp
1315Example: Initialise an \f(CW\*(C`ev_io\*(C'\fR watcher in two steps.
1316.Sp
1317.Vb 3
1318\& ev_io w;
1319\& ev_init (&w, my_cb);
1320\& ev_io_set (&w, STDIN_FILENO, EV_READ);
1321.Ve
1322.ie n .IP """ev_TYPE_set"" (ev_TYPE *watcher, [args])" 4
1323.el .IP "\f(CWev_TYPE_set\fR (ev_TYPE *watcher, [args])" 4
1324.IX Item "ev_TYPE_set (ev_TYPE *watcher, [args])"
1325This macro initialises the type\-specific parts of a watcher. You need to
1326call \f(CW\*(C`ev_init\*(C'\fR at least once before you call this macro, but you can
1327call \f(CW\*(C`ev_TYPE_set\*(C'\fR any number of times. You must not, however, call this
1328macro on a watcher that is active (it can be pending, however, which is a
1329difference to the \f(CW\*(C`ev_init\*(C'\fR macro).
1330.Sp
1331Although some watcher types do not have type\-specific arguments
1332(e.g. \f(CW\*(C`ev_prepare\*(C'\fR) you still need to call its \f(CW\*(C`set\*(C'\fR macro.
1333.Sp
1334See \f(CW\*(C`ev_init\*(C'\fR, above, for an example.
1335.ie n .IP """ev_TYPE_init"" (ev_TYPE *watcher, callback, [args])" 4
1336.el .IP "\f(CWev_TYPE_init\fR (ev_TYPE *watcher, callback, [args])" 4
1337.IX Item "ev_TYPE_init (ev_TYPE *watcher, callback, [args])"
1338This convenience macro rolls both \f(CW\*(C`ev_init\*(C'\fR and \f(CW\*(C`ev_TYPE_set\*(C'\fR macro
1339calls into a single call. This is the most convenient method to initialise
1340a watcher. The same limitations apply, of course.
1341.Sp
1342Example: Initialise and set an \f(CW\*(C`ev_io\*(C'\fR watcher in one step.
1343.Sp
1344.Vb 1
1345\& ev_io_init (&w, my_cb, STDIN_FILENO, EV_READ);
1346.Ve
1347.ie n .IP """ev_TYPE_start"" (loop, ev_TYPE *watcher)" 4
1348.el .IP "\f(CWev_TYPE_start\fR (loop, ev_TYPE *watcher)" 4
1349.IX Item "ev_TYPE_start (loop, ev_TYPE *watcher)"
1350Starts (activates) the given watcher. Only active watchers will receive
1351events. If the watcher is already active nothing will happen.
1352.Sp
1353Example: Start the \f(CW\*(C`ev_io\*(C'\fR watcher that is being abused as example in this
1354whole section.
1355.Sp
1356.Vb 1
1357\& ev_io_start (EV_DEFAULT_UC, &w);
1358.Ve
1359.ie n .IP """ev_TYPE_stop"" (loop, ev_TYPE *watcher)" 4
1360.el .IP "\f(CWev_TYPE_stop\fR (loop, ev_TYPE *watcher)" 4
1361.IX Item "ev_TYPE_stop (loop, ev_TYPE *watcher)"
1362Stops the given watcher if active, and clears the pending status (whether
1363the watcher was active or not).
1364.Sp
1365It is possible that stopped watchers are pending \- for example,
1366non\-repeating timers are being stopped when they become pending \- but
1367calling \f(CW\*(C`ev_TYPE_stop\*(C'\fR ensures that the watcher is neither active nor
1368pending. If you want to free or reuse the memory used by the watcher it is
1369therefore a good idea to always call its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function.
1370.IP "bool ev_is_active (ev_TYPE *watcher)" 4
1371.IX Item "bool ev_is_active (ev_TYPE *watcher)"
1372Returns a true value iff the watcher is active (i.e. it has been started
1373and not yet been stopped). As long as a watcher is active you must not modify
1374it.
1375.IP "bool ev_is_pending (ev_TYPE *watcher)" 4
1376.IX Item "bool ev_is_pending (ev_TYPE *watcher)"
1377Returns a true value iff the watcher is pending, (i.e. it has outstanding
1378events but its callback has not yet been invoked). As long as a watcher
1379is pending (but not active) you must not call an init function on it (but
1380\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must
1381make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR
1382it).
1383.IP "callback ev_cb (ev_TYPE *watcher)" 4
1384.IX Item "callback ev_cb (ev_TYPE *watcher)"
1385Returns the callback currently set on the watcher.
1386.IP "ev_set_cb (ev_TYPE *watcher, callback)" 4
1387.IX Item "ev_set_cb (ev_TYPE *watcher, callback)"
1388Change the callback. You can change the callback at virtually any time
1389(modulo threads).
1390.IP "ev_set_priority (ev_TYPE *watcher, int priority)" 4
1391.IX Item "ev_set_priority (ev_TYPE *watcher, int priority)"
1392.PD 0
1393.IP "int ev_priority (ev_TYPE *watcher)" 4
1394.IX Item "int ev_priority (ev_TYPE *watcher)"
1395.PD
1396Set and query the priority of the watcher. The priority is a small
1397integer between \f(CW\*(C`EV_MAXPRI\*(C'\fR (default: \f(CW2\fR) and \f(CW\*(C`EV_MINPRI\*(C'\fR
1398(default: \f(CW\-2\fR). Pending watchers with higher priority will be invoked
1399before watchers with lower priority, but priority will not keep watchers
1400from being executed (except for \f(CW\*(C`ev_idle\*(C'\fR watchers).
1401.Sp
1402If you need to suppress invocation when higher priority events are pending
1403you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality.
1404.Sp
1405You \fImust not\fR change the priority of a watcher as long as it is active or
1406pending.
1407.Sp
1408Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is
1409fine, as long as you do not mind that the priority value you query might
1410or might not have been clamped to the valid range.
1411.Sp
1412The default priority used by watchers when no priority has been set is
1413always \f(CW0\fR, which is supposed to not be too high and not be too low :).
1414.Sp
1415See "WATCHER PRIORITY MODELS", below, for a more thorough treatment of
1416priorities.
1417.IP "ev_invoke (loop, ev_TYPE *watcher, int revents)" 4
1418.IX Item "ev_invoke (loop, ev_TYPE *watcher, int revents)"
1419Invoke the \f(CW\*(C`watcher\*(C'\fR with the given \f(CW\*(C`loop\*(C'\fR and \f(CW\*(C`revents\*(C'\fR. Neither
1420\&\f(CW\*(C`loop\*(C'\fR nor \f(CW\*(C`revents\*(C'\fR need to be valid as long as the watcher callback
1421can deal with that fact, as both are simply passed through to the
1422callback.
1423.IP "int ev_clear_pending (loop, ev_TYPE *watcher)" 4
1424.IX Item "int ev_clear_pending (loop, ev_TYPE *watcher)"
1425If the watcher is pending, this function clears its pending status and
1426returns its \f(CW\*(C`revents\*(C'\fR bitset (as if its callback was invoked). If the
1427watcher isn\*(Aqt pending it does nothing and returns \f(CW0\fR.
1428.Sp
1429Sometimes it can be useful to "poll" a watcher instead of waiting for its
1430callback to be invoked, which can be accomplished with this function.
1431.IP "ev_feed_event (loop, ev_TYPE *watcher, int revents)" 4
1432.IX Item "ev_feed_event (loop, ev_TYPE *watcher, int revents)"
1433Feeds the given event set into the event loop, as if the specified event
1434had happened for the specified watcher (which must be a pointer to an
1435initialised but not necessarily started event watcher). Obviously you must
1436not free the watcher as long as it has pending events.
1437.Sp
1438Stopping the watcher, letting libev invoke it, or calling
1439\&\f(CW\*(C`ev_clear_pending\*(C'\fR will clear the pending event, even if the watcher was
1440not started in the first place.
1441.Sp
1442See also \f(CW\*(C`ev_feed_fd_event\*(C'\fR and \f(CW\*(C`ev_feed_signal_event\*(C'\fR for related
1443functions that do not need a watcher.
1444.PP
1445See also the "ASSOCIATING CUSTOM DATA WITH A WATCHER" and "BUILDING YOUR
1446OWN COMPOSITE WATCHERS" idioms.
1447.SS "WATCHER STATES"
1448.IX Subsection "WATCHER STATES"
1449There are various watcher states mentioned throughout this manual \-
1450active, pending and so on. In this section these states and the rules to
1451transition between them will be described in more detail \- and while these
1452rules might look complicated, they usually do "the right thing".
1453.IP initialised 4
1454.IX Item "initialised"
1455Before a watcher can be registered with the event loop it has to be
1456initialised. This can be done with a call to \f(CW\*(C`ev_TYPE_init\*(C'\fR, or calls to
1457\&\f(CW\*(C`ev_init\*(C'\fR followed by the watcher\-specific \f(CW\*(C`ev_TYPE_set\*(C'\fR function.
1458.Sp
1459In this state it is simply some block of memory that is suitable for
1460use in an event loop. It can be moved around, freed, reused etc. at
1461will \- as long as you either keep the memory contents intact, or call
1462\&\f(CW\*(C`ev_TYPE_init\*(C'\fR again.
1463.IP started/running/active 4
1464.IX Item "started/running/active"
1465Once a watcher has been started with a call to \f(CW\*(C`ev_TYPE_start\*(C'\fR it becomes
1466property of the event loop, and is actively waiting for events. While in
1467this state it cannot be accessed (except in a few documented ways), moved,
1468freed or anything else \- the only legal thing is to keep a pointer to it,
1469and call libev functions on it that are documented to work on active watchers.
1470.IP pending 4
1471.IX Item "pending"
1472If a watcher is active and libev determines that an event it is interested
1473in has occurred (such as a timer expiring), it will become pending. It will
1474stay in this pending state until either it is stopped or its callback is
1475about to be invoked, so it is not normally pending inside the watcher
1476callback.
1477.Sp
1478The watcher might or might not be active while it is pending (for example,
1479an expired non\-repeating timer can be pending but no longer active). If it
1480is stopped, it can be freely accessed (e.g. by calling \f(CW\*(C`ev_TYPE_set\*(C'\fR),
1481but it is still property of the event loop at this time, so cannot be
1482moved, freed or reused. And if it is active the rules described in the
1483previous item still apply.
1484.Sp
1485It is also possible to feed an event on a watcher that is not active (e.g.
1486via \f(CW\*(C`ev_feed_event\*(C'\fR), in which case it becomes pending without being
1487active.
1488.IP stopped 4
1489.IX Item "stopped"
1490A watcher can be stopped implicitly by libev (in which case it might still
1491be pending), or explicitly by calling its \f(CW\*(C`ev_TYPE_stop\*(C'\fR function. The
1492latter will clear any pending state the watcher might be in, regardless
1493of whether it was active or not, so stopping a watcher explicitly before
1494freeing it is often a good idea.
1495.Sp
1496While stopped (and not pending) the watcher is essentially in the
1497initialised state, that is, it can be reused, moved, modified in any way
1498you wish (but when you trash the memory block, you need to \f(CW\*(C`ev_TYPE_init\*(C'\fR
1499it again).
1500.SS "WATCHER PRIORITY MODELS"
1501.IX Subsection "WATCHER PRIORITY MODELS"
1502Many event loops support \fIwatcher priorities\fR, which are usually small
1503integers that influence the ordering of event callback invocation
1504between watchers in some way, all else being equal.
1505.PP
1506In libev, Watcher priorities can be set using \f(CW\*(C`ev_set_priority\*(C'\fR. See its
1507description for the more technical details such as the actual priority
1508range.
1509.PP
1510There are two common ways how these these priorities are being interpreted
1511by event loops:
1512.PP
1513In the more common lock\-out model, higher priorities "lock out" invocation
1514of lower priority watchers, which means as long as higher priority
1515watchers receive events, lower priority watchers are not being invoked.
1516.PP
1517The less common only\-for\-ordering model uses priorities solely to order
1518callback invocation within a single event loop iteration: Higher priority
1519watchers are invoked before lower priority ones, but they all get invoked
1520before polling for new events.
1521.PP
1522Libev uses the second (only\-for\-ordering) model for all its watchers
1523except for idle watchers (which use the lock\-out model).
1524.PP
1525The rationale behind this is that implementing the lock\-out model for
1526watchers is not well supported by most kernel interfaces, and most event
1527libraries will just poll for the same events again and again as long as
1528their callbacks have not been executed, which is very inefficient in the
1529common case of one high\-priority watcher locking out a mass of lower
1530priority ones.
1531.PP
1532Static (ordering) priorities are most useful when you have two or more
1533watchers handling the same resource: a typical usage example is having an
1534\&\f(CW\*(C`ev_io\*(C'\fR watcher to receive data, and an associated \f(CW\*(C`ev_timer\*(C'\fR to handle
1535timeouts. Under load, data might be received while the program handles
1536other jobs, but since timers normally get invoked first, the timeout
1537handler will be executed before checking for data. In that case, giving
1538the timer a lower priority than the I/O watcher ensures that I/O will be
1539handled first even under adverse conditions (which is usually, but not
1540always, what you want).
1541.PP
1542Since idle watchers use the "lock\-out" model, meaning that idle watchers
1543will only be executed when no same or higher priority watchers have
1544received events, they can be used to implement the "lock\-out" model when
1545required.
1546.PP
1547For example, to emulate how many other event libraries handle priorities,
1548you can associate an \f(CW\*(C`ev_idle\*(C'\fR watcher to each such watcher, and in
1549the normal watcher callback, you just start the idle watcher. The real
1550processing is done in the idle watcher callback. This causes libev to
1551continuously poll and process kernel event data for the watcher, but when
1552the lock\-out case is known to be rare (which in turn is rare :), this is
1553workable.
1554.PP
1555Usually, however, the lock\-out model implemented that way will perform
1556miserably under the type of load it was designed to handle. In that case,
1557it might be preferable to stop the real watcher before starting the
1558idle watcher, so the kernel will not have to process the event in case
1559the actual processing will be delayed for considerable time.
1560.PP
1561Here is an example of an I/O watcher that should run at a strictly lower
1562priority than the default, and which should only process data when no
1563other events are pending:
1564.PP
1565.Vb 2
1566\& ev_idle idle; // actual processing watcher
1567\& ev_io io; // actual event watcher
1568\&
1569\& static void
1570\& io_cb (EV_P_ ev_io *w, int revents)
1571\& {
1572\& // stop the I/O watcher, we received the event, but
1573\& // are not yet ready to handle it.
1574\& ev_io_stop (EV_A_ w);
1575\&
1576\& // start the idle watcher to handle the actual event.
1577\& // it will not be executed as long as other watchers
1578\& // with the default priority are receiving events.
1579\& ev_idle_start (EV_A_ &idle);
1580\& }
1581\&
1582\& static void
1583\& idle_cb (EV_P_ ev_idle *w, int revents)
1584\& {
1585\& // actual processing
1586\& read (STDIN_FILENO, ...);
1587\&
1588\& // have to start the I/O watcher again, as
1589\& // we have handled the event
1590\& ev_io_start (EV_P_ &io);
1591\& }
1592\&
1593\& // initialisation
1594\& ev_idle_init (&idle, idle_cb);
1595\& ev_io_init (&io, io_cb, STDIN_FILENO, EV_READ);
1596\& ev_io_start (EV_DEFAULT_ &io);
1597.Ve
1598.PP
1599In the "real" world, it might also be beneficial to start a timer, so that
1600low\-priority connections can not be locked out forever under load. This
1601enables your program to keep a lower latency for important connections
1602during short periods of high load, while not completely locking out less
1603important ones.
1604.SH "WATCHER TYPES"
1605.IX Header "WATCHER TYPES"
1606This section describes each watcher in detail, but will not repeat
1607information given in the last section. Any initialisation/set macros,
1608functions and members specific to the watcher type are explained.
1609.PP
1610Members are additionally marked with either \fI[read\-only]\fR, meaning that,
1611while the watcher is active, you can look at the member and expect some
1612sensible content, but you must not modify it (you can modify it while the
1613watcher is stopped to your hearts content), or \fI[read\-write]\fR, which
1614means you can expect it to have some sensible content while the watcher
1615is active, but you can also modify it. Modifying it may not do something
1616sensible or take immediate effect (or do anything at all), but libev will
1617not crash or malfunction in any way.
1618.ie n .SS """ev_io"" \- is this file descriptor readable or writable?"
1619.el .SS "\f(CWev_io\fP \- is this file descriptor readable or writable?"
1620.IX Subsection "ev_io - is this file descriptor readable or writable?"
1621I/O watchers check whether a file descriptor is readable or writable
1622in each iteration of the event loop, or, more precisely, when reading
1623would not block the process and writing would at least be able to write
1624some data. This behaviour is called level\-triggering because you keep
1625receiving events as long as the condition persists. Remember you can stop
1626the watcher if you don\*(Aqt want to act on the event and neither want to
1627receive future events.
1628.PP
1629In general you can register as many read and/or write event watchers per
1630fd as you want (as long as you don\*(Aqt confuse yourself). Setting all file
1631descriptors to non\-blocking mode is also usually a good idea (but not
1632required if you know what you are doing).
1633.PP
1634Another thing you have to watch out for is that it is quite easy to
1635receive "spurious" readiness notifications, that is, your callback might
1636be called with \f(CW\*(C`EV_READ\*(C'\fR but a subsequent \f(CW\*(C`read\*(C'\fR(2) will actually block
1637because there is no data. It is very easy to get into this situation even
1638with a relatively standard program structure. Thus it is best to always
1639use non\-blocking I/O: An extra \f(CW\*(C`read\*(C'\fR(2) returning \f(CW\*(C`EAGAIN\*(C'\fR is far
1640preferable to a program hanging until some data arrives.
1641.PP
1642If you cannot run the fd in non\-blocking mode (for example you should
1643not play around with an Xlib connection), then you have to separately
1644re\-test whether a file descriptor is really ready with a known\-to\-be good
1645interface such as poll (fortunately in the case of Xlib, it already does
1646this on its own, so its quite safe to use). Some people additionally
1647use \f(CW\*(C`SIGALRM\*(C'\fR and an interval timer, just to be sure you won\*(Aqt block
1648indefinitely.
1649.PP
1650But really, best use non\-blocking mode.
1651.PP
1652\fIThe special problem of disappearing file descriptors\fR
1653.IX Subsection "The special problem of disappearing file descriptors"
1654.PP
1655Some backends (e.g. kqueue, epoll) need to be told about closing a file
1656descriptor (either due to calling \f(CW\*(C`close\*(C'\fR explicitly or any other means,
1657such as \f(CW\*(C`dup2\*(C'\fR). The reason is that you register interest in some file
1658descriptor, but when it goes away, the operating system will silently drop
1659this interest. If another file descriptor with the same number then is
1660registered with libev, there is no efficient way to see that this is, in
1661fact, a different file descriptor.
1662.PP
1663To avoid having to explicitly tell libev about such cases, libev follows
1664the following policy: Each time \f(CW\*(C`ev_io_set\*(C'\fR is being called, libev
1665will assume that this is potentially a new file descriptor, otherwise
1666it is assumed that the file descriptor stays the same. That means that
1667you \fIhave\fR to call \f(CW\*(C`ev_io_set\*(C'\fR (or \f(CW\*(C`ev_io_init\*(C'\fR) when you change the
1668descriptor even if the file descriptor number itself did not change.
1669.PP
1670This is how one would do it normally anyway, the important point is that
1671the libev application should not optimise around libev but should leave
1672optimisations to libev.
1673.PP
1674\fIThe special problem of dup\*(Aqed file descriptors\fR
1675.IX Subsection "The special problem of dup'ed file descriptors"
1676.PP
1677Some backends (e.g. epoll), cannot register events for file descriptors,
1678but only events for the underlying file descriptions. That means when you
1679have \f(CW\*(C`dup ()\*(C'\fR\*(Aqed file descriptors or weirder constellations, and register
1680events for them, only one file descriptor might actually receive events.
1681.PP
1682There is no workaround possible except not registering events
1683for potentially \f(CW\*(C`dup ()\*(C'\fR\*(Aqed file descriptors, or to resort to
1684\&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR.
1685.PP
1686\fIThe special problem of files\fR
1687.IX Subsection "The special problem of files"
1688.PP
1689Many people try to use \f(CW\*(C`select\*(C'\fR (or libev) on file descriptors
1690representing files, and expect it to become ready when their program
1691doesn\*(Aqt block on disk accesses (which can take a long time on their own).
1692.PP
1693However, this cannot ever work in the "expected" way \- you get a readiness
1694notification as soon as the kernel knows whether and how much data is
1695there, and in the case of open files, that\*(Aqs always the case, so you
1696always get a readiness notification instantly, and your read (or possibly
1697write) will still block on the disk I/O.
1698.PP
1699Another way to view it is that in the case of sockets, pipes, character
1700devices and so on, there is another party (the sender) that delivers data
1701on its own, but in the case of files, there is no such thing: the disk
1702will not send data on its own, simply because it doesn\*(Aqt know what you
1703wish to read \- you would first have to request some data.
1704.PP
1705Since files are typically not\-so\-well supported by advanced notification
1706mechanism, libev tries hard to emulate POSIX behaviour with respect
1707to files, even though you should not use it. The reason for this is
1708convenience: sometimes you want to watch STDIN or STDOUT, which is
1709usually a tty, often a pipe, but also sometimes files or special devices
1710(for example, \f(CW\*(C`epoll\*(C'\fR on Linux works with \fI/dev/random\fR but not with
1711\&\fI/dev/urandom\fR), and even though the file might better be served with
1712asynchronous I/O instead of with non\-blocking I/O, it is still useful when
1713it "just works" instead of freezing.
1714.PP
1715So avoid file descriptors pointing to files when you know it (e.g. use
1716libeio), but use them when it is convenient, e.g. for STDIN/STDOUT, or
1717when you rarely read from a file instead of from a socket, and want to
1718reuse the same code path.
1719.PP
1720\fIThe special problem of fork\fR
1721.IX Subsection "The special problem of fork"
1722.PP
1723Some backends (epoll, kqueue) do not support \f(CW\*(C`fork ()\*(C'\fR at all or exhibit
1724useless behaviour. Libev fully supports fork, but needs to be told about
1725it in the child if you want to continue to use it in the child.
1726.PP
1727To support fork in your child processes, you have to call \f(CW\*(C`ev_loop_fork
1728()\*(C'\fR after a fork in the child, enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to
1729\&\f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or \f(CW\*(C`EVBACKEND_POLL\*(C'\fR.
1730.PP
1731\fIThe special problem of SIGPIPE\fR
1732.IX Subsection "The special problem of SIGPIPE"
1733.PP
1734While not really specific to libev, it is easy to forget about \f(CW\*(C`SIGPIPE\*(C'\fR:
1735when writing to a pipe whose other end has been closed, your program gets
1736sent a SIGPIPE, which, by default, aborts your program. For most programs
1737this is sensible behaviour, for daemons, this is usually undesirable.
1738.PP
1739So when you encounter spurious, unexplained daemon exits, make sure you
1740ignore SIGPIPE (and maybe make sure you log the exit status of your daemon
1741somewhere, as that would have given you a big clue).
1742.PP
1743\fIThe special problem of \fR\f(BIaccept()\fR\fIing when you can\*(Aqt\fR
1744.IX Subsection "The special problem of accept()ing when you can't"
1745.PP
1746Many implementations of the POSIX \f(CW\*(C`accept\*(C'\fR function (for example,
1747found in post\-2004 Linux) have the peculiar behaviour of not removing a
1748connection from the pending queue in all error cases.
1749.PP
1750For example, larger servers often run out of file descriptors (because
1751of resource limits), causing \f(CW\*(C`accept\*(C'\fR to fail with \f(CW\*(C`ENFILE\*(C'\fR but not
1752rejecting the connection, leading to libev signalling readiness on
1753the next iteration again (the connection still exists after all), and
1754typically causing the program to loop at 100% CPU usage.
1755.PP
1756Unfortunately, the set of errors that cause this issue differs between
1757operating systems, there is usually little the app can do to remedy the
1758situation, and no known thread\-safe method of removing the connection to
1759cope with overload is known (to me).
1760.PP
1761One of the easiest ways to handle this situation is to just ignore it
1762\&\- when the program encounters an overload, it will just loop until the
1763situation is over. While this is a form of busy waiting, no OS offers an
1764event\-based way to handle this situation, so it\*(Aqs the best one can do.
1765.PP
1766A better way to handle the situation is to log any errors other than
1767\&\f(CW\*(C`EAGAIN\*(C'\fR and \f(CW\*(C`EWOULDBLOCK\*(C'\fR, making sure not to flood the log with such
1768messages, and continue as usual, which at least gives the user an idea of
1769what could be wrong ("raise the ulimit!"). For extra points one could stop
1770the \f(CW\*(C`ev_io\*(C'\fR watcher on the listening fd "for a while", which reduces CPU
1771usage.
1772.PP
1773If your program is single\-threaded, then you could also keep a dummy file
1774descriptor for overload situations (e.g. by opening \fI/dev/null\fR), and
1775when you run into \f(CW\*(C`ENFILE\*(C'\fR or \f(CW\*(C`EMFILE\*(C'\fR, close it, run \f(CW\*(C`accept\*(C'\fR,
1776close that fd, and create a new dummy fd. This will gracefully refuse
1777clients under typical overload conditions.
1778.PP
1779The last way to handle it is to simply log the error and \f(CW\*(C`exit\*(C'\fR, as
1780is often done with \f(CW\*(C`malloc\*(C'\fR failures, but this results in an easy
1781opportunity for a DoS attack.
1782.PP
1783\fIWatcher\-Specific Functions\fR
1784.IX Subsection "Watcher-Specific Functions"
1785.IP "ev_io_init (ev_io *, callback, int fd, int events)" 4
1786.IX Item "ev_io_init (ev_io *, callback, int fd, int events)"
1787.PD 0
1788.IP "ev_io_set (ev_io *, int fd, int events)" 4
1789.IX Item "ev_io_set (ev_io *, int fd, int events)"
1790.PD
1791Configures an \f(CW\*(C`ev_io\*(C'\fR watcher. The \f(CW\*(C`fd\*(C'\fR is the file descriptor to
1792receive events for and \f(CW\*(C`events\*(C'\fR is either \f(CW\*(C`EV_READ\*(C'\fR, \f(CW\*(C`EV_WRITE\*(C'\fR or
1793\&\f(CW\*(C`EV_READ | EV_WRITE\*(C'\fR, to express the desire to receive the given events.
1794.IP "int fd [read\-only]" 4
1795.IX Item "int fd [read-only]"
1796The file descriptor being watched.
1797.IP "int events [read\-only]" 4
1798.IX Item "int events [read-only]"
1799The events being watched.
1800.PP
1801\fIExamples\fR
1802.IX Subsection "Examples"
1803.PP
1804Example: Call \f(CW\*(C`stdin_readable_cb\*(C'\fR when STDIN_FILENO has become, well
1805readable, but only once. Since it is likely line\-buffered, you could
1806attempt to read a whole line in the callback.
1807.PP
1808.Vb 6
1809\& static void
1810\& stdin_readable_cb (struct ev_loop *loop, ev_io *w, int revents)
1811\& {
1812\& ev_io_stop (loop, w);
1813\& .. read from stdin here (or from w\->fd) and handle any I/O errors
1814\& }
1815\&
1816\& ...
1817\& struct ev_loop *loop = ev_default_init (0);
1818\& ev_io stdin_readable;
1819\& ev_io_init (&stdin_readable, stdin_readable_cb, STDIN_FILENO, EV_READ);
1820\& ev_io_start (loop, &stdin_readable);
1821\& ev_run (loop, 0);
1822.Ve
1823.ie n .SS """ev_timer"" \- relative and optionally repeating timeouts"
1824.el .SS "\f(CWev_timer\fP \- relative and optionally repeating timeouts"
1825.IX Subsection "ev_timer - relative and optionally repeating timeouts"
1826Timer watchers are simple relative timers that generate an event after a
1827given time, and optionally repeating in regular intervals after that.
1828.PP
1829The timers are based on real time, that is, if you register an event that
1830times out after an hour and you reset your system clock to January last
1831year, it will still time out after (roughly) one hour. "Roughly" because
1832detecting time jumps is hard, and some inaccuracies are unavoidable (the
1833monotonic clock option helps a lot here).
1834.PP
1835The callback is guaranteed to be invoked only \fIafter\fR its timeout has
1836passed (not \fIat\fR, so on systems with very low\-resolution clocks this
1837might introduce a small delay, see "the special problem of being too
1838early", below). If multiple timers become ready during the same loop
1839iteration then the ones with earlier time\-out values are invoked before
1840ones of the same priority with later time\-out values (but this is no
1841longer true when a callback calls \f(CW\*(C`ev_run\*(C'\fR recursively).
1842.PP
1843\fIBe smart about timeouts\fR
1844.IX Subsection "Be smart about timeouts"
1845.PP
1846Many real\-world problems involve some kind of timeout, usually for error
1847recovery. A typical example is an HTTP request \- if the other side hangs,
1848you want to raise some error after a while.
1849.PP
1850What follows are some ways to handle this problem, from obvious and
1851inefficient to smart and efficient.
1852.PP
1853In the following, a 60 second activity timeout is assumed \- a timeout that
1854gets reset to 60 seconds each time there is activity (e.g. each time some
1855data or other life sign was received).
1856.IP "1. Use a timer and stop, reinitialise and start it on activity." 4
1857.IX Item "1. Use a timer and stop, reinitialise and start it on activity."
1858This is the most obvious, but not the most simple way: In the beginning,
1859start the watcher:
1860.Sp
1861.Vb 2
1862\& ev_timer_init (timer, callback, 60., 0.);
1863\& ev_timer_start (loop, timer);
1864.Ve
1865.Sp
1866Then, each time there is some activity, \f(CW\*(C`ev_timer_stop\*(C'\fR it, initialise it
1867and start it again:
1868.Sp
1869.Vb 3
1870\& ev_timer_stop (loop, timer);
1871\& ev_timer_set (timer, 60., 0.);
1872\& ev_timer_start (loop, timer);
1873.Ve
1874.Sp
1875This is relatively simple to implement, but means that each time there is
1876some activity, libev will first have to remove the timer from its internal
1877data structure and then add it again. Libev tries to be fast, but it\*(Aqs
1878still not a constant\-time operation.
1879.ie n .IP "2. Use a timer and re\-start it with ""ev_timer_again"" inactivity." 4
1880.el .IP "2. Use a timer and re\-start it with \f(CWev_timer_again\fR inactivity." 4
1881.IX Item "2. Use a timer and re-start it with ev_timer_again inactivity."
1882This is the easiest way, and involves using \f(CW\*(C`ev_timer_again\*(C'\fR instead of
1883\&\f(CW\*(C`ev_timer_start\*(C'\fR.
1884.Sp
1885To implement this, configure an \f(CW\*(C`ev_timer\*(C'\fR with a \f(CW\*(C`repeat\*(C'\fR value
1886of \f(CW60\fR and then call \f(CW\*(C`ev_timer_again\*(C'\fR at start and each time you
1887successfully read or write some data. If you go into an idle state where
1888you do not expect data to travel on the socket, you can \f(CW\*(C`ev_timer_stop\*(C'\fR
1889the timer, and \f(CW\*(C`ev_timer_again\*(C'\fR will automatically restart it if need be.
1890.Sp
1891That means you can ignore both the \f(CW\*(C`ev_timer_start\*(C'\fR function and the
1892\&\f(CW\*(C`after\*(C'\fR argument to \f(CW\*(C`ev_timer_set\*(C'\fR, and only ever use the \f(CW\*(C`repeat\*(C'\fR
1893member and \f(CW\*(C`ev_timer_again\*(C'\fR.
1894.Sp
1895At start:
1896.Sp
1897.Vb 3
1898\& ev_init (timer, callback);
1899\& timer\->repeat = 60.;
1900\& ev_timer_again (loop, timer);
1901.Ve
1902.Sp
1903Each time there is some activity:
1904.Sp
1905.Vb 1
1906\& ev_timer_again (loop, timer);
1907.Ve
1908.Sp
1909It is even possible to change the time\-out on the fly, regardless of
1910whether the watcher is active or not:
1911.Sp
1912.Vb 2
1913\& timer\->repeat = 30.;
1914\& ev_timer_again (loop, timer);
1915.Ve
1916.Sp
1917This is slightly more efficient then stopping/starting the timer each time
1918you want to modify its timeout value, as libev does not have to completely
1919remove and re\-insert the timer from/into its internal data structure.
1920.Sp
1921It is, however, even simpler than the "obvious" way to do it.
1922.IP "3. Let the timer time out, but then re\-arm it as required." 4
1923.IX Item "3. Let the timer time out, but then re-arm it as required."
1924This method is more tricky, but usually most efficient: Most timeouts are
1925relatively long compared to the intervals between other activity \- in
1926our example, within 60 seconds, there are usually many I/O events with
1927associated activity resets.
1928.Sp
1929In this case, it would be more efficient to leave the \f(CW\*(C`ev_timer\*(C'\fR alone,
1930but remember the time of last activity, and check for a real timeout only
1931within the callback:
1932.Sp
1933.Vb 3
1934\& ev_tstamp timeout = 60.;
1935\& ev_tstamp last_activity; // time of last activity
1936\& ev_timer timer;
1937\&
1938\& static void
1939\& callback (EV_P_ ev_timer *w, int revents)
1940\& {
1941\& // calculate when the timeout would happen
1942\& ev_tstamp after = last_activity \- ev_now (EV_A) + timeout;
1943\&
1944\& // if negative, it means we the timeout already occurred
1945\& if (after < 0.)
1946\& {
1947\& // timeout occurred, take action
1948\& }
1949\& else
1950\& {
1951\& // callback was invoked, but there was some recent
1952\& // activity. simply restart the timer to time out
1953\& // after "after" seconds, which is the earliest time
1954\& // the timeout can occur.
1955\& ev_timer_set (w, after, 0.);
1956\& ev_timer_start (EV_A_ w);
1957\& }
1958\& }
1959.Ve
1960.Sp
1961To summarise the callback: first calculate in how many seconds the
1962timeout will occur (by calculating the absolute time when it would occur,
1963\&\f(CW\*(C`last_activity + timeout\*(C'\fR, and subtracting the current time, \f(CW\*(C`ev_now
1964(EV_A)\*(C'\fR from that).
1965.Sp
1966If this value is negative, then we are already past the timeout, i.e. we
1967timed out, and need to do whatever is needed in this case.
1968.Sp
1969Otherwise, we now the earliest time at which the timeout would trigger,
1970and simply start the timer with this timeout value.
1971.Sp
1972In other words, each time the callback is invoked it will check whether
1973the timeout occurred. If not, it will simply reschedule itself to check
1974again at the earliest time it could time out. Rinse. Repeat.
1975.Sp
1976This scheme causes more callback invocations (about one every 60 seconds
1977minus half the average time between activity), but virtually no calls to
1978libev to change the timeout.
1979.Sp
1980To start the machinery, simply initialise the watcher and set
1981\&\f(CW\*(C`last_activity\*(C'\fR to the current time (meaning there was some activity just
1982now), then call the callback, which will "do the right thing" and start
1983the timer:
1984.Sp
1985.Vb 3
1986\& last_activity = ev_now (EV_A);
1987\& ev_init (&timer, callback);
1988\& callback (EV_A_ &timer, 0);
1989.Ve
1990.Sp
1991When there is some activity, simply store the current time in
1992\&\f(CW\*(C`last_activity\*(C'\fR, no libev calls at all:
1993.Sp
1994.Vb 2
1995\& if (activity detected)
1996\& last_activity = ev_now (EV_A);
1997.Ve
1998.Sp
1999When your timeout value changes, then the timeout can be changed by simply
2000providing a new value, stopping the timer and calling the callback, which
2001will again do the right thing (for example, time out immediately :).
2002.Sp
2003.Vb 3
2004\& timeout = new_value;
2005\& ev_timer_stop (EV_A_ &timer);
2006\& callback (EV_A_ &timer, 0);
2007.Ve
2008.Sp
2009This technique is slightly more complex, but in most cases where the
2010time\-out is unlikely to be triggered, much more efficient.
2011.IP "4. Wee, just use a double\-linked list for your timeouts." 4
2012.IX Item "4. Wee, just use a double-linked list for your timeouts."
2013If there is not one request, but many thousands (millions...), all
2014employing some kind of timeout with the same timeout value, then one can
2015do even better:
2016.Sp
2017When starting the timeout, calculate the timeout value and put the timeout
2018at the \fIend\fR of the list.
2019.Sp
2020Then use an \f(CW\*(C`ev_timer\*(C'\fR to fire when the timeout at the \fIbeginning\fR of
2021the list is expected to fire (for example, using the technique #3).
2022.Sp
2023When there is some activity, remove the timer from the list, recalculate
2024the timeout, append it to the end of the list again, and make sure to
2025update the \f(CW\*(C`ev_timer\*(C'\fR if it was taken from the beginning of the list.
2026.Sp
2027This way, one can manage an unlimited number of timeouts in O(1) time for
2028starting, stopping and updating the timers, at the expense of a major
2029complication, and having to use a constant timeout. The constant timeout
2030ensures that the list stays sorted.
2031.PP
2032So which method the best?
2033.PP
2034Method #2 is a simple no\-brain\-required solution that is adequate in most
2035situations. Method #3 requires a bit more thinking, but handles many cases
2036better, and isn\*(Aqt very complicated either. In most case, choosing either
2037one is fine, with #3 being better in typical situations.
2038.PP
2039Method #1 is almost always a bad idea, and buys you nothing. Method #4 is
2040rather complicated, but extremely efficient, something that really pays
2041off after the first million or so of active timers, i.e. it\*(Aqs usually
2042overkill :)
2043.PP
2044\fIThe special problem of being too early\fR
2045.IX Subsection "The special problem of being too early"
2046.PP
2047If you ask a timer to call your callback after three seconds, then
2048you expect it to be invoked after three seconds \- but of course, this
2049cannot be guaranteed to infinite precision. Less obviously, it cannot be
2050guaranteed to any precision by libev \- imagine somebody suspending the
2051process with a STOP signal for a few hours for example.
2052.PP
2053So, libev tries to invoke your callback as soon as possible \fIafter\fR the
2054delay has occurred, but cannot guarantee this.
2055.PP
2056A less obvious failure mode is calling your callback too early: many event
2057loops compare timestamps with a "elapsed delay >= requested delay", but
2058this can cause your callback to be invoked much earlier than you would
2059expect.
2060.PP
2061To see why, imagine a system with a clock that only offers full second
2062resolution (think windows if you can\*(Aqt come up with a broken enough OS
2063yourself). If you schedule a one\-second timer at the time 500.9, then the
2064event loop will schedule your timeout to elapse at a system time of 500
2065(500.9 truncated to the resolution) + 1, or 501.
2066.PP
2067If an event library looks at the timeout 0.1s later, it will see "501 >=
2068501" and invoke the callback 0.1s after it was started, even though a
2069one\-second delay was requested \- this is being "too early", despite best
2070intentions.
2071.PP
2072This is the reason why libev will never invoke the callback if the elapsed
2073delay equals the requested delay, but only when the elapsed delay is
2074larger than the requested delay. In the example above, libev would only invoke
2075the callback at system time 502, or 1.1s after the timer was started.
2076.PP
2077So, while libev cannot guarantee that your callback will be invoked
2078exactly when requested, it \fIcan\fR and \fIdoes\fR guarantee that the requested
2079delay has actually elapsed, or in other words, it always errs on the "too
2080late" side of things.
2081.PP
2082\fIThe special problem of time updates\fR
2083.IX Subsection "The special problem of time updates"
2084.PP
2085Establishing the current time is a costly operation (it usually takes
2086at least one system call): EV therefore updates its idea of the current
2087time only before and after \f(CW\*(C`ev_run\*(C'\fR collects new events, which causes a
2088growing difference between \f(CW\*(C`ev_now ()\*(C'\fR and \f(CW\*(C`ev_time ()\*(C'\fR when handling
2089lots of events in one iteration.
2090.PP
2091The relative timeouts are calculated relative to the \f(CW\*(C`ev_now ()\*(C'\fR
2092time. This is usually the right thing as this timestamp refers to the time
2093of the event triggering whatever timeout you are modifying/starting. If
2094you suspect event processing to be delayed and you \fIneed\fR to base the
2095timeout on the current time, use something like the following to adjust
2096for it:
2097.PP
2098.Vb 1
2099\& ev_timer_set (&timer, after + (ev_time () \- ev_now ()), 0.);
2100.Ve
2101.PP
2102If the event loop is suspended for a long time, you can also force an
2103update of the time returned by \f(CW\*(C`ev_now ()\*(C'\fR by calling \f(CW\*(C`ev_now_update
2104()\*(C'\fR, although that will push the event time of all outstanding events
2105further into the future.
2106.PP
2107\fIThe special problem of unsynchronised clocks\fR
2108.IX Subsection "The special problem of unsynchronised clocks"
2109.PP
2110Modern systems have a variety of clocks \- libev itself uses the normal
2111"wall clock" clock and, if available, the monotonic clock (to avoid time
2112jumps).
2113.PP
2114Neither of these clocks is synchronised with each other or any other clock
2115on the system, so \f(CW\*(C`ev_time ()\*(C'\fR might return a considerably different time
2116than \f(CW\*(C`gettimeofday ()\*(C'\fR or \f(CW\*(C`time ()\*(C'\fR. On a GNU/Linux system, for example,
2117a call to \f(CW\*(C`gettimeofday\*(C'\fR might return a second count that is one higher
2118than a directly following call to \f(CW\*(C`time\*(C'\fR.
2119.PP
2120The moral of this is to only compare libev\-related timestamps with
2121\&\f(CW\*(C`ev_time ()\*(C'\fR and \f(CW\*(C`ev_now ()\*(C'\fR, at least if you want better precision than
2122a second or so.
2123.PP
2124One more problem arises due to this lack of synchronisation: if libev uses
2125the system monotonic clock and you compare timestamps from \f(CW\*(C`ev_time\*(C'\fR
2126or \f(CW\*(C`ev_now\*(C'\fR from when you started your timer and when your callback is
2127invoked, you will find that sometimes the callback is a bit "early".
2128.PP
2129This is because \f(CW\*(C`ev_timer\*(C'\fRs work in real time, not wall clock time, so
2130libev makes sure your callback is not invoked before the delay happened,
2131\&\fImeasured according to the real time\fR, not the system clock.
2132.PP
2133If your timeouts are based on a physical timescale (e.g. "time out this
2134connection after 100 seconds") then this shouldn\*(Aqt bother you as it is
2135exactly the right behaviour.
2136.PP
2137If you want to compare wall clock/system timestamps to your timers, then
2138you need to use \f(CW\*(C`ev_periodic\*(C'\fRs, as these are based on the wall clock
2139time, where your comparisons will always generate correct results.
2140.PP
2141\fIThe special problems of suspended animation\fR
2142.IX Subsection "The special problems of suspended animation"
2143.PP
2144When you leave the server world it is quite customary to hit machines that
2145can suspend/hibernate \- what happens to the clocks during such a suspend?
2146.PP
2147Some quick tests made with a Linux 2.6.28 indicate that a suspend freezes
2148all processes, while the clocks (\f(CW\*(C`times\*(C'\fR, \f(CW\*(C`CLOCK_MONOTONIC\*(C'\fR) continue
2149to run until the system is suspended, but they will not advance while the
2150system is suspended. That means, on resume, it will be as if the program
2151was frozen for a few seconds, but the suspend time will not be counted
2152towards \f(CW\*(C`ev_timer\*(C'\fR when a monotonic clock source is used. The real time
2153clock advanced as expected, but if it is used as sole clocksource, then a
2154long suspend would be detected as a time jump by libev, and timers would
2155be adjusted accordingly.
2156.PP
2157I would not be surprised to see different behaviour in different between
2158operating systems, OS versions or even different hardware.
2159.PP
2160The other form of suspend (job control, or sending a SIGSTOP) will see a
2161time jump in the monotonic clocks and the realtime clock. If the program
2162is suspended for a very long time, and monotonic clock sources are in use,
2163then you can expect \f(CW\*(C`ev_timer\*(C'\fRs to expire as the full suspension time
2164will be counted towards the timers. When no monotonic clock source is in
2165use, then libev will again assume a timejump and adjust accordingly.
2166.PP
2167It might be beneficial for this latter case to call \f(CW\*(C`ev_suspend\*(C'\fR
2168and \f(CW\*(C`ev_resume\*(C'\fR in code that handles \f(CW\*(C`SIGTSTP\*(C'\fR, to at least get
2169deterministic behaviour in this case (you can do nothing against
2170\&\f(CW\*(C`SIGSTOP\*(C'\fR).
2171.PP
2172\fIWatcher\-Specific Functions and Data Members\fR
2173.IX Subsection "Watcher-Specific Functions and Data Members"
2174.IP "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)" 4
2175.IX Item "ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat)"
2176.PD 0
2177.IP "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)" 4
2178.IX Item "ev_timer_set (ev_timer *, ev_tstamp after, ev_tstamp repeat)"
2179.PD
2180Configure the timer to trigger after \f(CW\*(C`after\*(C'\fR seconds. If \f(CW\*(C`repeat\*(C'\fR
2181is \f(CW0.\fR, then it will automatically be stopped once the timeout is
2182reached. If it is positive, then the timer will automatically be
2183configured to trigger again \f(CW\*(C`repeat\*(C'\fR seconds later, again, and again,
2184until stopped manually.
2185.Sp
2186The timer itself will do a best\-effort at avoiding drift, that is, if
2187you configure a timer to trigger every 10 seconds, then it will normally
2188trigger at exactly 10 second intervals. If, however, your program cannot
2189keep up with the timer (because it takes longer than those 10 seconds to
2190do stuff) the timer will not fire more than once per event loop iteration.
2191.IP "ev_timer_again (loop, ev_timer *)" 4
2192.IX Item "ev_timer_again (loop, ev_timer *)"
2193This will act as if the timer timed out, and restarts it again if it is
2194repeating. It basically works like calling \f(CW\*(C`ev_timer_stop\*(C'\fR, updating the
2195timeout to the \f(CW\*(C`repeat\*(C'\fR value and calling \f(CW\*(C`ev_timer_start\*(C'\fR.
2196.Sp
2197The exact semantics are as in the following rules, all of which will be
2198applied to the watcher:
2199.RS 4
2200.IP "If the timer is pending, the pending status is always cleared." 4
2201.IX Item "If the timer is pending, the pending status is always cleared."
2202.PD 0
2203.IP "If the timer is started but non\-repeating, stop it (as if it timed out, without invoking it)." 4
2204.IX Item "If the timer is started but non-repeating, stop it (as if it timed out, without invoking it)."
2205.ie n .IP "If the timer is repeating, make the ""repeat"" value the new timeout and start the timer, if necessary." 4
2206.el .IP "If the timer is repeating, make the \f(CWrepeat\fR value the new timeout and start the timer, if necessary." 4
2207.IX Item "If the timer is repeating, make the repeat value the new timeout and start the timer, if necessary."
2208.PD
2209.RE
2210.RS 4
2211.Sp
2212This sounds a bit complicated, see "Be smart about timeouts", above, for a
2213usage example.
2214.RE
2215.IP "ev_tstamp ev_timer_remaining (loop, ev_timer *)" 4
2216.IX Item "ev_tstamp ev_timer_remaining (loop, ev_timer *)"
2217Returns the remaining time until a timer fires. If the timer is active,
2218then this time is relative to the current event loop time, otherwise it\*(Aqs
2219the timeout value currently configured.
2220.Sp
2221That is, after an \f(CW\*(C`ev_timer_set (w, 5, 7)\*(C'\fR, \f(CW\*(C`ev_timer_remaining\*(C'\fR returns
2222\&\f(CW5\fR. When the timer is started and one second passes, \f(CW\*(C`ev_timer_remaining\*(C'\fR
2223will return \f(CW4\fR. When the timer expires and is restarted, it will return
2224roughly \f(CW7\fR (likely slightly less as callback invocation takes some time,
2225too), and so on.
2226.IP "ev_tstamp repeat [read\-write]" 4
2227.IX Item "ev_tstamp repeat [read-write]"
2228The current \f(CW\*(C`repeat\*(C'\fR value. Will be used each time the watcher times out
2229or \f(CW\*(C`ev_timer_again\*(C'\fR is called, and determines the next timeout (if any),
2230which is also when any modifications are taken into account.
2231.PP
2232\fIExamples\fR
2233.IX Subsection "Examples"
2234.PP
2235Example: Create a timer that fires after 60 seconds.
2236.PP
2237.Vb 5
2238\& static void
2239\& one_minute_cb (struct ev_loop *loop, ev_timer *w, int revents)
2240\& {
2241\& .. one minute over, w is actually stopped right here
2242\& }
2243\&
2244\& ev_timer mytimer;
2245\& ev_timer_init (&mytimer, one_minute_cb, 60., 0.);
2246\& ev_timer_start (loop, &mytimer);
2247.Ve
2248.PP
2249Example: Create a timeout timer that times out after 10 seconds of
2250inactivity.
2251.PP
2252.Vb 5
2253\& static void
2254\& timeout_cb (struct ev_loop *loop, ev_timer *w, int revents)
2255\& {
2256\& .. ten seconds without any activity
2257\& }
2258\&
2259\& ev_timer mytimer;
2260\& ev_timer_init (&mytimer, timeout_cb, 0., 10.); /* note, only repeat used */
2261\& ev_timer_again (&mytimer); /* start timer */
2262\& ev_run (loop, 0);
2263\&
2264\& // and in some piece of code that gets executed on any "activity":
2265\& // reset the timeout to start ticking again at 10 seconds
2266\& ev_timer_again (&mytimer);
2267.Ve
2268.ie n .SS """ev_periodic"" \- to cron or not to cron?"
2269.el .SS "\f(CWev_periodic\fP \- to cron or not to cron?"
2270.IX Subsection "ev_periodic - to cron or not to cron?"
2271Periodic watchers are also timers of a kind, but they are very versatile
2272(and unfortunately a bit complex).
2273.PP
2274Unlike \f(CW\*(C`ev_timer\*(C'\fR, periodic watchers are not based on real time (or
2275relative time, the physical time that passes) but on wall clock time
2276(absolute time, the thing you can read on your calender or clock). The
2277difference is that wall clock time can run faster or slower than real
2278time, and time jumps are not uncommon (e.g. when you adjust your
2279wrist\-watch).
2280.PP
2281You can tell a periodic watcher to trigger after some specific point
2282in time: for example, if you tell a periodic watcher to trigger "in 10
2283seconds" (by specifying e.g. \f(CW\*(C`ev_now () + 10.\*(C'\fR, that is, an absolute time
2284not a delay) and then reset your system clock to January of the previous
2285year, then it will take a year or more to trigger the event (unlike an
2286\&\f(CW\*(C`ev_timer\*(C'\fR, which would still trigger roughly 10 seconds after starting
2287it, as it uses a relative timeout).
2288.PP
2289\&\f(CW\*(C`ev_periodic\*(C'\fR watchers can also be used to implement vastly more complex
2290timers, such as triggering an event on each "midnight, local time", or
2291other complicated rules. This cannot be done with \f(CW\*(C`ev_timer\*(C'\fR watchers, as
2292those cannot react to time jumps.
2293.PP
2294As with timers, the callback is guaranteed to be invoked only when the
2295point in time where it is supposed to trigger has passed. If multiple
2296timers become ready during the same loop iteration then the ones with
2297earlier time\-out values are invoked before ones with later time\-out values
2298(but this is no longer true when a callback calls \f(CW\*(C`ev_run\*(C'\fR recursively).
2299.PP
2300\fIWatcher\-Specific Functions and Data Members\fR
2301.IX Subsection "Watcher-Specific Functions and Data Members"
2302.IP "ev_periodic_init (ev_periodic *, callback, ev_tstamp offset, ev_tstamp interval, reschedule_cb)" 4
2303.IX Item "ev_periodic_init (ev_periodic *, callback, ev_tstamp offset, ev_tstamp interval, reschedule_cb)"
2304.PD 0
2305.IP "ev_periodic_set (ev_periodic *, ev_tstamp offset, ev_tstamp interval, reschedule_cb)" 4
2306.IX Item "ev_periodic_set (ev_periodic *, ev_tstamp offset, ev_tstamp interval, reschedule_cb)"
2307.PD
2308Lots of arguments, let\*(Aqs sort it out... There are basically three modes of
2309operation, and we will explain them from simplest to most complex:
2310.RS 4
2311.IP \(bu 4
2312absolute timer (offset = absolute time, interval = 0, reschedule_cb = 0)
2313.Sp
2314In this configuration the watcher triggers an event after the wall clock
2315time \f(CW\*(C`offset\*(C'\fR has passed. It will not repeat and will not adjust when a
2316time jump occurs, that is, if it is to be run at January 1st 2011 then it
2317will be stopped and invoked when the system clock reaches or surpasses
2318this point in time.
2319.IP \(bu 4
2320repeating interval timer (offset = offset within interval, interval > 0, reschedule_cb = 0)
2321.Sp
2322In this mode the watcher will always be scheduled to time out at the next
2323\&\f(CW\*(C`offset + N * interval\*(C'\fR time (for some integer N, which can also be
2324negative) and then repeat, regardless of any time jumps. The \f(CW\*(C`offset\*(C'\fR
2325argument is merely an offset into the \f(CW\*(C`interval\*(C'\fR periods.
2326.Sp
2327This can be used to create timers that do not drift with respect to the
2328system clock, for example, here is an \f(CW\*(C`ev_periodic\*(C'\fR that triggers each
2329hour, on the hour (with respect to UTC):
2330.Sp
2331.Vb 1
2332\& ev_periodic_set (&periodic, 0., 3600., 0);
2333.Ve
2334.Sp
2335This doesn\*(Aqt mean there will always be 3600 seconds in between triggers,
2336but only that the callback will be called when the system time shows a
2337full hour (UTC), or more correctly, when the system time is evenly divisible
2338by 3600.
2339.Sp
2340Another way to think about it (for the mathematically inclined) is that
2341\&\f(CW\*(C`ev_periodic\*(C'\fR will try to run the callback in this mode at the next possible
2342time where \f(CW\*(C`time = offset (mod interval)\*(C'\fR, regardless of any time jumps.
2343.Sp
2344The \f(CW\*(C`interval\*(C'\fR \fIMUST\fR be positive, and for numerical stability, the
2345interval value should be higher than \f(CW\*(C`1/8192\*(C'\fR (which is around 100
2346microseconds) and \f(CW\*(C`offset\*(C'\fR should be higher than \f(CW0\fR and should have
2347at most a similar magnitude as the current time (say, within a factor of
2348ten). Typical values for offset are, in fact, \f(CW0\fR or something between
2349\&\f(CW0\fR and \f(CW\*(C`interval\*(C'\fR, which is also the recommended range.
2350.Sp
2351Note also that there is an upper limit to how often a timer can fire (CPU
2352speed for example), so if \f(CW\*(C`interval\*(C'\fR is very small then timing stability
2353will of course deteriorate. Libev itself tries to be exact to be about one
2354millisecond (if the OS supports it and the machine is fast enough).
2355.IP \(bu 4
2356manual reschedule mode (offset ignored, interval ignored, reschedule_cb = callback)
2357.Sp
2358In this mode the values for \f(CW\*(C`interval\*(C'\fR and \f(CW\*(C`offset\*(C'\fR are both being
2359ignored. Instead, each time the periodic watcher gets scheduled, the
2360reschedule callback will be called with the watcher as first, and the
2361current time as second argument.
2362.Sp
2363NOTE: \fIThis callback MUST NOT stop or destroy any periodic watcher, ever,
2364or make ANY other event loop modifications whatsoever, unless explicitly
2365allowed by documentation here\fR.
2366.Sp
2367If you need to stop it, return \f(CW\*(C`now + 1e30\*(C'\fR (or so, fudge fudge) and stop
2368it afterwards (e.g. by starting an \f(CW\*(C`ev_prepare\*(C'\fR watcher, which is the
2369only event loop modification you are allowed to do).
2370.Sp
2371The callback prototype is \f(CW\*(C`ev_tstamp (*reschedule_cb)(ev_periodic
2372*w, ev_tstamp now)\*(C'\fR, e.g.:
2373.Sp
2374.Vb 5
2375\& static ev_tstamp
2376\& my_rescheduler (ev_periodic *w, ev_tstamp now)
2377\& {
2378\& return now + 60.;
2379\& }
2380.Ve
2381.Sp
2382It must return the next time to trigger, based on the passed time value
2383(that is, the lowest time value larger than to the second argument). It
2384will usually be called just before the callback will be triggered, but
2385might be called at other times, too.
2386.Sp
2387NOTE: \fIThis callback must always return a time that is higher than or
2388equal to the passed \fR\f(CI\*(C`now\*(C'\fR\fI value\fR.
2389.Sp
2390This can be used to create very complex timers, such as a timer that
2391triggers on "next midnight, local time". To do this, you would calculate the
2392next midnight after \f(CW\*(C`now\*(C'\fR and return the timestamp value for this. How
2393you do this is, again, up to you (but it is not trivial, which is the main
2394reason I omitted it as an example).
2395.RE
2396.RS 4
2397.RE
2398.IP "ev_periodic_again (loop, ev_periodic *)" 4
2399.IX Item "ev_periodic_again (loop, ev_periodic *)"
2400Simply stops and restarts the periodic watcher again. This is only useful
2401when you changed some parameters or the reschedule callback would return
2402a different time than the last time it was called (e.g. in a crond like
2403program when the crontabs have changed).
2404.IP "ev_tstamp ev_periodic_at (ev_periodic *)" 4
2405.IX Item "ev_tstamp ev_periodic_at (ev_periodic *)"
2406When active, returns the absolute time that the watcher is supposed
2407to trigger next. This is not the same as the \f(CW\*(C`offset\*(C'\fR argument to
2408\&\f(CW\*(C`ev_periodic_set\*(C'\fR, but indeed works even in interval and manual
2409rescheduling modes.
2410.IP "ev_tstamp offset [read\-write]" 4
2411.IX Item "ev_tstamp offset [read-write]"
2412When repeating, this contains the offset value, otherwise this is the
2413absolute point in time (the \f(CW\*(C`offset\*(C'\fR value passed to \f(CW\*(C`ev_periodic_set\*(C'\fR,
2414although libev might modify this value for better numerical stability).
2415.Sp
2416Can be modified any time, but changes only take effect when the periodic
2417timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called.
2418.IP "ev_tstamp interval [read\-write]" 4
2419.IX Item "ev_tstamp interval [read-write]"
2420The current interval value. Can be modified any time, but changes only
2421take effect when the periodic timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being
2422called.
2423.IP "ev_tstamp (*reschedule_cb)(ev_periodic *w, ev_tstamp now) [read\-write]" 4
2424.IX Item "ev_tstamp (*reschedule_cb)(ev_periodic *w, ev_tstamp now) [read-write]"
2425The current reschedule callback, or \f(CW0\fR, if this functionality is
2426switched off. Can be changed any time, but changes only take effect when
2427the periodic timer fires or \f(CW\*(C`ev_periodic_again\*(C'\fR is being called.
2428.PP
2429\fIExamples\fR
2430.IX Subsection "Examples"
2431.PP
2432Example: Call a callback every hour, or, more precisely, whenever the
2433system time is divisible by 3600. The callback invocation times have
2434potentially a lot of jitter, but good long\-term stability.
2435.PP
2436.Vb 5
2437\& static void
2438\& clock_cb (struct ev_loop *loop, ev_periodic *w, int revents)
2439\& {
2440\& ... its now a full hour (UTC, or TAI or whatever your clock follows)
2441\& }
2442\&
2443\& ev_periodic hourly_tick;
2444\& ev_periodic_init (&hourly_tick, clock_cb, 0., 3600., 0);
2445\& ev_periodic_start (loop, &hourly_tick);
2446.Ve
2447.PP
2448Example: The same as above, but use a reschedule callback to do it:
2449.PP
2450.Vb 1
2451\& #include <math.h>
2452\&
2453\& static ev_tstamp
2454\& my_scheduler_cb (ev_periodic *w, ev_tstamp now)
2455\& {
2456\& return now + (3600. \- fmod (now, 3600.));
2457\& }
2458\&
2459\& ev_periodic_init (&hourly_tick, clock_cb, 0., 0., my_scheduler_cb);
2460.Ve
2461.PP
2462Example: Call a callback every hour, starting now:
2463.PP
2464.Vb 4
2465\& ev_periodic hourly_tick;
2466\& ev_periodic_init (&hourly_tick, clock_cb,
2467\& fmod (ev_now (loop), 3600.), 3600., 0);
2468\& ev_periodic_start (loop, &hourly_tick);
2469.Ve
2470.ie n .SS """ev_signal"" \- signal me when a signal gets signalled!"
2471.el .SS "\f(CWev_signal\fP \- signal me when a signal gets signalled!"
2472.IX Subsection "ev_signal - signal me when a signal gets signalled!"
2473Signal watchers will trigger an event when the process receives a specific
2474signal one or more times. Even though signals are very asynchronous, libev
2475will try its best to deliver signals synchronously, i.e. as part of the
2476normal event processing, like any other event.
2477.PP
2478If you want signals to be delivered truly asynchronously, just use
2479\&\f(CW\*(C`sigaction\*(C'\fR as you would do without libev and forget about sharing
2480the signal. You can even use \f(CW\*(C`ev_async\*(C'\fR from a signal handler to
2481synchronously wake up an event loop.
2482.PP
2483You can configure as many watchers as you like for the same signal, but
2484only within the same loop, i.e. you can watch for \f(CW\*(C`SIGINT\*(C'\fR in your
2485default loop and for \f(CW\*(C`SIGIO\*(C'\fR in another loop, but you cannot watch for
2486\&\f(CW\*(C`SIGINT\*(C'\fR in both the default loop and another loop at the same time. At
2487the moment, \f(CW\*(C`SIGCHLD\*(C'\fR is permanently tied to the default loop.
2488.PP
2489Only after the first watcher for a signal is started will libev actually
2490register something with the kernel. It thus coexists with your own signal
2491handlers as long as you don\*(Aqt register any with libev for the same signal.
2492.PP
2493If possible and supported, libev will install its handlers with
2494\&\f(CW\*(C`SA_RESTART\*(C'\fR (or equivalent) behaviour enabled, so system calls should
2495not be unduly interrupted. If you have a problem with system calls getting
2496interrupted by signals you can block all signals in an \f(CW\*(C`ev_check\*(C'\fR watcher
2497and unblock them in an \f(CW\*(C`ev_prepare\*(C'\fR watcher.
2498.PP
2499\fIThe special problem of inheritance over fork/execve/pthread_create\fR
2500.IX Subsection "The special problem of inheritance over fork/execve/pthread_create"
2501.PP
2502Both the signal mask (\f(CW\*(C`sigprocmask\*(C'\fR) and the signal disposition
2503(\f(CW\*(C`sigaction\*(C'\fR) are unspecified after starting a signal watcher (and after
2504stopping it again), that is, libev might or might not block the signal,
2505and might or might not set or restore the installed signal handler (but
2506see \f(CW\*(C`EVFLAG_NOSIGMASK\*(C'\fR).
2507.PP
2508While this does not matter for the signal disposition (libev never
2509sets signals to \f(CW\*(C`SIG_IGN\*(C'\fR, so handlers will be reset to \f(CW\*(C`SIG_DFL\*(C'\fR on
2510\&\f(CW\*(C`execve\*(C'\fR), this matters for the signal mask: many programs do not expect
2511certain signals to be blocked.
2512.PP
2513This means that before calling \f(CW\*(C`exec\*(C'\fR (from the child) you should reset
2514the signal mask to whatever "default" you expect (all clear is a good
2515choice usually).
2516.PP
2517The simplest way to ensure that the signal mask is reset in the child is
2518to install a fork handler with \f(CW\*(C`pthread_atfork\*(C'\fR that resets it. That will
2519catch fork calls done by libraries (such as the libc) as well.
2520.PP
2521In current versions of libev, the signal will not be blocked indefinitely
2522unless you use the \f(CW\*(C`signalfd\*(C'\fR API (\f(CW\*(C`EV_SIGNALFD\*(C'\fR). While this reduces
2523the window of opportunity for problems, it will not go away, as libev
2524\&\fIhas\fR to modify the signal mask, at least temporarily.
2525.PP
2526So I can\*(Aqt stress this enough: \fIIf you do not reset your signal mask when
2527you expect it to be empty, you have a race condition in your code\fR. This
2528is not a libev\-specific thing, this is true for most event libraries.
2529.PP
2530\fIThe special problem of threads signal handling\fR
2531.IX Subsection "The special problem of threads signal handling"
2532.PP
2533POSIX threads has problematic signal handling semantics, specifically,
2534a lot of functionality (sigfd, sigwait etc.) only really works if all
2535threads in a process block signals, which is hard to achieve.
2536.PP
2537When you want to use sigwait (or mix libev signal handling with your own
2538for the same signals), you can tackle this problem by globally blocking
2539all signals before creating any threads (or creating them with a fully set
2540sigprocmask) and also specifying the \f(CW\*(C`EVFLAG_NOSIGMASK\*(C'\fR when creating
2541loops. Then designate one thread as "signal receiver thread" which handles
2542these signals. You can pass on any signals that libev might be interested
2543in by calling \f(CW\*(C`ev_feed_signal\*(C'\fR.
2544.PP
2545\fIWatcher\-Specific Functions and Data Members\fR
2546.IX Subsection "Watcher-Specific Functions and Data Members"
2547.IP "ev_signal_init (ev_signal *, callback, int signum)" 4
2548.IX Item "ev_signal_init (ev_signal *, callback, int signum)"
2549.PD 0
2550.IP "ev_signal_set (ev_signal *, int signum)" 4
2551.IX Item "ev_signal_set (ev_signal *, int signum)"
2552.PD
2553Configures the watcher to trigger on the given signal number (usually one
2554of the \f(CW\*(C`SIGxxx\*(C'\fR constants).
2555.IP "int signum [read\-only]" 4
2556.IX Item "int signum [read-only]"
2557The signal the watcher watches out for.
2558.PP
2559\fIExamples\fR
2560.IX Subsection "Examples"
2561.PP
2562Example: Try to exit cleanly on SIGINT.
2563.PP
2564.Vb 5
2565\& static void
2566\& sigint_cb (struct ev_loop *loop, ev_signal *w, int revents)
2567\& {
2568\& ev_break (loop, EVBREAK_ALL);
2569\& }
2570\&
2571\& ev_signal signal_watcher;
2572\& ev_signal_init (&signal_watcher, sigint_cb, SIGINT);
2573\& ev_signal_start (loop, &signal_watcher);
2574.Ve
2575.ie n .SS """ev_child"" \- watch out for process status changes"
2576.el .SS "\f(CWev_child\fP \- watch out for process status changes"
2577.IX Subsection "ev_child - watch out for process status changes"
2578Child watchers trigger when your process receives a SIGCHLD in response to
2579some child status changes (most typically when a child of yours dies or
2580exits). It is permissible to install a child watcher \fIafter\fR the child
2581has been forked (which implies it might have already exited), as long
2582as the event loop isn\*(Aqt entered (or is continued from a watcher), i.e.,
2583forking and then immediately registering a watcher for the child is fine,
2584but forking and registering a watcher a few event loop iterations later or
2585in the next callback invocation is not.
2586.PP
2587Only the default event loop is capable of handling signals, and therefore
2588you can only register child watchers in the default event loop.
2589.PP
2590Due to some design glitches inside libev, child watchers will always be
2591handled at maximum priority (their priority is set to \f(CW\*(C`EV_MAXPRI\*(C'\fR by
2592libev)
2593.PP
2594\fIProcess Interaction\fR
2595.IX Subsection "Process Interaction"
2596.PP
2597Libev grabs \f(CW\*(C`SIGCHLD\*(C'\fR as soon as the default event loop is
2598initialised. This is necessary to guarantee proper behaviour even if the
2599first child watcher is started after the child exits. The occurrence
2600of \f(CW\*(C`SIGCHLD\*(C'\fR is recorded asynchronously, but child reaping is done
2601synchronously as part of the event loop processing. Libev always reaps all
2602children, even ones not watched.
2603.PP
2604\fIOverriding the Built\-In Processing\fR
2605.IX Subsection "Overriding the Built-In Processing"
2606.PP
2607Libev offers no special support for overriding the built\-in child
2608processing, but if your application collides with libev\*(Aqs default child
2609handler, you can override it easily by installing your own handler for
2610\&\f(CW\*(C`SIGCHLD\*(C'\fR after initialising the default loop, and making sure the
2611default loop never gets destroyed. You are encouraged, however, to use an
2612event\-based approach to child reaping and thus use libev\*(Aqs support for
2613that, so other libev users can use \f(CW\*(C`ev_child\*(C'\fR watchers freely.
2614.PP
2615\fIStopping the Child Watcher\fR
2616.IX Subsection "Stopping the Child Watcher"
2617.PP
2618Currently, the child watcher never gets stopped, even when the
2619child terminates, so normally one needs to stop the watcher in the
2620callback. Future versions of libev might stop the watcher automatically
2621when a child exit is detected (calling \f(CW\*(C`ev_child_stop\*(C'\fR twice is not a
2622problem).
2623.PP
2624\fIWatcher\-Specific Functions and Data Members\fR
2625.IX Subsection "Watcher-Specific Functions and Data Members"
2626.IP "ev_child_init (ev_child *, callback, int pid, int trace)" 4
2627.IX Item "ev_child_init (ev_child *, callback, int pid, int trace)"
2628.PD 0
2629.IP "ev_child_set (ev_child *, int pid, int trace)" 4
2630.IX Item "ev_child_set (ev_child *, int pid, int trace)"
2631.PD
2632Configures the watcher to wait for status changes of process \f(CW\*(C`pid\*(C'\fR (or
2633\&\fIany\fR process if \f(CW\*(C`pid\*(C'\fR is specified as \f(CW0\fR). The callback can look
2634at the \f(CW\*(C`rstatus\*(C'\fR member of the \f(CW\*(C`ev_child\*(C'\fR watcher structure to see
2635the status word (use the macros from \f(CW\*(C`sys/wait.h\*(C'\fR and see your systems
2636\&\f(CW\*(C`waitpid\*(C'\fR documentation). The \f(CW\*(C`rpid\*(C'\fR member contains the pid of the
2637process causing the status change. \f(CW\*(C`trace\*(C'\fR must be either \f(CW0\fR (only
2638activate the watcher when the process terminates) or \f(CW1\fR (additionally
2639activate the watcher when the process is stopped or continued).
2640.IP "int pid [read\-only]" 4
2641.IX Item "int pid [read-only]"
2642The process id this watcher watches out for, or \f(CW0\fR, meaning any process id.
2643.IP "int rpid [read\-write]" 4
2644.IX Item "int rpid [read-write]"
2645The process id that detected a status change.
2646.IP "int rstatus [read\-write]" 4
2647.IX Item "int rstatus [read-write]"
2648The process exit/trace status caused by \f(CW\*(C`rpid\*(C'\fR (see your systems
2649\&\f(CW\*(C`waitpid\*(C'\fR and \f(CW\*(C`sys/wait.h\*(C'\fR documentation for details).
2650.PP
2651\fIExamples\fR
2652.IX Subsection "Examples"
2653.PP
2654Example: \f(CWfork()\fR a new process and install a child handler to wait for
2655its completion.
2656.PP
2657.Vb 1
2658\& ev_child cw;
2659\&
2660\& static void
2661\& child_cb (EV_P_ ev_child *w, int revents)
2662\& {
2663\& ev_child_stop (EV_A_ w);
2664\& printf ("process %d exited with status %x\en", w\->rpid, w\->rstatus);
2665\& }
2666\&
2667\& pid_t pid = fork ();
2668\&
2669\& if (pid < 0)
2670\& // error
2671\& else if (pid == 0)
2672\& {
2673\& // the forked child executes here
2674\& exit (1);
2675\& }
2676\& else
2677\& {
2678\& ev_child_init (&cw, child_cb, pid, 0);
2679\& ev_child_start (EV_DEFAULT_ &cw);
2680\& }
2681.Ve
2682.ie n .SS """ev_stat"" \- did the file attributes just change?"
2683.el .SS "\f(CWev_stat\fP \- did the file attributes just change?"
2684.IX Subsection "ev_stat - did the file attributes just change?"
2685This watches a file system path for attribute changes. That is, it calls
2686\&\f(CW\*(C`stat\*(C'\fR on that path in regular intervals (or when the OS says it changed)
2687and sees if it changed compared to the last time, invoking the callback
2688if it did. Starting the watcher \f(CW\*(C`stat\*(C'\fR\*(Aqs the file, so only changes that
2689happen after the watcher has been started will be reported.
2690.PP
2691The path does not need to exist: changing from "path exists" to "path does
2692not exist" is a status change like any other. The condition "path does not
2693exist" (or more correctly "path cannot be stat\*(Aqed") is signified by the
2694\&\f(CW\*(C`st_nlink\*(C'\fR field being zero (which is otherwise always forced to be at
2695least one) and all the other fields of the stat buffer having unspecified
2696contents.
2697.PP
2698The path \fImust not\fR end in a slash or contain special components such as
2699\&\f(CW\*(C`.\*(C'\fR or \f(CW\*(C`..\*(C'\fR. The path \fIshould\fR be absolute: If it is relative and
2700your working directory changes, then the behaviour is undefined.
2701.PP
2702Since there is no portable change notification interface available, the
2703portable implementation simply calls \f(CWstat(2)\fR regularly on the path
2704to see if it changed somehow. You can specify a recommended polling
2705interval for this case. If you specify a polling interval of \f(CW0\fR (highly
2706recommended!) then a \fIsuitable, unspecified default\fR value will be used
2707(which you can expect to be around five seconds, although this might
2708change dynamically). Libev will also impose a minimum interval which is
2709currently around \f(CW0.1\fR, but that\*(Aqs usually overkill.
2710.PP
2711This watcher type is not meant for massive numbers of stat watchers,
2712as even with OS\-supported change notifications, this can be
2713resource\-intensive.
2714.PP
2715At the time of this writing, the only OS\-specific interface implemented
2716is the Linux inotify interface (implementing kqueue support is left as an
2717exercise for the reader. Note, however, that the author sees no way of
2718implementing \f(CW\*(C`ev_stat\*(C'\fR semantics with kqueue, except as a hint).
2719.PP
2720\fIABI Issues (Largefile Support)\fR
2721.IX Subsection "ABI Issues (Largefile Support)"
2722.PP
2723Libev by default (unless the user overrides this) uses the default
2724compilation environment, which means that on systems with large file
2725support disabled by default, you get the 32 bit version of the stat
2726structure. When using the library from programs that change the ABI to
2727use 64 bit file offsets the programs will fail. In that case you have to
2728compile libev with the same flags to get binary compatibility. This is
2729obviously the case with any flags that change the ABI, but the problem is
2730most noticeably displayed with ev_stat and large file support.
2731.PP
2732The solution for this is to lobby your distribution maker to make large
2733file interfaces available by default (as e.g. FreeBSD does) and not
2734optional. Libev cannot simply switch on large file support because it has
2735to exchange stat structures with application programs compiled using the
2736default compilation environment.
2737.PP
2738\fIInotify and Kqueue\fR
2739.IX Subsection "Inotify and Kqueue"
2740.PP
2741When \f(CW\*(C`inotify (7)\*(C'\fR support has been compiled into libev and present at
2742runtime, it will be used to speed up change detection where possible. The
2743inotify descriptor will be created lazily when the first \f(CW\*(C`ev_stat\*(C'\fR
2744watcher is being started.
2745.PP
2746Inotify presence does not change the semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers
2747except that changes might be detected earlier, and in some cases, to avoid
2748making regular \f(CW\*(C`stat\*(C'\fR calls. Even in the presence of inotify support
2749there are many cases where libev has to resort to regular \f(CW\*(C`stat\*(C'\fR polling,
2750but as long as kernel 2.6.25 or newer is used (2.6.24 and older have too
2751many bugs), the path exists (i.e. stat succeeds), and the path resides on
2752a local filesystem (libev currently assumes only ext2/3, jfs, reiserfs and
2753xfs are fully working) libev usually gets away without polling.
2754.PP
2755There is no support for kqueue, as apparently it cannot be used to
2756implement this functionality, due to the requirement of having a file
2757descriptor open on the object at all times, and detecting renames, unlinks
2758etc. is difficult.
2759.PP
2760\fR\f(CI\*(C`stat ()\*(C'\fR\fI is a synchronous operation\fR
2761.IX Subsection "stat () is a synchronous operation"
2762.PP
2763Libev doesn\*(Aqt normally do any kind of I/O itself, and so is not blocking
2764the process. The exception are \f(CW\*(C`ev_stat\*(C'\fR watchers \- those call \f(CW\*(C`stat
2765()\*(C'\fR, which is a synchronous operation.
2766.PP
2767For local paths, this usually doesn\*(Aqt matter: unless the system is very
2768busy or the intervals between stat\*(Aqs are large, a stat call will be fast,
2769as the path data is usually in memory already (except when starting the
2770watcher).
2771.PP
2772For networked file systems, calling \f(CW\*(C`stat ()\*(C'\fR can block an indefinite
2773time due to network issues, and even under good conditions, a stat call
2774often takes multiple milliseconds.
2775.PP
2776Therefore, it is best to avoid using \f(CW\*(C`ev_stat\*(C'\fR watchers on networked
2777paths, although this is fully supported by libev.
2778.PP
2779\fIThe special problem of stat time resolution\fR
2780.IX Subsection "The special problem of stat time resolution"
2781.PP
2782The \f(CW\*(C`stat ()\*(C'\fR system call only supports full\-second resolution portably,
2783and even on systems where the resolution is higher, most file systems
2784still only support whole seconds.
2785.PP
2786That means that, if the time is the only thing that changes, you can
2787easily miss updates: on the first update, \f(CW\*(C`ev_stat\*(C'\fR detects a change and
2788calls your callback, which does something. When there is another update
2789within the same second, \f(CW\*(C`ev_stat\*(C'\fR will be unable to detect unless the
2790stat data does change in other ways (e.g. file size).
2791.PP
2792The solution to this is to delay acting on a change for slightly more
2793than a second (or till slightly after the next full second boundary), using
2794a roughly one\-second\-delay \f(CW\*(C`ev_timer\*(C'\fR (e.g. \f(CW\*(C`ev_timer_set (w, 0., 1.02);
2795ev_timer_again (loop, w)\*(C'\fR).
2796.PP
2797The \f(CW.02\fR offset is added to work around small timing inconsistencies
2798of some operating systems (where the second counter of the current time
2799might be be delayed. One such system is the Linux kernel, where a call to
2800\&\f(CW\*(C`gettimeofday\*(C'\fR might return a timestamp with a full second later than
2801a subsequent \f(CW\*(C`time\*(C'\fR call \- if the equivalent of \f(CW\*(C`time ()\*(C'\fR is used to
2802update file times then there will be a small window where the kernel uses
2803the previous second to update file times but libev might already execute
2804the timer callback).
2805.PP
2806\fIWatcher\-Specific Functions and Data Members\fR
2807.IX Subsection "Watcher-Specific Functions and Data Members"
2808.IP "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)" 4
2809.IX Item "ev_stat_init (ev_stat *, callback, const char *path, ev_tstamp interval)"
2810.PD 0
2811.IP "ev_stat_set (ev_stat *, const char *path, ev_tstamp interval)" 4
2812.IX Item "ev_stat_set (ev_stat *, const char *path, ev_tstamp interval)"
2813.PD
2814Configures the watcher to wait for status changes of the given
2815\&\f(CW\*(C`path\*(C'\fR. The \f(CW\*(C`interval\*(C'\fR is a hint on how quickly a change is expected to
2816be detected and should normally be specified as \f(CW0\fR to let libev choose
2817a suitable value. The memory pointed to by \f(CW\*(C`path\*(C'\fR must point to the same
2818path for as long as the watcher is active.
2819.Sp
2820The callback will receive an \f(CW\*(C`EV_STAT\*(C'\fR event when a change was detected,
2821relative to the attributes at the time the watcher was started (or the
2822last change was detected).
2823.IP "ev_stat_stat (loop, ev_stat *)" 4
2824.IX Item "ev_stat_stat (loop, ev_stat *)"
2825Updates the stat buffer immediately with new values. If you change the
2826watched path in your callback, you could call this function to avoid
2827detecting this change (while introducing a race condition if you are not
2828the only one changing the path). Can also be useful simply to find out the
2829new values.
2830.IP "ev_statdata attr [read\-only]" 4
2831.IX Item "ev_statdata attr [read-only]"
2832The most\-recently detected attributes of the file. Although the type is
2833\&\f(CW\*(C`ev_statdata\*(C'\fR, this is usually the (or one of the) \f(CW\*(C`struct stat\*(C'\fR types
2834suitable for your system, but you can only rely on the POSIX\-standardised
2835members to be present. If the \f(CW\*(C`st_nlink\*(C'\fR member is \f(CW0\fR, then there was
2836some error while \f(CW\*(C`stat\*(C'\fRing the file.
2837.IP "ev_statdata prev [read\-only]" 4
2838.IX Item "ev_statdata prev [read-only]"
2839The previous attributes of the file. The callback gets invoked whenever
2840\&\f(CW\*(C`prev\*(C'\fR != \f(CW\*(C`attr\*(C'\fR, or, more precisely, one or more of these members
2841differ: \f(CW\*(C`st_dev\*(C'\fR, \f(CW\*(C`st_ino\*(C'\fR, \f(CW\*(C`st_mode\*(C'\fR, \f(CW\*(C`st_nlink\*(C'\fR, \f(CW\*(C`st_uid\*(C'\fR,
2842\&\f(CW\*(C`st_gid\*(C'\fR, \f(CW\*(C`st_rdev\*(C'\fR, \f(CW\*(C`st_size\*(C'\fR, \f(CW\*(C`st_atime\*(C'\fR, \f(CW\*(C`st_mtime\*(C'\fR, \f(CW\*(C`st_ctime\*(C'\fR.
2843.IP "ev_tstamp interval [read\-only]" 4
2844.IX Item "ev_tstamp interval [read-only]"
2845The specified interval.
2846.IP "const char *path [read\-only]" 4
2847.IX Item "const char *path [read-only]"
2848The file system path that is being watched.
2849.PP
2850\fIExamples\fR
2851.IX Subsection "Examples"
2852.PP
2853Example: Watch \f(CW\*(C`/etc/passwd\*(C'\fR for attribute changes.
2854.PP
2855.Vb 10
2856\& static void
2857\& passwd_cb (struct ev_loop *loop, ev_stat *w, int revents)
2858\& {
2859\& /* /etc/passwd changed in some way */
2860\& if (w\->attr.st_nlink)
2861\& {
2862\& printf ("passwd current size %ld\en", (long)w\->attr.st_size);
2863\& printf ("passwd current atime %ld\en", (long)w\->attr.st_mtime);
2864\& printf ("passwd current mtime %ld\en", (long)w\->attr.st_mtime);
2865\& }
2866\& else
2867\& /* you shalt not abuse printf for puts */
2868\& puts ("wow, /etc/passwd is not there, expect problems. "
2869\& "if this is windows, they already arrived\en");
2870\& }
2871\&
2872\& ...
2873\& ev_stat passwd;
2874\&
2875\& ev_stat_init (&passwd, passwd_cb, "/etc/passwd", 0.);
2876\& ev_stat_start (loop, &passwd);
2877.Ve
2878.PP
2879Example: Like above, but additionally use a one\-second delay so we do not
2880miss updates (however, frequent updates will delay processing, too, so
2881one might do the work both on \f(CW\*(C`ev_stat\*(C'\fR callback invocation \fIand\fR on
2882\&\f(CW\*(C`ev_timer\*(C'\fR callback invocation).
2883.PP
2884.Vb 2
2885\& static ev_stat passwd;
2886\& static ev_timer timer;
2887\&
2888\& static void
2889\& timer_cb (EV_P_ ev_timer *w, int revents)
2890\& {
2891\& ev_timer_stop (EV_A_ w);
2892\&
2893\& /* now it\*(Aqs one second after the most recent passwd change */
2894\& }
2895\&
2896\& static void
2897\& stat_cb (EV_P_ ev_stat *w, int revents)
2898\& {
2899\& /* reset the one\-second timer */
2900\& ev_timer_again (EV_A_ &timer);
2901\& }
2902\&
2903\& ...
2904\& ev_stat_init (&passwd, stat_cb, "/etc/passwd", 0.);
2905\& ev_stat_start (loop, &passwd);
2906\& ev_timer_init (&timer, timer_cb, 0., 1.02);
2907.Ve
2908.ie n .SS """ev_idle"" \- when you\*(Aqve got nothing better to do..."
2909.el .SS "\f(CWev_idle\fP \- when you\*(Aqve got nothing better to do..."
2910.IX Subsection "ev_idle - when you've got nothing better to do..."
2911Idle watchers trigger events when no other events of the same or higher
2912priority are pending (prepare, check and other idle watchers do not count
2913as receiving "events").
2914.PP
2915That is, as long as your process is busy handling sockets or timeouts
2916(or even signals, imagine) of the same or higher priority it will not be
2917triggered. But when your process is idle (or only lower\-priority watchers
2918are pending), the idle watchers are being called once per event loop
2919iteration \- until stopped, that is, or your process receives more events
2920and becomes busy again with higher priority stuff.
2921.PP
2922The most noteworthy effect is that as long as any idle watchers are
2923active, the process will not block when waiting for new events.
2924.PP
2925Apart from keeping your process non\-blocking (which is a useful
2926effect on its own sometimes), idle watchers are a good place to do
2927"pseudo\-background processing", or delay processing stuff to after the
2928event loop has handled all outstanding events.
2929.PP
2930\fIAbusing an \fR\f(CI\*(C`ev_idle\*(C'\fR\fI watcher for its side\-effect\fR
2931.IX Subsection "Abusing an ev_idle watcher for its side-effect"
2932.PP
2933As long as there is at least one active idle watcher, libev will never
2934sleep unnecessarily. Or in other words, it will loop as fast as possible.
2935For this to work, the idle watcher doesn\*(Aqt need to be invoked at all \- the
2936lowest priority will do.
2937.PP
2938This mode of operation can be useful together with an \f(CW\*(C`ev_check\*(C'\fR watcher,
2939to do something on each event loop iteration \- for example to balance load
2940between different connections.
2941.PP
2942See "Abusing an ev_check watcher for its side\-effect" for a longer
2943example.
2944.PP
2945\fIWatcher\-Specific Functions and Data Members\fR
2946.IX Subsection "Watcher-Specific Functions and Data Members"
2947.IP "ev_idle_init (ev_idle *, callback)" 4
2948.IX Item "ev_idle_init (ev_idle *, callback)"
2949Initialises and configures the idle watcher \- it has no parameters of any
2950kind. There is a \f(CW\*(C`ev_idle_set\*(C'\fR macro, but using it is utterly pointless,
2951believe me.
2952.PP
2953\fIExamples\fR
2954.IX Subsection "Examples"
2955.PP
2956Example: Dynamically allocate an \f(CW\*(C`ev_idle\*(C'\fR watcher, start it, and in the
2957callback, free it. Also, use no error checking, as usual.
2958.PP
2959.Vb 5
2960\& static void
2961\& idle_cb (struct ev_loop *loop, ev_idle *w, int revents)
2962\& {
2963\& // stop the watcher
2964\& ev_idle_stop (loop, w);
2965\&
2966\& // now we can free it
2967\& free (w);
2968\&
2969\& // now do something you wanted to do when the program has
2970\& // no longer anything immediate to do.
2971\& }
2972\&
2973\& ev_idle *idle_watcher = malloc (sizeof (ev_idle));
2974\& ev_idle_init (idle_watcher, idle_cb);
2975\& ev_idle_start (loop, idle_watcher);
2976.Ve
2977.ie n .SS """ev_prepare"" and ""ev_check"" \- customise your event loop!"
2978.el .SS "\f(CWev_prepare\fP and \f(CWev_check\fP \- customise your event loop!"
2979.IX Subsection "ev_prepare and ev_check - customise your event loop!"
2980Prepare and check watchers are often (but not always) used in pairs:
2981prepare watchers get invoked before the process blocks and check watchers
2982afterwards.
2983.PP
2984You \fImust not\fR call \f(CW\*(C`ev_run\*(C'\fR (or similar functions that enter the
2985current event loop) or \f(CW\*(C`ev_loop_fork\*(C'\fR from either \f(CW\*(C`ev_prepare\*(C'\fR or
2986\&\f(CW\*(C`ev_check\*(C'\fR watchers. Other loops than the current one are fine,
2987however. The rationale behind this is that you do not need to check
2988for recursion in those watchers, i.e. the sequence will always be
2989\&\f(CW\*(C`ev_prepare\*(C'\fR, blocking, \f(CW\*(C`ev_check\*(C'\fR so if you have one watcher of each
2990kind they will always be called in pairs bracketing the blocking call.
2991.PP
2992Their main purpose is to integrate other event mechanisms into libev and
2993their use is somewhat advanced. They could be used, for example, to track
2994variable changes, implement your own watchers, integrate net\-snmp or a
2995coroutine library and lots more. They are also occasionally useful if
2996you cache some data and want to flush it before blocking (for example,
2997in X programs you might want to do an \f(CW\*(C`XFlush ()\*(C'\fR in an \f(CW\*(C`ev_prepare\*(C'\fR
2998watcher).
2999.PP
3000This is done by examining in each prepare call which file descriptors
3001need to be watched by the other library, registering \f(CW\*(C`ev_io\*(C'\fR watchers
3002for them and starting an \f(CW\*(C`ev_timer\*(C'\fR watcher for any timeouts (many
3003libraries provide exactly this functionality). Then, in the check watcher,
3004you check for any events that occurred (by checking the pending status
3005of all watchers and stopping them) and call back into the library. The
3006I/O and timer callbacks will never actually be called (but must be valid
3007nevertheless, because you never know, you know?).
3008.PP
3009As another example, the Perl Coro module uses these hooks to integrate
3010coroutines into libev programs, by yielding to other active coroutines
3011during each prepare and only letting the process block if no coroutines
3012are ready to run (it\*(Aqs actually more complicated: it only runs coroutines
3013with priority higher than or equal to the event loop and one coroutine
3014of lower priority, but only once, using idle watchers to keep the event
3015loop from blocking if lower\-priority coroutines are active, thus mapping
3016low\-priority coroutines to idle/background tasks).
3017.PP
3018When used for this purpose, it is recommended to give \f(CW\*(C`ev_check\*(C'\fR watchers
3019highest (\f(CW\*(C`EV_MAXPRI\*(C'\fR) priority, to ensure that they are being run before
3020any other watchers after the poll (this doesn\*(Aqt matter for \f(CW\*(C`ev_prepare\*(C'\fR
3021watchers).
3022.PP
3023Also, \f(CW\*(C`ev_check\*(C'\fR watchers (and \f(CW\*(C`ev_prepare\*(C'\fR watchers, too) should not
3024activate ("feed") events into libev. While libev fully supports this, they
3025might get executed before other \f(CW\*(C`ev_check\*(C'\fR watchers did their job. As
3026\&\f(CW\*(C`ev_check\*(C'\fR watchers are often used to embed other (non\-libev) event
3027loops those other event loops might be in an unusable state until their
3028\&\f(CW\*(C`ev_check\*(C'\fR watcher ran (always remind yourself to coexist peacefully with
3029others).
3030.PP
3031\fIAbusing an \fR\f(CI\*(C`ev_check\*(C'\fR\fI watcher for its side\-effect\fR
3032.IX Subsection "Abusing an ev_check watcher for its side-effect"
3033.PP
3034\&\f(CW\*(C`ev_check\*(C'\fR (and less often also \f(CW\*(C`ev_prepare\*(C'\fR) watchers can also be
3035useful because they are called once per event loop iteration. For
3036example, if you want to handle a large number of connections fairly, you
3037normally only do a bit of work for each active connection, and if there
3038is more work to do, you wait for the next event loop iteration, so other
3039connections have a chance of making progress.
3040.PP
3041Using an \f(CW\*(C`ev_check\*(C'\fR watcher is almost enough: it will be called on the
3042next event loop iteration. However, that isn\*(Aqt as soon as possible \-
3043without external events, your \f(CW\*(C`ev_check\*(C'\fR watcher will not be invoked.
3044.PP
3045This is where \f(CW\*(C`ev_idle\*(C'\fR watchers come in handy \- all you need is a
3046single global idle watcher that is active as long as you have one active
3047\&\f(CW\*(C`ev_check\*(C'\fR watcher. The \f(CW\*(C`ev_idle\*(C'\fR watcher makes sure the event loop
3048will not sleep, and the \f(CW\*(C`ev_check\*(C'\fR watcher makes sure a callback gets
3049invoked. Neither watcher alone can do that.
3050.PP
3051\fIWatcher\-Specific Functions and Data Members\fR
3052.IX Subsection "Watcher-Specific Functions and Data Members"
3053.IP "ev_prepare_init (ev_prepare *, callback)" 4
3054.IX Item "ev_prepare_init (ev_prepare *, callback)"
3055.PD 0
3056.IP "ev_check_init (ev_check *, callback)" 4
3057.IX Item "ev_check_init (ev_check *, callback)"
3058.PD
3059Initialises and configures the prepare or check watcher \- they have no
3060parameters of any kind. There are \f(CW\*(C`ev_prepare_set\*(C'\fR and \f(CW\*(C`ev_check_set\*(C'\fR
3061macros, but using them is utterly, utterly, utterly and completely
3062pointless.
3063.PP
3064\fIExamples\fR
3065.IX Subsection "Examples"
3066.PP
3067There are a number of principal ways to embed other event loops or modules
3068into libev. Here are some ideas on how to include libadns into libev
3069(there is a Perl module named \f(CW\*(C`EV::ADNS\*(C'\fR that does this, which you could
3070use as a working example. Another Perl module named \f(CW\*(C`EV::Glib\*(C'\fR embeds a
3071Glib main context into libev, and finally, \f(CW\*(C`Glib::EV\*(C'\fR embeds EV into the
3072Glib event loop).
3073.PP
3074Method 1: Add IO watchers and a timeout watcher in a prepare handler,
3075and in a check watcher, destroy them and call into libadns. What follows
3076is pseudo\-code only of course. This requires you to either use a low
3077priority for the check watcher or use \f(CW\*(C`ev_clear_pending\*(C'\fR explicitly, as
3078the callbacks for the IO/timeout watchers might not have been called yet.
3079.PP
3080.Vb 2
3081\& static ev_io iow [nfd];
3082\& static ev_timer tw;
3083\&
3084\& static void
3085\& io_cb (struct ev_loop *loop, ev_io *w, int revents)
3086\& {
3087\& }
3088\&
3089\& // create io watchers for each fd and a timer before blocking
3090\& static void
3091\& adns_prepare_cb (struct ev_loop *loop, ev_prepare *w, int revents)
3092\& {
3093\& int timeout = 3600000;
3094\& struct pollfd fds [nfd];
3095\& // actual code will need to loop here and realloc etc.
3096\& adns_beforepoll (ads, fds, &nfd, &timeout, timeval_from (ev_time ()));
3097\&
3098\& /* the callback is illegal, but won\*(Aqt be called as we stop during check */
3099\& ev_timer_init (&tw, 0, timeout * 1e\-3, 0.);
3100\& ev_timer_start (loop, &tw);
3101\&
3102\& // create one ev_io per pollfd
3103\& for (int i = 0; i < nfd; ++i)
3104\& {
3105\& ev_io_init (iow + i, io_cb, fds [i].fd,
3106\& ((fds [i].events & POLLIN ? EV_READ : 0)
3107\& | (fds [i].events & POLLOUT ? EV_WRITE : 0)));
3108\&
3109\& fds [i].revents = 0;
3110\& ev_io_start (loop, iow + i);
3111\& }
3112\& }
3113\&
3114\& // stop all watchers after blocking
3115\& static void
3116\& adns_check_cb (struct ev_loop *loop, ev_check *w, int revents)
3117\& {
3118\& ev_timer_stop (loop, &tw);
3119\&
3120\& for (int i = 0; i < nfd; ++i)
3121\& {
3122\& // set the relevant poll flags
3123\& // could also call adns_processreadable etc. here
3124\& struct pollfd *fd = fds + i;
3125\& int revents = ev_clear_pending (iow + i);
3126\& if (revents & EV_READ ) fd\->revents |= fd\->events & POLLIN;
3127\& if (revents & EV_WRITE) fd\->revents |= fd\->events & POLLOUT;
3128\&
3129\& // now stop the watcher
3130\& ev_io_stop (loop, iow + i);
3131\& }
3132\&
3133\& adns_afterpoll (adns, fds, nfd, timeval_from (ev_now (loop));
3134\& }
3135.Ve
3136.PP
3137Method 2: This would be just like method 1, but you run \f(CW\*(C`adns_afterpoll\*(C'\fR
3138in the prepare watcher and would dispose of the check watcher.
3139.PP
3140Method 3: If the module to be embedded supports explicit event
3141notification (libadns does), you can also make use of the actual watcher
3142callbacks, and only destroy/create the watchers in the prepare watcher.
3143.PP
3144.Vb 5
3145\& static void
3146\& timer_cb (EV_P_ ev_timer *w, int revents)
3147\& {
3148\& adns_state ads = (adns_state)w\->data;
3149\& update_now (EV_A);
3150\&
3151\& adns_processtimeouts (ads, &tv_now);
3152\& }
3153\&
3154\& static void
3155\& io_cb (EV_P_ ev_io *w, int revents)
3156\& {
3157\& adns_state ads = (adns_state)w\->data;
3158\& update_now (EV_A);
3159\&
3160\& if (revents & EV_READ ) adns_processreadable (ads, w\->fd, &tv_now);
3161\& if (revents & EV_WRITE) adns_processwriteable (ads, w\->fd, &tv_now);
3162\& }
3163\&
3164\& // do not ever call adns_afterpoll
3165.Ve
3166.PP
3167Method 4: Do not use a prepare or check watcher because the module you
3168want to embed is not flexible enough to support it. Instead, you can
3169override their poll function. The drawback with this solution is that the
3170main loop is now no longer controllable by EV. The \f(CW\*(C`Glib::EV\*(C'\fR module uses
3171this approach, effectively embedding EV as a client into the horrible
3172libglib event loop.
3173.PP
3174.Vb 4
3175\& static gint
3176\& event_poll_func (GPollFD *fds, guint nfds, gint timeout)
3177\& {
3178\& int got_events = 0;
3179\&
3180\& for (n = 0; n < nfds; ++n)
3181\& // create/start io watcher that sets the relevant bits in fds[n] and increment got_events
3182\&
3183\& if (timeout >= 0)
3184\& // create/start timer
3185\&
3186\& // poll
3187\& ev_run (EV_A_ 0);
3188\&
3189\& // stop timer again
3190\& if (timeout >= 0)
3191\& ev_timer_stop (EV_A_ &to);
3192\&
3193\& // stop io watchers again \- their callbacks should have set
3194\& for (n = 0; n < nfds; ++n)
3195\& ev_io_stop (EV_A_ iow [n]);
3196\&
3197\& return got_events;
3198\& }
3199.Ve
3200.ie n .SS """ev_embed"" \- when one backend isn\*(Aqt enough..."
3201.el .SS "\f(CWev_embed\fP \- when one backend isn\*(Aqt enough..."
3202.IX Subsection "ev_embed - when one backend isn't enough..."
3203This is a rather advanced watcher type that lets you embed one event loop
3204into another (currently only \f(CW\*(C`ev_io\*(C'\fR events are supported in the embedded
3205loop, other types of watchers might be handled in a delayed or incorrect
3206fashion and must not be used).
3207.PP
3208There are primarily two reasons you would want that: work around bugs and
3209prioritise I/O.
3210.PP
3211As an example for a bug workaround, the kqueue backend might only support
3212sockets on some platform, so it is unusable as generic backend, but you
3213still want to make use of it because you have many sockets and it scales
3214so nicely. In this case, you would create a kqueue\-based loop and embed
3215it into your default loop (which might use e.g. poll). Overall operation
3216will be a bit slower because first libev has to call \f(CW\*(C`poll\*(C'\fR and then
3217\&\f(CW\*(C`kevent\*(C'\fR, but at least you can use both mechanisms for what they are
3218best: \f(CW\*(C`kqueue\*(C'\fR for scalable sockets and \f(CW\*(C`poll\*(C'\fR if you want it to work :)
3219.PP
3220As for prioritising I/O: under rare circumstances you have the case where
3221some fds have to be watched and handled very quickly (with low latency),
3222and even priorities and idle watchers might have too much overhead. In
3223this case you would put all the high priority stuff in one loop and all
3224the rest in a second one, and embed the second one in the first.
3225.PP
3226As long as the watcher is active, the callback will be invoked every
3227time there might be events pending in the embedded loop. The callback
3228must then call \f(CW\*(C`ev_embed_sweep (mainloop, watcher)\*(C'\fR to make a single
3229sweep and invoke their callbacks (the callback doesn\*(Aqt need to invoke the
3230\&\f(CW\*(C`ev_embed_sweep\*(C'\fR function directly, it could also start an idle watcher
3231to give the embedded loop strictly lower priority for example).
3232.PP
3233You can also set the callback to \f(CW0\fR, in which case the embed watcher
3234will automatically execute the embedded loop sweep whenever necessary.
3235.PP
3236Fork detection will be handled transparently while the \f(CW\*(C`ev_embed\*(C'\fR watcher
3237is active, i.e., the embedded loop will automatically be forked when the
3238embedding loop forks. In other cases, the user is responsible for calling
3239\&\f(CW\*(C`ev_loop_fork\*(C'\fR on the embedded loop.
3240.PP
3241Unfortunately, not all backends are embeddable: only the ones returned by
3242\&\f(CW\*(C`ev_embeddable_backends\*(C'\fR are, which, unfortunately, does not include any
3243portable one.
3244.PP
3245So when you want to use this feature you will always have to be prepared
3246that you cannot get an embeddable loop. The recommended way to get around
3247this is to have a separate variables for your embeddable loop, try to
3248create it, and if that fails, use the normal loop for everything.
3249.PP
3250\fR\f(CI\*(C`ev_embed\*(C'\fR\fI and fork\fR
3251.IX Subsection "ev_embed and fork"
3252.PP
3253While the \f(CW\*(C`ev_embed\*(C'\fR watcher is running, forks in the embedding loop will
3254automatically be applied to the embedded loop as well, so no special
3255fork handling is required in that case. When the watcher is not running,
3256however, it is still the task of the libev user to call \f(CW\*(C`ev_loop_fork ()\*(C'\fR
3257as applicable.
3258.PP
3259\fIWatcher\-Specific Functions and Data Members\fR
3260.IX Subsection "Watcher-Specific Functions and Data Members"
3261.IP "ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)" 4
3262.IX Item "ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)"
3263.PD 0
3264.IP "ev_embed_set (ev_embed *, struct ev_loop *embedded_loop)" 4
3265.IX Item "ev_embed_set (ev_embed *, struct ev_loop *embedded_loop)"
3266.PD
3267Configures the watcher to embed the given loop, which must be
3268embeddable. If the callback is \f(CW0\fR, then \f(CW\*(C`ev_embed_sweep\*(C'\fR will be
3269invoked automatically, otherwise it is the responsibility of the callback
3270to invoke it (it will continue to be called until the sweep has been done,
3271if you do not want that, you need to temporarily stop the embed watcher).
3272.IP "ev_embed_sweep (loop, ev_embed *)" 4
3273.IX Item "ev_embed_sweep (loop, ev_embed *)"
3274Make a single, non\-blocking sweep over the embedded loop. This works
3275similarly to \f(CW\*(C`ev_run (embedded_loop, EVRUN_NOWAIT)\*(C'\fR, but in the most
3276appropriate way for embedded loops.
3277.IP "struct ev_loop *other [read\-only]" 4
3278.IX Item "struct ev_loop *other [read-only]"
3279The embedded event loop.
3280.PP
3281\fIExamples\fR
3282.IX Subsection "Examples"
3283.PP
3284Example: Try to get an embeddable event loop and embed it into the default
3285event loop. If that is not possible, use the default loop. The default
3286loop is stored in \f(CW\*(C`loop_hi\*(C'\fR, while the embeddable loop is stored in
3287\&\f(CW\*(C`loop_lo\*(C'\fR (which is \f(CW\*(C`loop_hi\*(C'\fR in the case no embeddable loop can be
3288used).
3289.PP
3290.Vb 3
3291\& struct ev_loop *loop_hi = ev_default_init (0);
3292\& struct ev_loop *loop_lo = 0;
3293\& ev_embed embed;
3294\&
3295\& // see if there is a chance of getting one that works
3296\& // (remember that a flags value of 0 means autodetection)
3297\& loop_lo = ev_embeddable_backends () & ev_recommended_backends ()
3298\& ? ev_loop_new (ev_embeddable_backends () & ev_recommended_backends ())
3299\& : 0;
3300\&
3301\& // if we got one, then embed it, otherwise default to loop_hi
3302\& if (loop_lo)
3303\& {
3304\& ev_embed_init (&embed, 0, loop_lo);
3305\& ev_embed_start (loop_hi, &embed);
3306\& }
3307\& else
3308\& loop_lo = loop_hi;
3309.Ve
3310.PP
3311Example: Check if kqueue is available but not recommended and create
3312a kqueue backend for use with sockets (which usually work with any
3313kqueue implementation). Store the kqueue/socket\-only event loop in
3314\&\f(CW\*(C`loop_socket\*(C'\fR. (One might optionally use \f(CW\*(C`EVFLAG_NOENV\*(C'\fR, too).
3315.PP
3316.Vb 3
3317\& struct ev_loop *loop = ev_default_init (0);
3318\& struct ev_loop *loop_socket = 0;
3319\& ev_embed embed;
3320\&
3321\& if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE)
3322\& if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE))
3323\& {
3324\& ev_embed_init (&embed, 0, loop_socket);
3325\& ev_embed_start (loop, &embed);
3326\& }
3327\&
3328\& if (!loop_socket)
3329\& loop_socket = loop;
3330\&
3331\& // now use loop_socket for all sockets, and loop for everything else
3332.Ve
3333.ie n .SS """ev_fork"" \- the audacity to resume the event loop after a fork"
3334.el .SS "\f(CWev_fork\fP \- the audacity to resume the event loop after a fork"
3335.IX Subsection "ev_fork - the audacity to resume the event loop after a fork"
3336Fork watchers are called when a \f(CW\*(C`fork ()\*(C'\fR was detected (usually because
3337whoever is a good citizen cared to tell libev about it by calling
3338\&\f(CW\*(C`ev_loop_fork\*(C'\fR). The invocation is done before the event loop blocks next
3339and before \f(CW\*(C`ev_check\*(C'\fR watchers are being called, and only in the child
3340after the fork. If whoever good citizen calling \f(CW\*(C`ev_default_fork\*(C'\fR cheats
3341and calls it in the wrong process, the fork handlers will be invoked, too,
3342of course.
3343.PP
3344\fIThe special problem of life after fork \- how is it possible?\fR
3345.IX Subsection "The special problem of life after fork - how is it possible?"
3346.PP
3347Most uses of \f(CW\*(C`fork ()\*(C'\fR consist of forking, then some simple calls to set
3348up/change the process environment, followed by a call to \f(CWexec()\fR. This
3349sequence should be handled by libev without any problems.
3350.PP
3351This changes when the application actually wants to do event handling
3352in the child, or both parent in child, in effect "continuing" after the
3353fork.
3354.PP
3355The default mode of operation (for libev, with application help to detect
3356forks) is to duplicate all the state in the child, as would be expected
3357when \fIeither\fR the parent \fIor\fR the child process continues.
3358.PP
3359When both processes want to continue using libev, then this is usually the
3360wrong result. In that case, usually one process (typically the parent) is
3361supposed to continue with all watchers in place as before, while the other
3362process typically wants to start fresh, i.e. without any active watchers.
3363.PP
3364The cleanest and most efficient way to achieve that with libev is to
3365simply create a new event loop, which of course will be "empty", and
3366use that for new watchers. This has the advantage of not touching more
3367memory than necessary, and thus avoiding the copy\-on\-write, and the
3368disadvantage of having to use multiple event loops (which do not support
3369signal watchers).
3370.PP
3371When this is not possible, or you want to use the default loop for
3372other reasons, then in the process that wants to start "fresh", call
3373\&\f(CW\*(C`ev_loop_destroy (EV_DEFAULT)\*(C'\fR followed by \f(CW\*(C`ev_default_loop (...)\*(C'\fR.
3374Destroying the default loop will "orphan" (not stop) all registered
3375watchers, so you have to be careful not to execute code that modifies
3376those watchers. Note also that in that case, you have to re\-register any
3377signal watchers.
3378.PP
3379\fIWatcher\-Specific Functions and Data Members\fR
3380.IX Subsection "Watcher-Specific Functions and Data Members"
3381.IP "ev_fork_init (ev_fork *, callback)" 4
3382.IX Item "ev_fork_init (ev_fork *, callback)"
3383Initialises and configures the fork watcher \- it has no parameters of any
3384kind. There is a \f(CW\*(C`ev_fork_set\*(C'\fR macro, but using it is utterly pointless,
3385really.
3386.ie n .SS """ev_cleanup"" \- even the best things end"
3387.el .SS "\f(CWev_cleanup\fP \- even the best things end"
3388.IX Subsection "ev_cleanup - even the best things end"
3389Cleanup watchers are called just before the event loop is being destroyed
3390by a call to \f(CW\*(C`ev_loop_destroy\*(C'\fR.
3391.PP
3392While there is no guarantee that the event loop gets destroyed, cleanup
3393watchers provide a convenient method to install cleanup hooks for your
3394program, worker threads and so on \- you just to make sure to destroy the
3395loop when you want them to be invoked.
3396.PP
3397Cleanup watchers are invoked in the same way as any other watcher. Unlike
3398all other watchers, they do not keep a reference to the event loop (which
3399makes a lot of sense if you think about it). Like all other watchers, you
3400can call libev functions in the callback, except \f(CW\*(C`ev_cleanup_start\*(C'\fR.
3401.PP
3402\fIWatcher\-Specific Functions and Data Members\fR
3403.IX Subsection "Watcher-Specific Functions and Data Members"
3404.IP "ev_cleanup_init (ev_cleanup *, callback)" 4
3405.IX Item "ev_cleanup_init (ev_cleanup *, callback)"
3406Initialises and configures the cleanup watcher \- it has no parameters of
3407any kind. There is a \f(CW\*(C`ev_cleanup_set\*(C'\fR macro, but using it is utterly
3408pointless, I assure you.
3409.PP
3410Example: Register an atexit handler to destroy the default loop, so any
3411cleanup functions are called.
3412.PP
3413.Vb 5
3414\& static void
3415\& program_exits (void)
3416\& {
3417\& ev_loop_destroy (EV_DEFAULT_UC);
3418\& }
3419\&
3420\& ...
3421\& atexit (program_exits);
3422.Ve
3423.ie n .SS """ev_async"" \- how to wake up an event loop"
3424.el .SS "\f(CWev_async\fP \- how to wake up an event loop"
3425.IX Subsection "ev_async - how to wake up an event loop"
3426In general, you cannot use an \f(CW\*(C`ev_loop\*(C'\fR from multiple threads or other
3427asynchronous sources such as signal handlers (as opposed to multiple event
3428loops \- those are of course safe to use in different threads).
3429.PP
3430Sometimes, however, you need to wake up an event loop you do not control,
3431for example because it belongs to another thread. This is what \f(CW\*(C`ev_async\*(C'\fR
3432watchers do: as long as the \f(CW\*(C`ev_async\*(C'\fR watcher is active, you can signal
3433it by calling \f(CW\*(C`ev_async_send\*(C'\fR, which is thread\- and signal safe.
3434.PP
3435This functionality is very similar to \f(CW\*(C`ev_signal\*(C'\fR watchers, as signals,
3436too, are asynchronous in nature, and signals, too, will be compressed
3437(i.e. the number of callback invocations may be less than the number of
3438\&\f(CW\*(C`ev_async_send\*(C'\fR calls). In fact, you could use signal watchers as a kind
3439of "global async watchers" by using a watcher on an otherwise unused
3440signal, and \f(CW\*(C`ev_feed_signal\*(C'\fR to signal this watcher from another thread,
3441even without knowing which loop owns the signal.
3442.PP
3443\fIQueueing\fR
3444.IX Subsection "Queueing"
3445.PP
3446\&\f(CW\*(C`ev_async\*(C'\fR does not support queueing of data in any way. The reason
3447is that the author does not know of a simple (or any) algorithm for a
3448multiple\-writer\-single\-reader queue that works in all cases and doesn\*(Aqt
3449need elaborate support such as pthreads or unportable memory access
3450semantics.
3451.PP
3452That means that if you want to queue data, you have to provide your own
3453queue. But at least I can tell you how to implement locking around your
3454queue:
3455.IP "queueing from a signal handler context" 4
3456.IX Item "queueing from a signal handler context"
3457To implement race\-free queueing, you simply add to the queue in the signal
3458handler but you block the signal handler in the watcher callback. Here is
3459an example that does that for some fictitious SIGUSR1 handler:
3460.Sp
3461.Vb 1
3462\& static ev_async mysig;
3463\&
3464\& static void
3465\& sigusr1_handler (void)
3466\& {
3467\& sometype data;
3468\&
3469\& // no locking etc.
3470\& queue_put (data);
3471\& ev_async_send (EV_DEFAULT_ &mysig);
3472\& }
3473\&
3474\& static void
3475\& mysig_cb (EV_P_ ev_async *w, int revents)
3476\& {
3477\& sometype data;
3478\& sigset_t block, prev;
3479\&
3480\& sigemptyset (&block);
3481\& sigaddset (&block, SIGUSR1);
3482\& sigprocmask (SIG_BLOCK, &block, &prev);
3483\&
3484\& while (queue_get (&data))
3485\& process (data);
3486\&
3487\& if (sigismember (&prev, SIGUSR1)
3488\& sigprocmask (SIG_UNBLOCK, &block, 0);
3489\& }
3490.Ve
3491.Sp
3492(Note: pthreads in theory requires you to use \f(CW\*(C`pthread_setmask\*(C'\fR
3493instead of \f(CW\*(C`sigprocmask\*(C'\fR when you use threads, but libev doesn\*(Aqt do it
3494either...).
3495.IP "queueing from a thread context" 4
3496.IX Item "queueing from a thread context"
3497The strategy for threads is different, as you cannot (easily) block
3498threads but you can easily preempt them, so to queue safely you need to
3499employ a traditional mutex lock, such as in this pthread example:
3500.Sp
3501.Vb 2
3502\& static ev_async mysig;
3503\& static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
3504\&
3505\& static void
3506\& otherthread (void)
3507\& {
3508\& // only need to lock the actual queueing operation
3509\& pthread_mutex_lock (&mymutex);
3510\& queue_put (data);
3511\& pthread_mutex_unlock (&mymutex);
3512\&
3513\& ev_async_send (EV_DEFAULT_ &mysig);
3514\& }
3515\&
3516\& static void
3517\& mysig_cb (EV_P_ ev_async *w, int revents)
3518\& {
3519\& pthread_mutex_lock (&mymutex);
3520\&
3521\& while (queue_get (&data))
3522\& process (data);
3523\&
3524\& pthread_mutex_unlock (&mymutex);
3525\& }
3526.Ve
3527.PP
3528\fIWatcher\-Specific Functions and Data Members\fR
3529.IX Subsection "Watcher-Specific Functions and Data Members"
3530.IP "ev_async_init (ev_async *, callback)" 4
3531.IX Item "ev_async_init (ev_async *, callback)"
3532Initialises and configures the async watcher \- it has no parameters of any
3533kind. There is a \f(CW\*(C`ev_async_set\*(C'\fR macro, but using it is utterly pointless,
3534trust me.
3535.IP "ev_async_send (loop, ev_async *)" 4
3536.IX Item "ev_async_send (loop, ev_async *)"
3537Sends/signals/activates the given \f(CW\*(C`ev_async\*(C'\fR watcher, that is, feeds
3538an \f(CW\*(C`EV_ASYNC\*(C'\fR event on the watcher into the event loop, and instantly
3539returns.
3540.Sp
3541Unlike \f(CW\*(C`ev_feed_event\*(C'\fR, this call is safe to do from other threads,
3542signal or similar contexts (see the discussion of \f(CW\*(C`EV_ATOMIC_T\*(C'\fR in the
3543embedding section below on what exactly this means).
3544.Sp
3545Note that, as with other watchers in libev, multiple events might get
3546compressed into a single callback invocation (another way to look at
3547this is that \f(CW\*(C`ev_async\*(C'\fR watchers are level\-triggered: they are set on
3548\&\f(CW\*(C`ev_async_send\*(C'\fR, reset when the event loop detects that).
3549.Sp
3550This call incurs the overhead of at most one extra system call per event
3551loop iteration, if the event loop is blocked, and no syscall at all if
3552the event loop (or your program) is processing events. That means that
3553repeated calls are basically free (there is no need to avoid calls for
3554performance reasons) and that the overhead becomes smaller (typically
3555zero) under load.
3556.IP "bool = ev_async_pending (ev_async *)" 4
3557.IX Item "bool = ev_async_pending (ev_async *)"
3558Returns a non\-zero value when \f(CW\*(C`ev_async_send\*(C'\fR has been called on the
3559watcher but the event has not yet been processed (or even noted) by the
3560event loop.
3561.Sp
3562\&\f(CW\*(C`ev_async_send\*(C'\fR sets a flag in the watcher and wakes up the loop. When
3563the loop iterates next and checks for the watcher to have become active,
3564it will reset the flag again. \f(CW\*(C`ev_async_pending\*(C'\fR can be used to very
3565quickly check whether invoking the loop might be a good idea.
3566.Sp
3567Not that this does \fInot\fR check whether the watcher itself is pending,
3568only whether it has been requested to make this watcher pending: there
3569is a time window between the event loop checking and resetting the async
3570notification, and the callback being invoked.
3571.SH "OTHER FUNCTIONS"
3572.IX Header "OTHER FUNCTIONS"
3573There are some other functions of possible interest. Described. Here. Now.
3574.IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4
3575.IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)"
3576This function combines a simple timer and an I/O watcher, calls your
3577callback on whichever event happens first and automatically stops both
3578watchers. This is useful if you want to wait for a single event on an fd
3579or timeout without having to allocate/configure/start/stop/free one or
3580more watchers yourself.
3581.Sp
3582If \f(CW\*(C`fd\*(C'\fR is less than 0, then no I/O watcher will be started and the
3583\&\f(CW\*(C`events\*(C'\fR argument is being ignored. Otherwise, an \f(CW\*(C`ev_io\*(C'\fR watcher for
3584the given \f(CW\*(C`fd\*(C'\fR and \f(CW\*(C`events\*(C'\fR set will be created and started.
3585.Sp
3586If \f(CW\*(C`timeout\*(C'\fR is less than 0, then no timeout watcher will be
3587started. Otherwise an \f(CW\*(C`ev_timer\*(C'\fR watcher with after = \f(CW\*(C`timeout\*(C'\fR (and
3588repeat = 0) will be started. \f(CW0\fR is a valid timeout.
3589.Sp
3590The callback has the type \f(CW\*(C`void (*cb)(int revents, void *arg)\*(C'\fR and is
3591passed an \f(CW\*(C`revents\*(C'\fR set like normal event callbacks (a combination of
3592\&\f(CW\*(C`EV_ERROR\*(C'\fR, \f(CW\*(C`EV_READ\*(C'\fR, \f(CW\*(C`EV_WRITE\*(C'\fR or \f(CW\*(C`EV_TIMER\*(C'\fR) and the \f(CW\*(C`arg\*(C'\fR
3593value passed to \f(CW\*(C`ev_once\*(C'\fR. Note that it is possible to receive \fIboth\fR
3594a timeout and an io event at the same time \- you probably should give io
3595events precedence.
3596.Sp
3597Example: wait up to ten seconds for data to appear on STDIN_FILENO.
3598.Sp
3599.Vb 7
3600\& static void stdin_ready (int revents, void *arg)
3601\& {
3602\& if (revents & EV_READ)
3603\& /* stdin might have data for us, joy! */;
3604\& else if (revents & EV_TIMER)
3605\& /* doh, nothing entered */;
3606\& }
3607\&
3608\& ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0);
3609.Ve
3610.IP "ev_feed_fd_event (loop, int fd, int revents)" 4
3611.IX Item "ev_feed_fd_event (loop, int fd, int revents)"
3612Feed an event on the given fd, as if a file descriptor backend detected
3613the given events.
3614.IP "ev_feed_signal_event (loop, int signum)" 4
3615.IX Item "ev_feed_signal_event (loop, int signum)"
3616Feed an event as if the given signal occurred. See also \f(CW\*(C`ev_feed_signal\*(C'\fR,
3617which is async\-safe.
3618.SH "COMMON OR USEFUL IDIOMS (OR BOTH)"
3619.IX Header "COMMON OR USEFUL IDIOMS (OR BOTH)"
3620This section explains some common idioms that are not immediately
3621obvious. Note that examples are sprinkled over the whole manual, and this
3622section only contains stuff that wouldn\*(Aqt fit anywhere else.
3623.SS "ASSOCIATING CUSTOM DATA WITH A WATCHER"
3624.IX Subsection "ASSOCIATING CUSTOM DATA WITH A WATCHER"
3625Each watcher has, by default, a \f(CW\*(C`void *data\*(C'\fR member that you can read
3626or modify at any time: libev will completely ignore it. This can be used
3627to associate arbitrary data with your watcher. If you need more data and
3628don\*(Aqt want to allocate memory separately and store a pointer to it in that
3629data member, you can also "subclass" the watcher type and provide your own
3630data:
3631.PP
3632.Vb 7
3633\& struct my_io
3634\& {
3635\& ev_io io;
3636\& int otherfd;
3637\& void *somedata;
3638\& struct whatever *mostinteresting;
3639\& };
3640\&
3641\& ...
3642\& struct my_io w;
3643\& ev_io_init (&w.io, my_cb, fd, EV_READ);
3644.Ve
3645.PP
3646And since your callback will be called with a pointer to the watcher, you
3647can cast it back to your own type:
3648.PP
3649.Vb 5
3650\& static void my_cb (struct ev_loop *loop, ev_io *w_, int revents)
3651\& {
3652\& struct my_io *w = (struct my_io *)w_;
3653\& ...
3654\& }
3655.Ve
3656.PP
3657More interesting and less C\-conformant ways of casting your callback
3658function type instead have been omitted.
3659.SS "BUILDING YOUR OWN COMPOSITE WATCHERS"
3660.IX Subsection "BUILDING YOUR OWN COMPOSITE WATCHERS"
3661Another common scenario is to use some data structure with multiple
3662embedded watchers, in effect creating your own watcher that combines
3663multiple libev event sources into one "super\-watcher":
3664.PP
3665.Vb 6
3666\& struct my_biggy
3667\& {
3668\& int some_data;
3669\& ev_timer t1;
3670\& ev_timer t2;
3671\& }
3672.Ve
3673.PP
3674In this case getting the pointer to \f(CW\*(C`my_biggy\*(C'\fR is a bit more
3675complicated: Either you store the address of your \f(CW\*(C`my_biggy\*(C'\fR struct in
3676the \f(CW\*(C`data\*(C'\fR member of the watcher (for woozies or C++ coders), or you need
3677to use some pointer arithmetic using \f(CW\*(C`offsetof\*(C'\fR inside your watchers (for
3678real programmers):
3679.PP
3680.Vb 1
3681\& #include <stddef.h>
3682\&
3683\& static void
3684\& t1_cb (EV_P_ ev_timer *w, int revents)
3685\& {
3686\& struct my_biggy big = (struct my_biggy *)
3687\& (((char *)w) \- offsetof (struct my_biggy, t1));
3688\& }
3689\&
3690\& static void
3691\& t2_cb (EV_P_ ev_timer *w, int revents)
3692\& {
3693\& struct my_biggy big = (struct my_biggy *)
3694\& (((char *)w) \- offsetof (struct my_biggy, t2));
3695\& }
3696.Ve
3697.SS "AVOIDING FINISHING BEFORE RETURNING"
3698.IX Subsection "AVOIDING FINISHING BEFORE RETURNING"
3699Often you have structures like this in event\-based programs:
3700.PP
3701.Vb 4
3702\& callback ()
3703\& {
3704\& free (request);
3705\& }
3706\&
3707\& request = start_new_request (..., callback);
3708.Ve
3709.PP
3710The intent is to start some "lengthy" operation. The \f(CW\*(C`request\*(C'\fR could be
3711used to cancel the operation, or do other things with it.
3712.PP
3713It\*(Aqs not uncommon to have code paths in \f(CW\*(C`start_new_request\*(C'\fR that
3714immediately invoke the callback, for example, to report errors. Or you add
3715some caching layer that finds that it can skip the lengthy aspects of the
3716operation and simply invoke the callback with the result.
3717.PP
3718The problem here is that this will happen \fIbefore\fR \f(CW\*(C`start_new_request\*(C'\fR
3719has returned, so \f(CW\*(C`request\*(C'\fR is not set.
3720.PP
3721Even if you pass the request by some safer means to the callback, you
3722might want to do something to the request after starting it, such as
3723canceling it, which probably isn\*(Aqt working so well when the callback has
3724already been invoked.
3725.PP
3726A common way around all these issues is to make sure that
3727\&\f(CW\*(C`start_new_request\*(C'\fR \fIalways\fR returns before the callback is invoked. If
3728\&\f(CW\*(C`start_new_request\*(C'\fR immediately knows the result, it can artificially
3729delay invoking the callback by using a \f(CW\*(C`prepare\*(C'\fR or \f(CW\*(C`idle\*(C'\fR watcher for
3730example, or more sneakily, by reusing an existing (stopped) watcher and
3731pushing it into the pending queue:
3732.PP
3733.Vb 2
3734\& ev_set_cb (watcher, callback);
3735\& ev_feed_event (EV_A_ watcher, 0);
3736.Ve
3737.PP
3738This way, \f(CW\*(C`start_new_request\*(C'\fR can safely return before the callback is
3739invoked, while not delaying callback invocation too much.
3740.SS "MODEL/NESTED EVENT LOOP INVOCATIONS AND EXIT CONDITIONS"
3741.IX Subsection "MODEL/NESTED EVENT LOOP INVOCATIONS AND EXIT CONDITIONS"
3742Often (especially in GUI toolkits) there are places where you have
3743\&\fImodal\fR interaction, which is most easily implemented by recursively
3744invoking \f(CW\*(C`ev_run\*(C'\fR.
3745.PP
3746This brings the problem of exiting \- a callback might want to finish the
3747main \f(CW\*(C`ev_run\*(C'\fR call, but not the nested one (e.g. user clicked "Quit", but
3748a modal "Are you sure?" dialog is still waiting), or just the nested one
3749and not the main one (e.g. user clocked "Ok" in a modal dialog), or some
3750other combination: In these cases, a simple \f(CW\*(C`ev_break\*(C'\fR will not work.
3751.PP
3752The solution is to maintain "break this loop" variable for each \f(CW\*(C`ev_run\*(C'\fR
3753invocation, and use a loop around \f(CW\*(C`ev_run\*(C'\fR until the condition is
3754triggered, using \f(CW\*(C`EVRUN_ONCE\*(C'\fR:
3755.PP
3756.Vb 2
3757\& // main loop
3758\& int exit_main_loop = 0;
3759\&
3760\& while (!exit_main_loop)
3761\& ev_run (EV_DEFAULT_ EVRUN_ONCE);
3762\&
3763\& // in a modal watcher
3764\& int exit_nested_loop = 0;
3765\&
3766\& while (!exit_nested_loop)
3767\& ev_run (EV_A_ EVRUN_ONCE);
3768.Ve
3769.PP
3770To exit from any of these loops, just set the corresponding exit variable:
3771.PP
3772.Vb 2
3773\& // exit modal loop
3774\& exit_nested_loop = 1;
3775\&
3776\& // exit main program, after modal loop is finished
3777\& exit_main_loop = 1;
3778\&
3779\& // exit both
3780\& exit_main_loop = exit_nested_loop = 1;
3781.Ve
3782.SS "THREAD LOCKING EXAMPLE"
3783.IX Subsection "THREAD LOCKING EXAMPLE"
3784Here is a fictitious example of how to run an event loop in a different
3785thread from where callbacks are being invoked and watchers are
3786created/added/removed.
3787.PP
3788For a real\-world example, see the \f(CW\*(C`EV::Loop::Async\*(C'\fR perl module,
3789which uses exactly this technique (which is suited for many high\-level
3790languages).
3791.PP
3792The example uses a pthread mutex to protect the loop data, a condition
3793variable to wait for callback invocations, an async watcher to notify the
3794event loop thread and an unspecified mechanism to wake up the main thread.
3795.PP
3796First, you need to associate some data with the event loop:
3797.PP
3798.Vb 6
3799\& typedef struct {
3800\& mutex_t lock; /* global loop lock */
3801\& ev_async async_w;
3802\& thread_t tid;
3803\& cond_t invoke_cv;
3804\& } userdata;
3805\&
3806\& void prepare_loop (EV_P)
3807\& {
3808\& // for simplicity, we use a static userdata struct.
3809\& static userdata u;
3810\&
3811\& ev_async_init (&u\->async_w, async_cb);
3812\& ev_async_start (EV_A_ &u\->async_w);
3813\&
3814\& pthread_mutex_init (&u\->lock, 0);
3815\& pthread_cond_init (&u\->invoke_cv, 0);
3816\&
3817\& // now associate this with the loop
3818\& ev_set_userdata (EV_A_ u);
3819\& ev_set_invoke_pending_cb (EV_A_ l_invoke);
3820\& ev_set_loop_release_cb (EV_A_ l_release, l_acquire);
3821\&
3822\& // then create the thread running ev_run
3823\& pthread_create (&u\->tid, 0, l_run, EV_A);
3824\& }
3825.Ve
3826.PP
3827The callback for the \f(CW\*(C`ev_async\*(C'\fR watcher does nothing: the watcher is used
3828solely to wake up the event loop so it takes notice of any new watchers
3829that might have been added:
3830.PP
3831.Vb 5
3832\& static void
3833\& async_cb (EV_P_ ev_async *w, int revents)
3834\& {
3835\& // just used for the side effects
3836\& }
3837.Ve
3838.PP
3839The \f(CW\*(C`l_release\*(C'\fR and \f(CW\*(C`l_acquire\*(C'\fR callbacks simply unlock/lock the mutex
3840protecting the loop data, respectively.
3841.PP
3842.Vb 6
3843\& static void
3844\& l_release (EV_P)
3845\& {
3846\& userdata *u = ev_userdata (EV_A);
3847\& pthread_mutex_unlock (&u\->lock);
3848\& }
3849\&
3850\& static void
3851\& l_acquire (EV_P)
3852\& {
3853\& userdata *u = ev_userdata (EV_A);
3854\& pthread_mutex_lock (&u\->lock);
3855\& }
3856.Ve
3857.PP
3858The event loop thread first acquires the mutex, and then jumps straight
3859into \f(CW\*(C`ev_run\*(C'\fR:
3860.PP
3861.Vb 4
3862\& void *
3863\& l_run (void *thr_arg)
3864\& {
3865\& struct ev_loop *loop = (struct ev_loop *)thr_arg;
3866\&
3867\& l_acquire (EV_A);
3868\& pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
3869\& ev_run (EV_A_ 0);
3870\& l_release (EV_A);
3871\&
3872\& return 0;
3873\& }
3874.Ve
3875.PP
3876Instead of invoking all pending watchers, the \f(CW\*(C`l_invoke\*(C'\fR callback will
3877signal the main thread via some unspecified mechanism (signals? pipe
3878writes? \f(CW\*(C`Async::Interrupt\*(C'\fR?) and then waits until all pending watchers
3879have been called (in a while loop because a) spurious wakeups are possible
3880and b) skipping inter\-thread\-communication when there are no pending
3881watchers is very beneficial):
3882.PP
3883.Vb 4
3884\& static void
3885\& l_invoke (EV_P)
3886\& {
3887\& userdata *u = ev_userdata (EV_A);
3888\&
3889\& while (ev_pending_count (EV_A))
3890\& {
3891\& wake_up_other_thread_in_some_magic_or_not_so_magic_way ();
3892\& pthread_cond_wait (&u\->invoke_cv, &u\->lock);
3893\& }
3894\& }
3895.Ve
3896.PP
3897Now, whenever the main thread gets told to invoke pending watchers, it
3898will grab the lock, call \f(CW\*(C`ev_invoke_pending\*(C'\fR and then signal the loop
3899thread to continue:
3900.PP
3901.Vb 4
3902\& static void
3903\& real_invoke_pending (EV_P)
3904\& {
3905\& userdata *u = ev_userdata (EV_A);
3906\&
3907\& pthread_mutex_lock (&u\->lock);
3908\& ev_invoke_pending (EV_A);
3909\& pthread_cond_signal (&u\->invoke_cv);
3910\& pthread_mutex_unlock (&u\->lock);
3911\& }
3912.Ve
3913.PP
3914Whenever you want to start/stop a watcher or do other modifications to an
3915event loop, you will now have to lock:
3916.PP
3917.Vb 2
3918\& ev_timer timeout_watcher;
3919\& userdata *u = ev_userdata (EV_A);
3920\&
3921\& ev_timer_init (&timeout_watcher, timeout_cb, 5.5, 0.);
3922\&
3923\& pthread_mutex_lock (&u\->lock);
3924\& ev_timer_start (EV_A_ &timeout_watcher);
3925\& ev_async_send (EV_A_ &u\->async_w);
3926\& pthread_mutex_unlock (&u\->lock);
3927.Ve
3928.PP
3929Note that sending the \f(CW\*(C`ev_async\*(C'\fR watcher is required because otherwise
3930an event loop currently blocking in the kernel will have no knowledge
3931about the newly added timer. By waking up the loop it will pick up any new
3932watchers in the next event loop iteration.
3933.SS "THREADS, COROUTINES, CONTINUATIONS, QUEUES... INSTEAD OF CALLBACKS"
3934.IX Subsection "THREADS, COROUTINES, CONTINUATIONS, QUEUES... INSTEAD OF CALLBACKS"
3935While the overhead of a callback that e.g. schedules a thread is small, it
3936is still an overhead. If you embed libev, and your main usage is with some
3937kind of threads or coroutines, you might want to customise libev so that
3938doesn\*(Aqt need callbacks anymore.
3939.PP
3940Imagine you have coroutines that you can switch to using a function
3941\&\f(CW\*(C`switch_to (coro)\*(C'\fR, that libev runs in a coroutine called \f(CW\*(C`libev_coro\*(C'\fR
3942and that due to some magic, the currently active coroutine is stored in a
3943global called \f(CW\*(C`current_coro\*(C'\fR. Then you can build your own "wait for libev
3944event" primitive by changing \f(CW\*(C`EV_CB_DECLARE\*(C'\fR and \f(CW\*(C`EV_CB_INVOKE\*(C'\fR (note
3945the differing \f(CW\*(C`;\*(C'\fR conventions):
3946.PP
3947.Vb 2
3948\& #define EV_CB_DECLARE(type) struct my_coro *cb;
3949\& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb)
3950.Ve
3951.PP
3952That means instead of having a C callback function, you store the
3953coroutine to switch to in each watcher, and instead of having libev call
3954your callback, you instead have it switch to that coroutine.
3955.PP
3956A coroutine might now wait for an event with a function called
3957\&\f(CW\*(C`wait_for_event\*(C'\fR. (the watcher needs to be started, as always, but it doesn\*(Aqt
3958matter when, or whether the watcher is active or not when this function is
3959called):
3960.PP
3961.Vb 6
3962\& void
3963\& wait_for_event (ev_watcher *w)
3964\& {
3965\& ev_set_cb (w, current_coro);
3966\& switch_to (libev_coro);
3967\& }
3968.Ve
3969.PP
3970That basically suspends the coroutine inside \f(CW\*(C`wait_for_event\*(C'\fR and
3971continues the libev coroutine, which, when appropriate, switches back to
3972this or any other coroutine.
3973.PP
3974You can do similar tricks if you have, say, threads with an event queue \-
3975instead of storing a coroutine, you store the queue object and instead of
3976switching to a coroutine, you push the watcher onto the queue and notify
3977any waiters.
3978.PP
3979To embed libev, see "EMBEDDING", but in short, it\*(Aqs easiest to create two
3980files, \fImy_ev.h\fR and \fImy_ev.c\fR that include the respective libev files:
3981.PP
3982.Vb 4
3983\& // my_ev.h
3984\& #define EV_CB_DECLARE(type) struct my_coro *cb;
3985\& #define EV_CB_INVOKE(watcher) switch_to ((watcher)\->cb)
3986\& #include "../libev/ev.h"
3987\&
3988\& // my_ev.c
3989\& #define EV_H "my_ev.h"
3990\& #include "../libev/ev.c"
3991.Ve
3992.PP
3993And then use \fImy_ev.h\fR when you would normally use \fIev.h\fR, and compile
3994\&\fImy_ev.c\fR into your project. When properly specifying include paths, you
3995can even use \fIev.h\fR as header file name directly.
3996.SH "LIBEVENT EMULATION"
3997.IX Header "LIBEVENT EMULATION"
3998Libev offers a compatibility emulation layer for libevent. It cannot
3999emulate the internals of libevent, so here are some usage hints:
4000.IP \(bu 4
4001Only the libevent\-1.4.1\-beta API is being emulated.
4002.Sp
4003This was the newest libevent version available when libev was implemented,
4004and is still mostly unchanged in 2010.
4005.IP \(bu 4
4006Use it by including <event.h>, as usual.
4007.IP \(bu 4
4008The following members are fully supported: ev_base, ev_callback,
4009ev_arg, ev_fd, ev_res, ev_events.
4010.IP \(bu 4
4011Avoid using ev_flags and the EVLIST_*\-macros, while it is
4012maintained by libev, it does not work exactly the same way as in libevent (consider
4013it a private API).
4014.IP \(bu 4
4015Priorities are not currently supported. Initialising priorities
4016will fail and all watchers will have the same priority, even though there
4017is an ev_pri field.
4018.IP \(bu 4
4019In libevent, the last base created gets the signals, in libev, the
4020base that registered the signal gets the signals.
4021.IP \(bu 4
4022Other members are not supported.
4023.IP \(bu 4
4024The libev emulation is \fInot\fR ABI compatible to libevent, you need
4025to use the libev header file and library.
4026.SH "C++ SUPPORT"
4027.IX Header "C++ SUPPORT"
4028.SS "C API"
4029.IX Subsection "C API"
4030The normal C API should work fine when used from C++: both ev.h and the
4031libev sources can be compiled as C++. Therefore, code that uses the C API
4032will work fine.
4033.PP
4034Proper exception specifications might have to be added to callbacks passed
4035to libev: exceptions may be thrown only from watcher callbacks, all
4036other callbacks (allocator, syserr, loop acquire/release and periodic
4037reschedule callbacks) must not throw exceptions, and might need a \f(CW\*(C`throw
4038()\*(C'\fR specification. If you have code that needs to be compiled as both C
4039and C++ you can use the \f(CW\*(C`EV_THROW\*(C'\fR macro for this:
4040.PP
4041.Vb 6
4042\& static void
4043\& fatal_error (const char *msg) EV_THROW
4044\& {
4045\& perror (msg);
4046\& abort ();
4047\& }
4048\&
4049\& ...
4050\& ev_set_syserr_cb (fatal_error);
4051.Ve
4052.PP
4053The only API functions that can currently throw exceptions are \f(CW\*(C`ev_run\*(C'\fR,
4054\&\f(CW\*(C`ev_invoke\*(C'\fR, \f(CW\*(C`ev_invoke_pending\*(C'\fR and \f(CW\*(C`ev_loop_destroy\*(C'\fR (the latter
4055because it runs cleanup watchers).
4056.PP
4057Throwing exceptions in watcher callbacks is only supported if libev itself
4058is compiled with a C++ compiler or your C and C++ environments allow
4059throwing exceptions through C libraries (most do).
4060.SS "C++ API"
4061.IX Subsection "C++ API"
4062Libev comes with some simplistic wrapper classes for C++ that mainly allow
4063you to use some convenience methods to start/stop watchers and also change
4064the callback model to a model using method callbacks on objects.
4065.PP
4066To use it,
4067.PP
4068.Vb 1
4069\& #include <ev++.h>
4070.Ve
4071.PP
4072This automatically includes \fIev.h\fR and puts all of its definitions (many
4073of them macros) into the global namespace. All C++ specific things are
4074put into the \f(CW\*(C`ev\*(C'\fR namespace. It should support all the same embedding
4075options as \fIev.h\fR, most notably \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR.
4076.PP
4077Care has been taken to keep the overhead low. The only data member the C++
4078classes add (compared to plain C\-style watchers) is the event loop pointer
4079that the watcher is associated with (or no additional members at all if
4080you disable \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR when embedding libev).
4081.PP
4082Currently, functions, static and non\-static member functions and classes
4083with \f(CW\*(C`operator ()\*(C'\fR can be used as callbacks. Other types should be easy
4084to add as long as they only need one additional pointer for context. If
4085you need support for other types of functors please contact the author
4086(preferably after implementing it).
4087.PP
4088For all this to work, your C++ compiler either has to use the same calling
4089conventions as your C compiler (for static member functions), or you have
4090to embed libev and compile libev itself as C++.
4091.PP
4092Here is a list of things available in the \f(CW\*(C`ev\*(C'\fR namespace:
4093.ie n .IP """ev::READ"", ""ev::WRITE"" etc." 4
4094.el .IP "\f(CWev::READ\fR, \f(CWev::WRITE\fR etc." 4
4095.IX Item "ev::READ, ev::WRITE etc."
4096These are just enum values with the same values as the \f(CW\*(C`EV_READ\*(C'\fR etc.
4097macros from \fIev.h\fR.
4098.ie n .IP """ev::tstamp"", ""ev::now""" 4
4099.el .IP "\f(CWev::tstamp\fR, \f(CWev::now\fR" 4
4100.IX Item "ev::tstamp, ev::now"
4101Aliases to the same types/functions as with the \f(CW\*(C`ev_\*(C'\fR prefix.
4102.ie n .IP """ev::io"", ""ev::timer"", ""ev::periodic"", ""ev::idle"", ""ev::sig"" etc." 4
4103.el .IP "\f(CWev::io\fR, \f(CWev::timer\fR, \f(CWev::periodic\fR, \f(CWev::idle\fR, \f(CWev::sig\fR etc." 4
4104.IX Item "ev::io, ev::timer, ev::periodic, ev::idle, ev::sig etc."
4105For each \f(CW\*(C`ev_TYPE\*(C'\fR watcher in \fIev.h\fR there is a corresponding class of
4106the same name in the \f(CW\*(C`ev\*(C'\fR namespace, with the exception of \f(CW\*(C`ev_signal\*(C'\fR
4107which is called \f(CW\*(C`ev::sig\*(C'\fR to avoid clashes with the \f(CW\*(C`signal\*(C'\fR macro
4108defined by many implementations.
4109.Sp
4110All of those classes have these methods:
4111.RS 4
4112.IP "ev::TYPE::TYPE ()" 4
4113.IX Item "ev::TYPE::TYPE ()"
4114.PD 0
4115.IP "ev::TYPE::TYPE (loop)" 4
4116.IX Item "ev::TYPE::TYPE (loop)"
4117.IP ev::TYPE::~TYPE 4
4118.IX Item "ev::TYPE::~TYPE"
4119.PD
4120The constructor (optionally) takes an event loop to associate the watcher
4121with. If it is omitted, it will use \f(CW\*(C`EV_DEFAULT\*(C'\fR.
4122.Sp
4123The constructor calls \f(CW\*(C`ev_init\*(C'\fR for you, which means you have to call the
4124\&\f(CW\*(C`set\*(C'\fR method before starting it.
4125.Sp
4126It will not set a callback, however: You have to call the templated \f(CW\*(C`set\*(C'\fR
4127method to set a callback before you can start the watcher.
4128.Sp
4129(The reason why you have to use a method is a limitation in C++ which does
4130not allow explicit template arguments for constructors).
4131.Sp
4132The destructor automatically stops the watcher if it is active.
4133.IP "w\->set<class, &class::method> (object *)" 4
4134.IX Item "w->set<class, &class::method> (object *)"
4135This method sets the callback method to call. The method has to have a
4136signature of \f(CW\*(C`void (*)(ev_TYPE &, int)\*(C'\fR, it receives the watcher as
4137first argument and the \f(CW\*(C`revents\*(C'\fR as second. The object must be given as
4138parameter and is stored in the \f(CW\*(C`data\*(C'\fR member of the watcher.
4139.Sp
4140This method synthesizes efficient thunking code to call your method from
4141the C callback that libev requires. If your compiler can inline your
4142callback (i.e. it is visible to it at the place of the \f(CW\*(C`set\*(C'\fR call and
4143your compiler is good :), then the method will be fully inlined into the
4144thunking function, making it as fast as a direct C callback.
4145.Sp
4146Example: simple class declaration and watcher initialisation
4147.Sp
4148.Vb 4
4149\& struct myclass
4150\& {
4151\& void io_cb (ev::io &w, int revents) { }
4152\& }
4153\&
4154\& myclass obj;
4155\& ev::io iow;
4156\& iow.set <myclass, &myclass::io_cb> (&obj);
4157.Ve
4158.IP "w\->set (object *)" 4
4159.IX Item "w->set (object *)"
4160This is a variation of a method callback \- leaving out the method to call
4161will default the method to \f(CW\*(C`operator ()\*(C'\fR, which makes it possible to use
4162functor objects without having to manually specify the \f(CW\*(C`operator ()\*(C'\fR all
4163the time. Incidentally, you can then also leave out the template argument
4164list.
4165.Sp
4166The \f(CW\*(C`operator ()\*(C'\fR method prototype must be \f(CW\*(C`void operator ()(watcher &w,
4167int revents)\*(C'\fR.
4168.Sp
4169See the method\-\f(CW\*(C`set\*(C'\fR above for more details.
4170.Sp
4171Example: use a functor object as callback.
4172.Sp
4173.Vb 7
4174\& struct myfunctor
4175\& {
4176\& void operator() (ev::io &w, int revents)
4177\& {
4178\& ...
4179\& }
4180\& }
4181\&
4182\& myfunctor f;
4183\&
4184\& ev::io w;
4185\& w.set (&f);
4186.Ve
4187.IP "w\->set<function> (void *data = 0)" 4
4188.IX Item "w->set<function> (void *data = 0)"
4189Also sets a callback, but uses a static method or plain function as
4190callback. The optional \f(CW\*(C`data\*(C'\fR argument will be stored in the watcher\*(Aqs
4191\&\f(CW\*(C`data\*(C'\fR member and is free for you to use.
4192.Sp
4193The prototype of the \f(CW\*(C`function\*(C'\fR must be \f(CW\*(C`void (*)(ev::TYPE &w, int)\*(C'\fR.
4194.Sp
4195See the method\-\f(CW\*(C`set\*(C'\fR above for more details.
4196.Sp
4197Example: Use a plain function as callback.
4198.Sp
4199.Vb 2
4200\& static void io_cb (ev::io &w, int revents) { }
4201\& iow.set <io_cb> ();
4202.Ve
4203.IP "w\->set (loop)" 4
4204.IX Item "w->set (loop)"
4205Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only
4206do this when the watcher is inactive (and not pending either).
4207.IP "w\->set ([arguments])" 4
4208.IX Item "w->set ([arguments])"
4209Basically the same as \f(CW\*(C`ev_TYPE_set\*(C'\fR (except for \f(CW\*(C`ev::embed\*(C'\fR watchers>),
4210with the same arguments. Either this method or a suitable start method
4211must be called at least once. Unlike the C counterpart, an active watcher
4212gets automatically stopped and restarted when reconfiguring it with this
4213method.
4214.Sp
4215For \f(CW\*(C`ev::embed\*(C'\fR watchers this method is called \f(CW\*(C`set_embed\*(C'\fR, to avoid
4216clashing with the \f(CW\*(C`set (loop)\*(C'\fR method.
4217.IP "w\->start ()" 4
4218.IX Item "w->start ()"
4219Starts the watcher. Note that there is no \f(CW\*(C`loop\*(C'\fR argument, as the
4220constructor already stores the event loop.
4221.IP "w\->start ([arguments])" 4
4222.IX Item "w->start ([arguments])"
4223Instead of calling \f(CW\*(C`set\*(C'\fR and \f(CW\*(C`start\*(C'\fR methods separately, it is often
4224convenient to wrap them in one call. Uses the same type of arguments as
4225the configure \f(CW\*(C`set\*(C'\fR method of the watcher.
4226.IP "w\->stop ()" 4
4227.IX Item "w->stop ()"
4228Stops the watcher if it is active. Again, no \f(CW\*(C`loop\*(C'\fR argument.
4229.ie n .IP "w\->again () (""ev::timer"", ""ev::periodic"" only)" 4
4230.el .IP "w\->again () (\f(CWev::timer\fR, \f(CWev::periodic\fR only)" 4
4231.IX Item "w->again () (ev::timer, ev::periodic only)"
4232For \f(CW\*(C`ev::timer\*(C'\fR and \f(CW\*(C`ev::periodic\*(C'\fR, this invokes the corresponding
4233\&\f(CW\*(C`ev_TYPE_again\*(C'\fR function.
4234.ie n .IP "w\->sweep () (""ev::embed"" only)" 4
4235.el .IP "w\->sweep () (\f(CWev::embed\fR only)" 4
4236.IX Item "w->sweep () (ev::embed only)"
4237Invokes \f(CW\*(C`ev_embed_sweep\*(C'\fR.
4238.ie n .IP "w\->update () (""ev::stat"" only)" 4
4239.el .IP "w\->update () (\f(CWev::stat\fR only)" 4
4240.IX Item "w->update () (ev::stat only)"
4241Invokes \f(CW\*(C`ev_stat_stat\*(C'\fR.
4242.RE
4243.RS 4
4244.RE
4245.PP
4246Example: Define a class with two I/O and idle watchers, start the I/O
4247watchers in the constructor.
4248.PP
4249.Vb 5
4250\& class myclass
4251\& {
4252\& ev::io io ; void io_cb (ev::io &w, int revents);
4253\& ev::io io2 ; void io2_cb (ev::io &w, int revents);
4254\& ev::idle idle; void idle_cb (ev::idle &w, int revents);
4255\&
4256\& myclass (int fd)
4257\& {
4258\& io .set <myclass, &myclass::io_cb > (this);
4259\& io2 .set <myclass, &myclass::io2_cb > (this);
4260\& idle.set <myclass, &myclass::idle_cb> (this);
4261\&
4262\& io.set (fd, ev::WRITE); // configure the watcher
4263\& io.start (); // start it whenever convenient
4264\&
4265\& io2.start (fd, ev::READ); // set + start in one call
4266\& }
4267\& };
4268.Ve
4269.SH "OTHER LANGUAGE BINDINGS"
4270.IX Header "OTHER LANGUAGE BINDINGS"
4271Libev does not offer other language bindings itself, but bindings for a
4272number of languages exist in the form of third\-party packages. If you know
4273any interesting language binding in addition to the ones listed here, drop
4274me a note.
4275.IP Perl 4
4276.IX Item "Perl"
4277The EV module implements the full libev API and is actually used to test
4278libev. EV is developed together with libev. Apart from the EV core module,
4279there are additional modules that implement libev\-compatible interfaces
4280to \f(CW\*(C`libadns\*(C'\fR (\f(CW\*(C`EV::ADNS\*(C'\fR, but \f(CW\*(C`AnyEvent::DNS\*(C'\fR is preferred nowadays),
4281\&\f(CW\*(C`Net::SNMP\*(C'\fR (\f(CW\*(C`Net::SNMP::EV\*(C'\fR) and the \f(CW\*(C`libglib\*(C'\fR event core (\f(CW\*(C`Glib::EV\*(C'\fR
4282and \f(CW\*(C`EV::Glib\*(C'\fR).
4283.Sp
4284It can be found and installed via CPAN, its homepage is at
4285<http://software.schmorp.de/pkg/EV>.
4286.IP Python 4
4287.IX Item "Python"
4288Python bindings can be found at <http://code.google.com/p/pyev/>. It
4289seems to be quite complete and well\-documented.
4290.IP Ruby 4
4291.IX Item "Ruby"
4292Tony Arcieri has written a ruby extension that offers access to a subset
4293of the libev API and adds file handle abstractions, asynchronous DNS and
4294more on top of it. It can be found via gem servers. Its homepage is at
4295<http://rev.rubyforge.org/>.
4296.Sp
4297Roger Pack reports that using the link order \f(CW\*(C`\-lws2_32 \-lmsvcrt\-ruby\-190\*(C'\fR
4298makes rev work even on mingw.
4299.IP Haskell 4
4300.IX Item "Haskell"
4301A haskell binding to libev is available at
4302<http://hackage.haskell.org/cgi\-bin/hackage\-scripts/package/hlibev>.
4303.IP D 4
4304.IX Item "D"
4305Leandro Lucarella has written a D language binding (\fIev.d\fR) for libev, to
4306be found at <http://www.llucax.com.ar/proj/ev.d/index.html>.
4307.IP Ocaml 4
4308.IX Item "Ocaml"
4309Erkki Seppala has written Ocaml bindings for libev, to be found at
4310<http://modeemi.cs.tut.fi/~flux/software/ocaml\-ev/>.
4311.IP Lua 4
4312.IX Item "Lua"
4313Brian Maher has written a partial interface to libev for lua (at the
4314time of this writing, only \f(CW\*(C`ev_io\*(C'\fR and \f(CW\*(C`ev_timer\*(C'\fR), to be found at
4315<http://github.com/brimworks/lua\-ev>.
4316.IP Javascript 4
4317.IX Item "Javascript"
4318Node.js (<http://nodejs.org>) uses libev as the underlying event library.
4319.IP Others 4
4320.IX Item "Others"
4321There are others, and I stopped counting.
4322.SH "MACRO MAGIC"
4323.IX Header "MACRO MAGIC"
4324Libev can be compiled with a variety of options, the most fundamental
4325of which is \f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. This option determines whether (most)
4326functions and callbacks have an initial \f(CW\*(C`struct ev_loop *\*(C'\fR argument.
4327.PP
4328To make it easier to write programs that cope with either variant, the
4329following macros are defined:
4330.ie n .IP """EV_A"", ""EV_A_""" 4
4331.el .IP "\f(CWEV_A\fR, \f(CWEV_A_\fR" 4
4332.IX Item "EV_A, EV_A_"
4333This provides the loop \fIargument\fR for functions, if one is required ("ev
4334loop argument"). The \f(CW\*(C`EV_A\*(C'\fR form is used when this is the sole argument,
4335\&\f(CW\*(C`EV_A_\*(C'\fR is used when other arguments are following. Example:
4336.Sp
4337.Vb 3
4338\& ev_unref (EV_A);
4339\& ev_timer_add (EV_A_ watcher);
4340\& ev_run (EV_A_ 0);
4341.Ve
4342.Sp
4343It assumes the variable \f(CW\*(C`loop\*(C'\fR of type \f(CW\*(C`struct ev_loop *\*(C'\fR is in scope,
4344which is often provided by the following macro.
4345.ie n .IP """EV_P"", ""EV_P_""" 4
4346.el .IP "\f(CWEV_P\fR, \f(CWEV_P_\fR" 4
4347.IX Item "EV_P, EV_P_"
4348This provides the loop \fIparameter\fR for functions, if one is required ("ev
4349loop parameter"). The \f(CW\*(C`EV_P\*(C'\fR form is used when this is the sole parameter,
4350\&\f(CW\*(C`EV_P_\*(C'\fR is used when other parameters are following. Example:
4351.Sp
4352.Vb 2
4353\& // this is how ev_unref is being declared
4354\& static void ev_unref (EV_P);
4355\&
4356\& // this is how you can declare your typical callback
4357\& static void cb (EV_P_ ev_timer *w, int revents)
4358.Ve
4359.Sp
4360It declares a parameter \f(CW\*(C`loop\*(C'\fR of type \f(CW\*(C`struct ev_loop *\*(C'\fR, quite
4361suitable for use with \f(CW\*(C`EV_A\*(C'\fR.
4362.ie n .IP """EV_DEFAULT"", ""EV_DEFAULT_""" 4
4363.el .IP "\f(CWEV_DEFAULT\fR, \f(CWEV_DEFAULT_\fR" 4
4364.IX Item "EV_DEFAULT, EV_DEFAULT_"
4365Similar to the other two macros, this gives you the value of the default
4366loop, if multiple loops are supported ("ev loop default"). The default loop
4367will be initialised if it isn\*(Aqt already initialised.
4368.Sp
4369For non\-multiplicity builds, these macros do nothing, so you always have
4370to initialise the loop somewhere.
4371.ie n .IP """EV_DEFAULT_UC"", ""EV_DEFAULT_UC_""" 4
4372.el .IP "\f(CWEV_DEFAULT_UC\fR, \f(CWEV_DEFAULT_UC_\fR" 4
4373.IX Item "EV_DEFAULT_UC, EV_DEFAULT_UC_"
4374Usage identical to \f(CW\*(C`EV_DEFAULT\*(C'\fR and \f(CW\*(C`EV_DEFAULT_\*(C'\fR, but requires that the
4375default loop has been initialised (\f(CW\*(C`UC\*(C'\fR == unchecked). Their behaviour
4376is undefined when the default loop has not been initialised by a previous
4377execution of \f(CW\*(C`EV_DEFAULT\*(C'\fR, \f(CW\*(C`EV_DEFAULT_\*(C'\fR or \f(CW\*(C`ev_default_init (...)\*(C'\fR.
4378.Sp
4379It is often prudent to use \f(CW\*(C`EV_DEFAULT\*(C'\fR when initialising the first
4380watcher in a function but use \f(CW\*(C`EV_DEFAULT_UC\*(C'\fR afterwards.
4381.PP
4382Example: Declare and initialise a check watcher, utilising the above
4383macros so it will work regardless of whether multiple loops are supported
4384or not.
4385.PP
4386.Vb 5
4387\& static void
4388\& check_cb (EV_P_ ev_timer *w, int revents)
4389\& {
4390\& ev_check_stop (EV_A_ w);
4391\& }
4392\&
4393\& ev_check check;
4394\& ev_check_init (&check, check_cb);
4395\& ev_check_start (EV_DEFAULT_ &check);
4396\& ev_run (EV_DEFAULT_ 0);
4397.Ve
4398.SH EMBEDDING
4399.IX Header "EMBEDDING"
4400Libev can (and often is) directly embedded into host
4401applications. Examples of applications that embed it include the Deliantra
4402Game Server, the EV perl module, the GNU Virtual Private Ethernet (gvpe)
4403and rxvt\-unicode.
4404.PP
4405The goal is to enable you to just copy the necessary files into your
4406source directory without having to change even a single line in them, so
4407you can easily upgrade by simply copying (or having a checked\-out copy of
4408libev somewhere in your source tree).
4409.SS FILESETS
4410.IX Subsection "FILESETS"
4411Depending on what features you need you need to include one or more sets of files
4412in your application.
4413.PP
4414\fICORE EVENT LOOP\fR
4415.IX Subsection "CORE EVENT LOOP"
4416.PP
4417To include only the libev core (all the \f(CW\*(C`ev_*\*(C'\fR functions), with manual
4418configuration (no autoconf):
4419.PP
4420.Vb 2
4421\& #define EV_STANDALONE 1
4422\& #include "ev.c"
4423.Ve
4424.PP
4425This will automatically include \fIev.h\fR, too, and should be done in a
4426single C source file only to provide the function implementations. To use
4427it, do the same for \fIev.h\fR in all files wishing to use this API (best
4428done by writing a wrapper around \fIev.h\fR that you can include instead and
4429where you can put other configuration options):
4430.PP
4431.Vb 2
4432\& #define EV_STANDALONE 1
4433\& #include "ev.h"
4434.Ve
4435.PP
4436Both header files and implementation files can be compiled with a C++
4437compiler (at least, that\*(Aqs a stated goal, and breakage will be treated
4438as a bug).
4439.PP
4440You need the following files in your source tree, or in a directory
4441in your include path (e.g. in libev/ when using \-Ilibev):
4442.PP
4443.Vb 4
4444\& ev.h
4445\& ev.c
4446\& ev_vars.h
4447\& ev_wrap.h
4448\&
4449\& ev_win32.c required on win32 platforms only
4450\&
4451\& ev_select.c only when select backend is enabled (which is enabled by default)
4452\& ev_poll.c only when poll backend is enabled (disabled by default)
4453\& ev_epoll.c only when the epoll backend is enabled (disabled by default)
4454\& ev_kqueue.c only when the kqueue backend is enabled (disabled by default)
4455\& ev_port.c only when the solaris port backend is enabled (disabled by default)
4456.Ve
4457.PP
4458\&\fIev.c\fR includes the backend files directly when enabled, so you only need
4459to compile this single file.
4460.PP
4461\fILIBEVENT COMPATIBILITY API\fR
4462.IX Subsection "LIBEVENT COMPATIBILITY API"
4463.PP
4464To include the libevent compatibility API, also include:
4465.PP
4466.Vb 1
4467\& #include "event.c"
4468.Ve
4469.PP
4470in the file including \fIev.c\fR, and:
4471.PP
4472.Vb 1
4473\& #include "event.h"
4474.Ve
4475.PP
4476in the files that want to use the libevent API. This also includes \fIev.h\fR.
4477.PP
4478You need the following additional files for this:
4479.PP
4480.Vb 2
4481\& event.h
4482\& event.c
4483.Ve
4484.PP
4485\fIAUTOCONF SUPPORT\fR
4486.IX Subsection "AUTOCONF SUPPORT"
4487.PP
4488Instead of using \f(CW\*(C`EV_STANDALONE=1\*(C'\fR and providing your configuration in
4489whatever way you want, you can also \f(CWm4_include([libev.m4])\fR in your
4490\&\fIconfigure.ac\fR and leave \f(CW\*(C`EV_STANDALONE\*(C'\fR undefined. \fIev.c\fR will then
4491include \fIconfig.h\fR and configure itself accordingly.
4492.PP
4493For this of course you need the m4 file:
4494.PP
4495.Vb 1
4496\& libev.m4
4497.Ve
4498.SS "PREPROCESSOR SYMBOLS/MACROS"
4499.IX Subsection "PREPROCESSOR SYMBOLS/MACROS"
4500Libev can be configured via a variety of preprocessor symbols you have to
4501define before including (or compiling) any of its files. The default in
4502the absence of autoconf is documented for every option.
4503.PP
4504Symbols marked with "(h)" do not change the ABI, and can have different
4505values when compiling libev vs. including \fIev.h\fR, so it is permissible
4506to redefine them before including \fIev.h\fR without breaking compatibility
4507to a compiled library. All other symbols change the ABI, which means all
4508users of libev and the libev code itself must be compiled with compatible
4509settings.
4510.IP "EV_COMPAT3 (h)" 4
4511.IX Item "EV_COMPAT3 (h)"
4512Backwards compatibility is a major concern for libev. This is why this
4513release of libev comes with wrappers for the functions and symbols that
4514have been renamed between libev version 3 and 4.
4515.Sp
4516You can disable these wrappers (to test compatibility with future
4517versions) by defining \f(CW\*(C`EV_COMPAT3\*(C'\fR to \f(CW0\fR when compiling your
4518sources. This has the additional advantage that you can drop the \f(CW\*(C`struct\*(C'\fR
4519from \f(CW\*(C`struct ev_loop\*(C'\fR declarations, as libev will provide an \f(CW\*(C`ev_loop\*(C'\fR
4520typedef in that case.
4521.Sp
4522In some future version, the default for \f(CW\*(C`EV_COMPAT3\*(C'\fR will become \f(CW0\fR,
4523and in some even more future version the compatibility code will be
4524removed completely.
4525.IP "EV_STANDALONE (h)" 4
4526.IX Item "EV_STANDALONE (h)"
4527Must always be \f(CW1\fR if you do not use autoconf configuration, which
4528keeps libev from including \fIconfig.h\fR, and it also defines dummy
4529implementations for some libevent functions (such as logging, which is not
4530supported). It will also not define any of the structs usually found in
4531\&\fIevent.h\fR that are not directly supported by the libev core alone.
4532.Sp
4533In standalone mode, libev will still try to automatically deduce the
4534configuration, but has to be more conservative.
4535.IP EV_USE_FLOOR 4
4536.IX Item "EV_USE_FLOOR"
4537If defined to be \f(CW1\fR, libev will use the \f(CW\*(C`floor ()\*(C'\fR function for its
4538periodic reschedule calculations, otherwise libev will fall back on a
4539portable (slower) implementation. If you enable this, you usually have to
4540link against libm or something equivalent. Enabling this when the \f(CW\*(C`floor\*(C'\fR
4541function is not available will fail, so the safe default is to not enable
4542this.
4543.IP EV_USE_MONOTONIC 4
4544.IX Item "EV_USE_MONOTONIC"
4545If defined to be \f(CW1\fR, libev will try to detect the availability of the
4546monotonic clock option at both compile time and runtime. Otherwise no
4547use of the monotonic clock option will be attempted. If you enable this,
4548you usually have to link against librt or something similar. Enabling it
4549when the functionality isn\*(Aqt available is safe, though, although you have
4550to make sure you link against any libraries where the \f(CW\*(C`clock_gettime\*(C'\fR
4551function is hiding in (often \fI\-lrt\fR). See also \f(CW\*(C`EV_USE_CLOCK_SYSCALL\*(C'\fR.
4552.IP EV_USE_REALTIME 4
4553.IX Item "EV_USE_REALTIME"
4554If defined to be \f(CW1\fR, libev will try to detect the availability of the
4555real\-time clock option at compile time (and assume its availability
4556at runtime if successful). Otherwise no use of the real\-time clock
4557option will be attempted. This effectively replaces \f(CW\*(C`gettimeofday\*(C'\fR
4558by \f(CW\*(C`clock_get (CLOCK_REALTIME, ...)\*(C'\fR and will not normally affect
4559correctness. See the note about libraries in the description of
4560\&\f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though. Defaults to the opposite value of
4561\&\f(CW\*(C`EV_USE_CLOCK_SYSCALL\*(C'\fR.
4562.IP EV_USE_CLOCK_SYSCALL 4
4563.IX Item "EV_USE_CLOCK_SYSCALL"
4564If defined to be \f(CW1\fR, libev will try to use a direct syscall instead
4565of calling the system\-provided \f(CW\*(C`clock_gettime\*(C'\fR function. This option
4566exists because on GNU/Linux, \f(CW\*(C`clock_gettime\*(C'\fR is in \f(CW\*(C`librt\*(C'\fR, but \f(CW\*(C`librt\*(C'\fR
4567unconditionally pulls in \f(CW\*(C`libpthread\*(C'\fR, slowing down single\-threaded
4568programs needlessly. Using a direct syscall is slightly slower (in
4569theory), because no optimised vdso implementation can be used, but avoids
4570the pthread dependency. Defaults to \f(CW1\fR on GNU/Linux with glibc 2.x or
4571higher, as it simplifies linking (no need for \f(CW\*(C`\-lrt\*(C'\fR).
4572.IP EV_USE_NANOSLEEP 4
4573.IX Item "EV_USE_NANOSLEEP"
4574If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available
4575and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR.
4576.IP EV_USE_EVENTFD 4
4577.IX Item "EV_USE_EVENTFD"
4578If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is
4579available and will probe for kernel support at runtime. This will improve
4580\&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption.
4581If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc
45822.7 or newer, otherwise disabled.
4583.IP EV_USE_SELECT 4
4584.IX Item "EV_USE_SELECT"
4585If undefined or defined to be \f(CW1\fR, libev will compile in support for the
4586\&\f(CW\*(C`select\*(C'\fR(2) backend. No attempt at auto\-detection will be done: if no
4587other method takes over, select will be it. Otherwise the select backend
4588will not be compiled in.
4589.IP EV_SELECT_USE_FD_SET 4
4590.IX Item "EV_SELECT_USE_FD_SET"
4591If defined to \f(CW1\fR, then the select backend will use the system \f(CW\*(C`fd_set\*(C'\fR
4592structure. This is useful if libev doesn\*(Aqt compile due to a missing
4593\&\f(CW\*(C`NFDBITS\*(C'\fR or \f(CW\*(C`fd_mask\*(C'\fR definition or it mis\-guesses the bitset layout
4594on exotic systems. This usually limits the range of file descriptors to
4595some low limit such as 1024 or might have other limitations (winsocket
4596only allows 64 sockets). The \f(CW\*(C`FD_SETSIZE\*(C'\fR macro, set before compilation,
4597configures the maximum size of the \f(CW\*(C`fd_set\*(C'\fR.
4598.IP EV_SELECT_IS_WINSOCKET 4
4599.IX Item "EV_SELECT_IS_WINSOCKET"
4600When defined to \f(CW1\fR, the select backend will assume that
4601select/socket/connect etc. don\*(Aqt understand file descriptors but
4602wants osf handles on win32 (this is the case when the select to
4603be used is the winsock select). This means that it will call
4604\&\f(CW\*(C`_get_osfhandle\*(C'\fR on the fd to convert it to an OS handle. Otherwise,
4605it is assumed that all these functions actually work on fds, even
4606on win32. Should not be defined on non\-win32 platforms.
4607.IP EV_FD_TO_WIN32_HANDLE(fd) 4
4608.IX Item "EV_FD_TO_WIN32_HANDLE(fd)"
4609If \f(CW\*(C`EV_SELECT_IS_WINSOCKET\*(C'\fR is enabled, then libev needs a way to map
4610file descriptors to socket handles. When not defining this symbol (the
4611default), then libev will call \f(CW\*(C`_get_osfhandle\*(C'\fR, which is usually
4612correct. In some cases, programs use their own file descriptor management,
4613in which case they can provide this function to map fds to socket handles.
4614.IP EV_WIN32_HANDLE_TO_FD(handle) 4
4615.IX Item "EV_WIN32_HANDLE_TO_FD(handle)"
4616If \f(CW\*(C`EV_SELECT_IS_WINSOCKET\*(C'\fR then libev maps handles to file descriptors
4617using the standard \f(CW\*(C`_open_osfhandle\*(C'\fR function. For programs implementing
4618their own fd to handle mapping, overwriting this function makes it easier
4619to do so. This can be done by defining this macro to an appropriate value.
4620.IP EV_WIN32_CLOSE_FD(fd) 4
4621.IX Item "EV_WIN32_CLOSE_FD(fd)"
4622If programs implement their own fd to handle mapping on win32, then this
4623macro can be used to override the \f(CW\*(C`close\*(C'\fR function, useful to unregister
4624file descriptors again. Note that the replacement function has to close
4625the underlying OS handle.
4626.IP EV_USE_WSASOCKET 4
4627.IX Item "EV_USE_WSASOCKET"
4628If defined to be \f(CW1\fR, libev will use \f(CW\*(C`WSASocket\*(C'\fR to create its internal
4629communication socket, which works better in some environments. Otherwise,
4630the normal \f(CW\*(C`socket\*(C'\fR function will be used, which works better in other
4631environments.
4632.IP EV_USE_POLL 4
4633.IX Item "EV_USE_POLL"
4634If defined to be \f(CW1\fR, libev will compile in support for the \f(CW\*(C`poll\*(C'\fR(2)
4635backend. Otherwise it will be enabled on non\-win32 platforms. It
4636takes precedence over select.
4637.IP EV_USE_EPOLL 4
4638.IX Item "EV_USE_EPOLL"
4639If defined to be \f(CW1\fR, libev will compile in support for the Linux
4640\&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime,
4641otherwise another method will be used as fallback. This is the preferred
4642backend for GNU/Linux systems. If undefined, it will be enabled if the
4643headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
4644.IP EV_USE_KQUEUE 4
4645.IX Item "EV_USE_KQUEUE"
4646If defined to be \f(CW1\fR, libev will compile in support for the BSD style
4647\&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime,
4648otherwise another method will be used as fallback. This is the preferred
4649backend for BSD and BSD\-like systems, although on most BSDs kqueue only
4650supports some types of fds correctly (the only platform we found that
4651supports ptys for example was NetBSD), so kqueue might be compiled in, but
4652not be used unless explicitly requested. The best way to use it is to find
4653out whether kqueue supports your type of fd properly and use an embedded
4654kqueue loop.
4655.IP EV_USE_PORT 4
4656.IX Item "EV_USE_PORT"
4657If defined to be \f(CW1\fR, libev will compile in support for the Solaris
465810 port style backend. Its availability will be detected at runtime,
4659otherwise another method will be used as fallback. This is the preferred
4660backend for Solaris 10 systems.
4661.IP EV_USE_DEVPOLL 4
4662.IX Item "EV_USE_DEVPOLL"
4663Reserved for future expansion, works like the USE symbols above.
4664.IP EV_USE_INOTIFY 4
4665.IX Item "EV_USE_INOTIFY"
4666If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify
4667interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will
4668be detected at runtime. If undefined, it will be enabled if the headers
4669indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
4670.IP EV_NO_SMP 4
4671.IX Item "EV_NO_SMP"
4672If defined to be \f(CW1\fR, libev will assume that memory is always coherent
4673between threads, that is, threads can be used, but threads never run on
4674different cpus (or different cpu cores). This reduces dependencies
4675and makes libev faster.
4676.IP EV_NO_THREADS 4
4677.IX Item "EV_NO_THREADS"
4678If defined to be \f(CW1\fR, libev will assume that it will never be called from
4679different threads (that includes signal handlers), which is a stronger
4680assumption than \f(CW\*(C`EV_NO_SMP\*(C'\fR, above. This reduces dependencies and makes
4681libev faster.
4682.IP EV_ATOMIC_T 4
4683.IX Item "EV_ATOMIC_T"
4684Libev requires an integer type (suitable for storing \f(CW0\fR or \f(CW1\fR) whose
4685access is atomic with respect to other threads or signal contexts. No
4686such type is easily found in the C language, so you can provide your own
4687type that you know is safe for your purposes. It is used both for signal
4688handler "locking" as well as for signal and thread safety in \f(CW\*(C`ev_async\*(C'\fR
4689watchers.
4690.Sp
4691In the absence of this define, libev will use \f(CW\*(C`sig_atomic_t volatile\*(C'\fR
4692(from \fIsignal.h\fR), which is usually good enough on most platforms.
4693.IP "EV_H (h)" 4
4694.IX Item "EV_H (h)"
4695The name of the \fIev.h\fR header file used to include it. The default if
4696undefined is \f(CW"ev.h"\fR in \fIevent.h\fR, \fIev.c\fR and \fIev++.h\fR. This can be
4697used to virtually rename the \fIev.h\fR header file in case of conflicts.
4698.IP "EV_CONFIG_H (h)" 4
4699.IX Item "EV_CONFIG_H (h)"
4700If \f(CW\*(C`EV_STANDALONE\*(C'\fR isn\*(Aqt \f(CW1\fR, this variable can be used to override
4701\&\fIev.c\fR\*(Aqs idea of where to find the \fIconfig.h\fR file, similarly to
4702\&\f(CW\*(C`EV_H\*(C'\fR, above.
4703.IP "EV_EVENT_H (h)" 4
4704.IX Item "EV_EVENT_H (h)"
4705Similarly to \f(CW\*(C`EV_H\*(C'\fR, this macro can be used to override \fIevent.c\fR\*(Aqs idea
4706of how the \fIevent.h\fR header can be found, the default is \f(CW"event.h"\fR.
4707.IP "EV_PROTOTYPES (h)" 4
4708.IX Item "EV_PROTOTYPES (h)"
4709If defined to be \f(CW0\fR, then \fIev.h\fR will not define any function
4710prototypes, but still define all the structs and other symbols. This is
4711occasionally useful if you want to provide your own wrapper functions
4712around libev functions.
4713.IP EV_MULTIPLICITY 4
4714.IX Item "EV_MULTIPLICITY"
4715If undefined or defined to \f(CW1\fR, then all event\-loop\-specific functions
4716will have the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument, and you can create
4717additional independent event loops. Otherwise there will be no support
4718for multiple event loops and there is no first event loop pointer
4719argument. Instead, all functions act on the single default loop.
4720.Sp
4721Note that \f(CW\*(C`EV_DEFAULT\*(C'\fR and \f(CW\*(C`EV_DEFAULT_\*(C'\fR will no longer provide a
4722default loop when multiplicity is switched off \- you always have to
4723initialise the loop manually in this case.
4724.IP EV_MINPRI 4
4725.IX Item "EV_MINPRI"
4726.PD 0
4727.IP EV_MAXPRI 4
4728.IX Item "EV_MAXPRI"
4729.PD
4730The range of allowed priorities. \f(CW\*(C`EV_MINPRI\*(C'\fR must be smaller or equal to
4731\&\f(CW\*(C`EV_MAXPRI\*(C'\fR, but otherwise there are no non\-obvious limitations. You can
4732provide for more priorities by overriding those symbols (usually defined
4733to be \f(CW\-2\fR and \f(CW2\fR, respectively).
4734.Sp
4735When doing priority\-based operations, libev usually has to linearly search
4736all the priorities, so having many of them (hundreds) uses a lot of space
4737and time, so using the defaults of five priorities (\-2 .. +2) is usually
4738fine.
4739.Sp
4740If your embedding application does not need any priorities, defining these
4741both to \f(CW0\fR will save some memory and CPU.
4742.IP "EV_PERIODIC_ENABLE, EV_IDLE_ENABLE, EV_EMBED_ENABLE, EV_STAT_ENABLE, EV_PREPARE_ENABLE, EV_CHECK_ENABLE, EV_FORK_ENABLE, EV_SIGNAL_ENABLE, EV_ASYNC_ENABLE, EV_CHILD_ENABLE." 4
4743.IX Item "EV_PERIODIC_ENABLE, EV_IDLE_ENABLE, EV_EMBED_ENABLE, EV_STAT_ENABLE, EV_PREPARE_ENABLE, EV_CHECK_ENABLE, EV_FORK_ENABLE, EV_SIGNAL_ENABLE, EV_ASYNC_ENABLE, EV_CHILD_ENABLE."
4744If undefined or defined to be \f(CW1\fR (and the platform supports it), then
4745the respective watcher type is supported. If defined to be \f(CW0\fR, then it
4746is not. Disabling watcher types mainly saves code size.
4747.IP EV_FEATURES 4
4748.IX Item "EV_FEATURES"
4749If you need to shave off some kilobytes of code at the expense of some
4750speed (but with the full API), you can define this symbol to request
4751certain subsets of functionality. The default is to enable all features
4752that can be enabled on the platform.
4753.Sp
4754A typical way to use this symbol is to define it to \f(CW0\fR (or to a bitset
4755with some broad features you want) and then selectively re\-enable
4756additional parts you want, for example if you want everything minimal,
4757but multiple event loop support, async and child watchers and the poll
4758backend, use this:
4759.Sp
4760.Vb 5
4761\& #define EV_FEATURES 0
4762\& #define EV_MULTIPLICITY 1
4763\& #define EV_USE_POLL 1
4764\& #define EV_CHILD_ENABLE 1
4765\& #define EV_ASYNC_ENABLE 1
4766.Ve
4767.Sp
4768The actual value is a bitset, it can be a combination of the following
4769values (by default, all of these are enabled):
4770.RS 4
4771.ie n .IP "1 \- faster/larger code" 4
4772.el .IP "\f(CW1\fR \- faster/larger code" 4
4773.IX Item "1 - faster/larger code"
4774Use larger code to speed up some operations.
4775.Sp
4776Currently this is used to override some inlining decisions (enlarging the
4777code size by roughly 30% on amd64).
4778.Sp
4779When optimising for size, use of compiler flags such as \f(CW\*(C`\-Os\*(C'\fR with
4780gcc is recommended, as well as \f(CW\*(C`\-DNDEBUG\*(C'\fR, as libev contains a number of
4781assertions.
4782.Sp
4783The default is off when \f(CW\*(C`_\|_OPTIMIZE_SIZE_\|_\*(C'\fR is defined by your compiler
4784(e.g. gcc with \f(CW\*(C`\-Os\*(C'\fR).
4785.ie n .IP "2 \- faster/larger data structures" 4
4786.el .IP "\f(CW2\fR \- faster/larger data structures" 4
4787.IX Item "2 - faster/larger data structures"
4788Replaces the small 2\-heap for timer management by a faster 4\-heap, larger
4789hash table sizes and so on. This will usually further increase code size
4790and can additionally have an effect on the size of data structures at
4791runtime.
4792.Sp
4793The default is off when \f(CW\*(C`_\|_OPTIMIZE_SIZE_\|_\*(C'\fR is defined by your compiler
4794(e.g. gcc with \f(CW\*(C`\-Os\*(C'\fR).
4795.ie n .IP "4 \- full API configuration" 4
4796.el .IP "\f(CW4\fR \- full API configuration" 4
4797.IX Item "4 - full API configuration"
4798This enables priorities (sets \f(CW\*(C`EV_MAXPRI\*(C'\fR=2 and \f(CW\*(C`EV_MINPRI\*(C'\fR=\-2), and
4799enables multiplicity (\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR=1).
4800.ie n .IP "8 \- full API" 4
4801.el .IP "\f(CW8\fR \- full API" 4
4802.IX Item "8 - full API"
4803This enables a lot of the "lesser used" API functions. See \f(CW\*(C`ev.h\*(C'\fR for
4804details on which parts of the API are still available without this
4805feature, and do not complain if this subset changes over time.
4806.ie n .IP "16 \- enable all optional watcher types" 4
4807.el .IP "\f(CW16\fR \- enable all optional watcher types" 4
4808.IX Item "16 - enable all optional watcher types"
4809Enables all optional watcher types. If you want to selectively enable
4810only some watcher types other than I/O and timers (e.g. prepare,
4811embed, async, child...) you can enable them manually by defining
4812\&\f(CW\*(C`EV_watchertype_ENABLE\*(C'\fR to \f(CW1\fR instead.
4813.ie n .IP "32 \- enable all backends" 4
4814.el .IP "\f(CW32\fR \- enable all backends" 4
4815.IX Item "32 - enable all backends"
4816This enables all backends \- without this feature, you need to enable at
4817least one backend manually (\f(CW\*(C`EV_USE_SELECT\*(C'\fR is a good choice).
4818.ie n .IP "64 \- enable OS\-specific ""helper"" APIs" 4
4819.el .IP "\f(CW64\fR \- enable OS\-specific ""helper"" APIs" 4
4820.IX Item "64 - enable OS-specific ""helper"" APIs"
4821Enable inotify, eventfd, signalfd and similar OS\-specific helper APIs by
4822default.
4823.RE
4824.RS 4
4825.Sp
4826Compiling with \f(CW\*(C`gcc \-Os \-DEV_STANDALONE \-DEV_USE_EPOLL=1 \-DEV_FEATURES=0\*(C'\fR
4827reduces the compiled size of libev from 24.7Kb code/2.8Kb data to 6.5Kb
4828code/0.3Kb data on my GNU/Linux amd64 system, while still giving you I/O
4829watchers, timers and monotonic clock support.
4830.Sp
4831With an intelligent\-enough linker (gcc+binutils are intelligent enough
4832when you use \f(CW\*(C`\-Wl,\-\-gc\-sections \-ffunction\-sections\*(C'\fR) functions unused by
4833your program might be left out as well \- a binary starting a timer and an
4834I/O watcher then might come out at only 5Kb.
4835.RE
4836.IP EV_API_STATIC 4
4837.IX Item "EV_API_STATIC"
4838If this symbol is defined (by default it is not), then all identifiers
4839will have static linkage. This means that libev will not export any
4840identifiers, and you cannot link against libev anymore. This can be useful
4841when you embed libev, only want to use libev functions in a single file,
4842and do not want its identifiers to be visible.
4843.Sp
4844To use this, define \f(CW\*(C`EV_API_STATIC\*(C'\fR and include \fIev.c\fR in the file that
4845wants to use libev.
4846.Sp
4847This option only works when libev is compiled with a C compiler, as C++
4848doesn\*(Aqt support the required declaration syntax.
4849.IP EV_AVOID_STDIO 4
4850.IX Item "EV_AVOID_STDIO"
4851If this is set to \f(CW1\fR at compiletime, then libev will avoid using stdio
4852functions (printf, scanf, perror etc.). This will increase the code size
4853somewhat, but if your program doesn\*(Aqt otherwise depend on stdio and your
4854libc allows it, this avoids linking in the stdio library which is quite
4855big.
4856.Sp
4857Note that error messages might become less precise when this option is
4858enabled.
4859.IP EV_NSIG 4
4860.IX Item "EV_NSIG"
4861The highest supported signal number, +1 (or, the number of
4862signals): Normally, libev tries to deduce the maximum number of signals
4863automatically, but sometimes this fails, in which case it can be
4864specified. Also, using a lower number than detected (\f(CW32\fR should be
4865good for about any system in existence) can save some memory, as libev
4866statically allocates some 12\-24 bytes per signal number.
4867.IP EV_PID_HASHSIZE 4
4868.IX Item "EV_PID_HASHSIZE"
4869\&\f(CW\*(C`ev_child\*(C'\fR watchers use a small hash table to distribute workload by
4870pid. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_FEATURES\*(C'\fR disabled),
4871usually more than enough. If you need to manage thousands of children you
4872might want to increase this value (\fImust\fR be a power of two).
4873.IP EV_INOTIFY_HASHSIZE 4
4874.IX Item "EV_INOTIFY_HASHSIZE"
4875\&\f(CW\*(C`ev_stat\*(C'\fR watchers use a small hash table to distribute workload by
4876inotify watch id. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_FEATURES\*(C'\fR
4877disabled), usually more than enough. If you need to manage thousands of
4878\&\f(CW\*(C`ev_stat\*(C'\fR watchers you might want to increase this value (\fImust\fR be a
4879power of two).
4880.IP EV_USE_4HEAP 4
4881.IX Item "EV_USE_4HEAP"
4882Heaps are not very cache\-efficient. To improve the cache\-efficiency of the
4883timer and periodics heaps, libev uses a 4\-heap when this symbol is defined
4884to \f(CW1\fR. The 4\-heap uses more complicated (longer) code but has noticeably
4885faster performance with many (thousands) of watchers.
4886.Sp
4887The default is \f(CW1\fR, unless \f(CW\*(C`EV_FEATURES\*(C'\fR overrides it, in which case it
4888will be \f(CW0\fR.
4889.IP EV_HEAP_CACHE_AT 4
4890.IX Item "EV_HEAP_CACHE_AT"
4891Heaps are not very cache\-efficient. To improve the cache\-efficiency of the
4892timer and periodics heaps, libev can cache the timestamp (\fIat\fR) within
4893the heap structure (selected by defining \f(CW\*(C`EV_HEAP_CACHE_AT\*(C'\fR to \f(CW1\fR),
4894which uses 8\-12 bytes more per watcher and a few hundred bytes more code,
4895but avoids random read accesses on heap changes. This improves performance
4896noticeably with many (hundreds) of watchers.
4897.Sp
4898The default is \f(CW1\fR, unless \f(CW\*(C`EV_FEATURES\*(C'\fR overrides it, in which case it
4899will be \f(CW0\fR.
4900.IP EV_VERIFY 4
4901.IX Item "EV_VERIFY"
4902Controls how much internal verification (see \f(CW\*(C`ev_verify ()\*(C'\fR) will
4903be done: If set to \f(CW0\fR, no internal verification code will be compiled
4904in. If set to \f(CW1\fR, then verification code will be compiled in, but not
4905called. If set to \f(CW2\fR, then the internal verification code will be
4906called once per loop, which can slow down libev. If set to \f(CW3\fR, then the
4907verification code will be called very frequently, which will slow down
4908libev considerably.
4909.Sp
4910The default is \f(CW1\fR, unless \f(CW\*(C`EV_FEATURES\*(C'\fR overrides it, in which case it
4911will be \f(CW0\fR.
4912.IP EV_COMMON 4
4913.IX Item "EV_COMMON"
4914By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining
4915this macro to something else you can include more and other types of
4916members. You have to define it each time you include one of the files,
4917though, and it must be identical each time.
4918.Sp
4919For example, the perl EV module uses something like this:
4920.Sp
4921.Vb 3
4922\& #define EV_COMMON \e
4923\& SV *self; /* contains this struct */ \e
4924\& SV *cb_sv, *fh /* note no trailing ";" */
4925.Ve
4926.IP "EV_CB_DECLARE (type)" 4
4927.IX Item "EV_CB_DECLARE (type)"
4928.PD 0
4929.IP "EV_CB_INVOKE (watcher, revents)" 4
4930.IX Item "EV_CB_INVOKE (watcher, revents)"
4931.IP "ev_set_cb (ev, cb)" 4
4932.IX Item "ev_set_cb (ev, cb)"
4933.PD
4934Can be used to change the callback member declaration in each watcher,
4935and the way callbacks are invoked and set. Must expand to a struct member
4936definition and a statement, respectively. See the \fIev.h\fR header file for
4937their default definitions. One possible use for overriding these is to
4938avoid the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument in all cases, or to use
4939method calls instead of plain function calls in C++.
4940.SS "EXPORTED API SYMBOLS"
4941.IX Subsection "EXPORTED API SYMBOLS"
4942If you need to re\-export the API (e.g. via a DLL) and you need a list of
4943exported symbols, you can use the provided \fISymbol.*\fR files which list
4944all public symbols, one per line:
4945.PP
4946.Vb 2
4947\& Symbols.ev for libev proper
4948\& Symbols.event for the libevent emulation
4949.Ve
4950.PP
4951This can also be used to rename all public symbols to avoid clashes with
4952multiple versions of libev linked together (which is obviously bad in
4953itself, but sometimes it is inconvenient to avoid this).
4954.PP
4955A sed command like this will create wrapper \f(CW\*(C`#define\*(C'\fR\*(Aqs that you need to
4956include before including \fIev.h\fR:
4957.PP
4958.Vb 1
4959\& <Symbols.ev sed \-e "s/.*/#define & myprefix_&/" >wrap.h
4960.Ve
4961.PP
4962This would create a file \fIwrap.h\fR which essentially looks like this:
4963.PP
4964.Vb 4
4965\& #define ev_backend myprefix_ev_backend
4966\& #define ev_check_start myprefix_ev_check_start
4967\& #define ev_check_stop myprefix_ev_check_stop
4968\& ...
4969.Ve
4970.SS EXAMPLES
4971.IX Subsection "EXAMPLES"
4972For a real\-world example of a program the includes libev
4973verbatim, you can have a look at the EV perl module
4974(<http://software.schmorp.de/pkg/EV.html>). It has the libev files in
4975the \fIlibev/\fR subdirectory and includes them in the \fIEV/EVAPI.h\fR (public
4976interface) and \fIEV.xs\fR (implementation) files. Only the \fIEV.xs\fR file
4977will be compiled. It is pretty complex because it provides its own header
4978file.
4979.PP
4980The usage in rxvt\-unicode is simpler. It has a \fIev_cpp.h\fR header file
4981that everybody includes and which overrides some configure choices:
4982.PP
4983.Vb 8
4984\& #define EV_FEATURES 8
4985\& #define EV_USE_SELECT 1
4986\& #define EV_PREPARE_ENABLE 1
4987\& #define EV_IDLE_ENABLE 1
4988\& #define EV_SIGNAL_ENABLE 1
4989\& #define EV_CHILD_ENABLE 1
4990\& #define EV_USE_STDEXCEPT 0
4991\& #define EV_CONFIG_H <config.h>
4992\&
4993\& #include "ev++.h"
4994.Ve
4995.PP
4996And a \fIev_cpp.C\fR implementation file that contains libev proper and is compiled:
4997.PP
4998.Vb 2
4999\& #include "ev_cpp.h"
5000\& #include "ev.c"
5001.Ve
5002.SH "INTERACTION WITH OTHER PROGRAMS, LIBRARIES OR THE ENVIRONMENT"
5003.IX Header "INTERACTION WITH OTHER PROGRAMS, LIBRARIES OR THE ENVIRONMENT"
5004.SS "THREADS AND COROUTINES"
5005.IX Subsection "THREADS AND COROUTINES"
5006\fITHREADS\fR
5007.IX Subsection "THREADS"
5008.PP
5009All libev functions are reentrant and thread\-safe unless explicitly
5010documented otherwise, but libev implements no locking itself. This means
5011that you can use as many loops as you want in parallel, as long as there
5012are no concurrent calls into any libev function with the same loop
5013parameter (\f(CW\*(C`ev_default_*\*(C'\fR calls have an implicit default loop parameter,
5014of course): libev guarantees that different event loops share no data
5015structures that need any locking.
5016.PP
5017Or to put it differently: calls with different loop parameters can be done
5018concurrently from multiple threads, calls with the same loop parameter
5019must be done serially (but can be done from different threads, as long as
5020only one thread ever is inside a call at any point in time, e.g. by using
5021a mutex per loop).
5022.PP
5023Specifically to support threads (and signal handlers), libev implements
5024so\-called \f(CW\*(C`ev_async\*(C'\fR watchers, which allow some limited form of
5025concurrency on the same event loop, namely waking it up "from the
5026outside".
5027.PP
5028If you want to know which design (one loop, locking, or multiple loops
5029without or something else still) is best for your problem, then I cannot
5030help you, but here is some generic advice:
5031.IP \(bu 4
5032most applications have a main thread: use the default libev loop
5033in that thread, or create a separate thread running only the default loop.
5034.Sp
5035This helps integrating other libraries or software modules that use libev
5036themselves and don\*(Aqt care/know about threading.
5037.IP \(bu 4
5038one loop per thread is usually a good model.
5039.Sp
5040Doing this is almost never wrong, sometimes a better\-performance model
5041exists, but it is always a good start.
5042.IP \(bu 4
5043other models exist, such as the leader/follower pattern, where one
5044loop is handed through multiple threads in a kind of round\-robin fashion.
5045.Sp
5046Choosing a model is hard \- look around, learn, know that usually you can do
5047better than you currently do :\-)
5048.IP \(bu 4
5049often you need to talk to some other thread which blocks in the
5050event loop.
5051.Sp
5052\&\f(CW\*(C`ev_async\*(C'\fR watchers can be used to wake them up from other threads safely
5053(or from signal contexts...).
5054.Sp
5055An example use would be to communicate signals or other events that only
5056work in the default loop by registering the signal watcher with the
5057default loop and triggering an \f(CW\*(C`ev_async\*(C'\fR watcher from the default loop
5058watcher callback into the event loop interested in the signal.
5059.PP
5060See also "THREAD LOCKING EXAMPLE".
5061.PP
5062\fICOROUTINES\fR
5063.IX Subsection "COROUTINES"
5064.PP
5065Libev is very accommodating to coroutines ("cooperative threads"):
5066libev fully supports nesting calls to its functions from different
5067coroutines (e.g. you can call \f(CW\*(C`ev_run\*(C'\fR on the same loop from two
5068different coroutines, and switch freely between both coroutines running
5069the loop, as long as you don\*(Aqt confuse yourself). The only exception is
5070that you must not do this from \f(CW\*(C`ev_periodic\*(C'\fR reschedule callbacks.
5071.PP
5072Care has been taken to ensure that libev does not keep local state inside
5073\&\f(CW\*(C`ev_run\*(C'\fR, and other calls do not usually allow for coroutine switches as
5074they do not call any callbacks.
5075.SS "COMPILER WARNINGS"
5076.IX Subsection "COMPILER WARNINGS"
5077Depending on your compiler and compiler settings, you might get no or a
5078lot of warnings when compiling libev code. Some people are apparently
5079scared by this.
5080.PP
5081However, these are unavoidable for many reasons. For one, each compiler
5082has different warnings, and each user has different tastes regarding
5083warning options. "Warn\-free" code therefore cannot be a goal except when
5084targeting a specific compiler and compiler\-version.
5085.PP
5086Another reason is that some compiler warnings require elaborate
5087workarounds, or other changes to the code that make it less clear and less
5088maintainable.
5089.PP
5090And of course, some compiler warnings are just plain stupid, or simply
5091wrong (because they don\*(Aqt actually warn about the condition their message
5092seems to warn about). For example, certain older gcc versions had some
5093warnings that resulted in an extreme number of false positives. These have
5094been fixed, but some people still insist on making code warn\-free with
5095such buggy versions.
5096.PP
5097While libev is written to generate as few warnings as possible,
5098"warn\-free" code is not a goal, and it is recommended not to build libev
5099with any compiler warnings enabled unless you are prepared to cope with
5100them (e.g. by ignoring them). Remember that warnings are just that:
5101warnings, not errors, or proof of bugs.
5102.SS VALGRIND
5103.IX Subsection "VALGRIND"
5104Valgrind has a special section here because it is a popular tool that is
5105highly useful. Unfortunately, valgrind reports are very hard to interpret.
5106.PP
5107If you think you found a bug (memory leak, uninitialised data access etc.)
5108in libev, then check twice: If valgrind reports something like:
5109.PP
5110.Vb 3
5111\& ==2274== definitely lost: 0 bytes in 0 blocks.
5112\& ==2274== possibly lost: 0 bytes in 0 blocks.
5113\& ==2274== still reachable: 256 bytes in 1 blocks.
5114.Ve
5115.PP
5116Then there is no memory leak, just as memory accounted to global variables
5117is not a memleak \- the memory is still being referenced, and didn\*(Aqt leak.
5118.PP
5119Similarly, under some circumstances, valgrind might report kernel bugs
5120as if it were a bug in libev (e.g. in realloc or in the poll backend,
5121although an acceptable workaround has been found here), or it might be
5122confused.
5123.PP
5124Keep in mind that valgrind is a very good tool, but only a tool. Don\*(Aqt
5125make it into some kind of religion.
5126.PP
5127If you are unsure about something, feel free to contact the mailing list
5128with the full valgrind report and an explanation on why you think this
5129is a bug in libev (best check the archives, too :). However, don\*(Aqt be
5130annoyed when you get a brisk "this is no bug" answer and take the chance
5131of learning how to interpret valgrind properly.
5132.PP
5133If you need, for some reason, empty reports from valgrind for your project
5134I suggest using suppression lists.
5135.SH "PORTABILITY NOTES"
5136.IX Header "PORTABILITY NOTES"
5137.SS "GNU/LINUX 32 BIT LIMITATIONS"
5138.IX Subsection "GNU/LINUX 32 BIT LIMITATIONS"
5139GNU/Linux is the only common platform that supports 64 bit file/large file
5140interfaces but \fIdisables\fR them by default.
5141.PP
5142That means that libev compiled in the default environment doesn\*(Aqt support
5143files larger than 2GiB or so, which mainly affects \f(CW\*(C`ev_stat\*(C'\fR watchers.
5144.PP
5145Unfortunately, many programs try to work around this GNU/Linux issue
5146by enabling the large file API, which makes them incompatible with the
5147standard libev compiled for their system.
5148.PP
5149Likewise, libev cannot enable the large file API itself as this would
5150suddenly make it incompatible to the default compile time environment,
5151i.e. all programs not using special compile switches.
5152.SS "OS/X AND DARWIN BUGS"
5153.IX Subsection "OS/X AND DARWIN BUGS"
5154The whole thing is a bug if you ask me \- basically any system interface
5155you touch is broken, whether it is locales, poll, kqueue or even the
5156OpenGL drivers.
5157.PP
5158\fR\f(CI\*(C`kqueue\*(C'\fR\fI is buggy\fR
5159.IX Subsection "kqueue is buggy"
5160.PP
5161The kqueue syscall is broken in all known versions \- most versions support
5162only sockets, many support pipes.
5163.PP
5164Libev tries to work around this by not using \f(CW\*(C`kqueue\*(C'\fR by default on this
5165rotten platform, but of course you can still ask for it when creating a
5166loop \- embedding a socket\-only kqueue loop into a select\-based one is
5167probably going to work well.
5168.PP
5169\fR\f(CI\*(C`poll\*(C'\fR\fI is buggy\fR
5170.IX Subsection "poll is buggy"
5171.PP
5172Instead of fixing \f(CW\*(C`kqueue\*(C'\fR, Apple replaced their (working) \f(CW\*(C`poll\*(C'\fR
5173implementation by something calling \f(CW\*(C`kqueue\*(C'\fR internally around the 10.5.6
5174release, so now \f(CW\*(C`kqueue\*(C'\fR \fIand\fR \f(CW\*(C`poll\*(C'\fR are broken.
5175.PP
5176Libev tries to work around this by not using \f(CW\*(C`poll\*(C'\fR by default on
5177this rotten platform, but of course you can still ask for it when creating
5178a loop.
5179.PP
5180\fR\f(CI\*(C`select\*(C'\fR\fI is buggy\fR
5181.IX Subsection "select is buggy"
5182.PP
5183All that\*(Aqs left is \f(CW\*(C`select\*(C'\fR, and of course Apple found a way to fuck this
5184one up as well: On OS/X, \f(CW\*(C`select\*(C'\fR actively limits the number of file
5185descriptors you can pass in to 1024 \- your program suddenly crashes when
5186you use more.
5187.PP
5188There is an undocumented "workaround" for this \- defining
5189\&\f(CW\*(C`_DARWIN_UNLIMITED_SELECT\*(C'\fR, which libev tries to use, so select \fIshould\fR
5190work on OS/X.
5191.SS "SOLARIS PROBLEMS AND WORKAROUNDS"
5192.IX Subsection "SOLARIS PROBLEMS AND WORKAROUNDS"
5193\fR\f(CI\*(C`errno\*(C'\fR\fI reentrancy\fR
5194.IX Subsection "errno reentrancy"
5195.PP
5196The default compile environment on Solaris is unfortunately so
5197thread\-unsafe that you can\*(Aqt even use components/libraries compiled
5198without \f(CW\*(C`\-D_REENTRANT\*(C'\fR in a threaded program, which, of course, isn\*(Aqt
5199defined by default. A valid, if stupid, implementation choice.
5200.PP
5201If you want to use libev in threaded environments you have to make sure
5202it\*(Aqs compiled with \f(CW\*(C`_REENTRANT\*(C'\fR defined.
5203.PP
5204\fIEvent port backend\fR
5205.IX Subsection "Event port backend"
5206.PP
5207The scalable event interface for Solaris is called "event
5208ports". Unfortunately, this mechanism is very buggy in all major
5209releases. If you run into high CPU usage, your program freezes or you get
5210a large number of spurious wakeups, make sure you have all the relevant
5211and latest kernel patches applied. No, I don\*(Aqt know which ones, but there
5212are multiple ones to apply, and afterwards, event ports actually work
5213great.
5214.PP
5215If you can\*(Aqt get it to work, you can try running the program by setting
5216the environment variable \f(CW\*(C`LIBEV_FLAGS=3\*(C'\fR to only allow \f(CW\*(C`poll\*(C'\fR and
5217\&\f(CW\*(C`select\*(C'\fR backends.
5218.SS "AIX POLL BUG"
5219.IX Subsection "AIX POLL BUG"
5220AIX unfortunately has a broken \f(CW\*(C`poll.h\*(C'\fR header. Libev works around
5221this by trying to avoid the poll backend altogether (i.e. it\*(Aqs not even
5222compiled in), which normally isn\*(Aqt a big problem as \f(CW\*(C`select\*(C'\fR works fine
5223with large bitsets on AIX, and AIX is dead anyway.
5224.SS "WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS"
5225.IX Subsection "WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS"
5226\fIGeneral issues\fR
5227.IX Subsection "General issues"
5228.PP
5229Win32 doesn\*(Aqt support any of the standards (e.g. POSIX) that libev
5230requires, and its I/O model is fundamentally incompatible with the POSIX
5231model. Libev still offers limited functionality on this platform in
5232the form of the \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR backend, and only supports socket
5233descriptors. This only applies when using Win32 natively, not when using
5234e.g. cygwin. Actually, it only applies to the microsofts own compilers,
5235as every compiler comes with a slightly differently broken/incompatible
5236environment.
5237.PP
5238Lifting these limitations would basically require the full
5239re\-implementation of the I/O system. If you are into this kind of thing,
5240then note that glib does exactly that for you in a very portable way (note
5241also that glib is the slowest event library known to man).
5242.PP
5243There is no supported compilation method available on windows except
5244embedding it into other applications.
5245.PP
5246Sensible signal handling is officially unsupported by Microsoft \- libev
5247tries its best, but under most conditions, signals will simply not work.
5248.PP
5249Not a libev limitation but worth mentioning: windows apparently doesn\*(Aqt
5250accept large writes: instead of resulting in a partial write, windows will
5251either accept everything or return \f(CW\*(C`ENOBUFS\*(C'\fR if the buffer is too large,
5252so make sure you only write small amounts into your sockets (less than a
5253megabyte seems safe, but this apparently depends on the amount of memory
5254available).
5255.PP
5256Due to the many, low, and arbitrary limits on the win32 platform and
5257the abysmal performance of winsockets, using a large number of sockets
5258is not recommended (and not reasonable). If your program needs to use
5259more than a hundred or so sockets, then likely it needs to use a totally
5260different implementation for windows, as libev offers the POSIX readiness
5261notification model, which cannot be implemented efficiently on windows
5262(due to Microsoft monopoly games).
5263.PP
5264A typical way to use libev under windows is to embed it (see the embedding
5265section for details) and use the following \fIevwrap.h\fR header file instead
5266of \fIev.h\fR:
5267.PP
5268.Vb 2
5269\& #define EV_STANDALONE /* keeps ev from requiring config.h */
5270\& #define EV_SELECT_IS_WINSOCKET 1 /* configure libev for windows select */
5271\&
5272\& #include "ev.h"
5273.Ve
5274.PP
5275And compile the following \fIevwrap.c\fR file into your project (make sure
5276you do \fInot\fR compile the \fIev.c\fR or any other embedded source files!):
5277.PP
5278.Vb 2
5279\& #include "evwrap.h"
5280\& #include "ev.c"
5281.Ve
5282.PP
5283\fIThe winsocket \fR\f(CI\*(C`select\*(C'\fR\fI function\fR
5284.IX Subsection "The winsocket select function"
5285.PP
5286The winsocket \f(CW\*(C`select\*(C'\fR function doesn\*(Aqt follow POSIX in that it
5287requires socket \fIhandles\fR and not socket \fIfile descriptors\fR (it is
5288also extremely buggy). This makes select very inefficient, and also
5289requires a mapping from file descriptors to socket handles (the Microsoft
5290C runtime provides the function \f(CW\*(C`_open_osfhandle\*(C'\fR for this). See the
5291discussion of the \f(CW\*(C`EV_SELECT_USE_FD_SET\*(C'\fR, \f(CW\*(C`EV_SELECT_IS_WINSOCKET\*(C'\fR and
5292\&\f(CW\*(C`EV_FD_TO_WIN32_HANDLE\*(C'\fR preprocessor symbols for more info.
5293.PP
5294The configuration for a "naked" win32 using the Microsoft runtime
5295libraries and raw winsocket select is:
5296.PP
5297.Vb 2
5298\& #define EV_USE_SELECT 1
5299\& #define EV_SELECT_IS_WINSOCKET 1 /* forces EV_SELECT_USE_FD_SET, too */
5300.Ve
5301.PP
5302Note that winsockets handling of fd sets is O(n), so you can easily get a
5303complexity in the O(nยฒ) range when using win32.
5304.PP
5305\fILimited number of file descriptors\fR
5306.IX Subsection "Limited number of file descriptors"
5307.PP
5308Windows has numerous arbitrary (and low) limits on things.
5309.PP
5310Early versions of winsocket\*(Aqs select only supported waiting for a maximum
5311of \f(CW64\fR handles (probably owning to the fact that all windows kernels
5312can only wait for \f(CW64\fR things at the same time internally; Microsoft
5313recommends spawning a chain of threads and wait for 63 handles and the
5314previous thread in each. Sounds great!).
5315.PP
5316Newer versions support more handles, but you need to define \f(CW\*(C`FD_SETSIZE\*(C'\fR
5317to some high number (e.g. \f(CW2048\fR) before compiling the winsocket select
5318call (which might be in libev or elsewhere, for example, perl and many
5319other interpreters do their own select emulation on windows).
5320.PP
5321Another limit is the number of file descriptors in the Microsoft runtime
5322libraries, which by default is \f(CW64\fR (there must be a hidden \fI64\fR
5323fetish or something like this inside Microsoft). You can increase this
5324by calling \f(CW\*(C`_setmaxstdio\*(C'\fR, which can increase this limit to \f(CW2048\fR
5325(another arbitrary limit), but is broken in many versions of the Microsoft
5326runtime libraries. This might get you to about \f(CW512\fR or \f(CW2048\fR sockets
5327(depending on windows version and/or the phase of the moon). To get more,
5328you need to wrap all I/O functions and provide your own fd management, but
5329the cost of calling select (O(nยฒ)) will likely make this unworkable.
5330.SS "PORTABILITY REQUIREMENTS"
5331.IX Subsection "PORTABILITY REQUIREMENTS"
5332In addition to a working ISO\-C implementation and of course the
5333backend\-specific APIs, libev relies on a few additional extensions:
5334.ie n .IP """void (*)(ev_watcher_type *, int revents)"" must have compatible calling conventions regardless of ""ev_watcher_type *""." 4
5335.el .IP "\f(CWvoid (*)(ev_watcher_type *, int revents)\fR must have compatible calling conventions regardless of \f(CWev_watcher_type *\fR." 4
5336.IX Item "void (*)(ev_watcher_type *, int revents) must have compatible calling conventions regardless of ev_watcher_type *."
5337Libev assumes not only that all watcher pointers have the same internal
5338structure (guaranteed by POSIX but not by ISO C for example), but it also
5339assumes that the same (machine) code can be used to call any watcher
5340callback: The watcher callbacks have different type signatures, but libev
5341calls them using an \f(CW\*(C`ev_watcher *\*(C'\fR internally.
5342.IP "pointer accesses must be thread\-atomic" 4
5343.IX Item "pointer accesses must be thread-atomic"
5344Accessing a pointer value must be atomic, it must both be readable and
5345writable in one piece \- this is the case on all current architectures.
5346.ie n .IP """sig_atomic_t volatile"" must be thread\-atomic as well" 4
5347.el .IP "\f(CWsig_atomic_t volatile\fR must be thread\-atomic as well" 4
5348.IX Item "sig_atomic_t volatile must be thread-atomic as well"
5349The type \f(CW\*(C`sig_atomic_t volatile\*(C'\fR (or whatever is defined as
5350\&\f(CW\*(C`EV_ATOMIC_T\*(C'\fR) must be atomic with respect to accesses from different
5351threads. This is not part of the specification for \f(CW\*(C`sig_atomic_t\*(C'\fR, but is
5352believed to be sufficiently portable.
5353.ie n .IP """sigprocmask"" must work in a threaded environment" 4
5354.el .IP "\f(CWsigprocmask\fR must work in a threaded environment" 4
5355.IX Item "sigprocmask must work in a threaded environment"
5356Libev uses \f(CW\*(C`sigprocmask\*(C'\fR to temporarily block signals. This is not
5357allowed in a threaded program (\f(CW\*(C`pthread_sigmask\*(C'\fR has to be used). Typical
5358pthread implementations will either allow \f(CW\*(C`sigprocmask\*(C'\fR in the "main
5359thread" or will block signals process\-wide, both behaviours would
5360be compatible with libev. Interaction between \f(CW\*(C`sigprocmask\*(C'\fR and
5361\&\f(CW\*(C`pthread_sigmask\*(C'\fR could complicate things, however.
5362.Sp
5363The most portable way to handle signals is to block signals in all threads
5364except the initial one, and run the signal handling loop in the initial
5365thread as well.
5366.ie n .IP """long"" must be large enough for common memory allocation sizes" 4
5367.el .IP "\f(CWlong\fR must be large enough for common memory allocation sizes" 4
5368.IX Item "long must be large enough for common memory allocation sizes"
5369To improve portability and simplify its API, libev uses \f(CW\*(C`long\*(C'\fR internally
5370instead of \f(CW\*(C`size_t\*(C'\fR when allocating its data structures. On non\-POSIX
5371systems (Microsoft...) this might be unexpectedly low, but is still at
5372least 31 bits everywhere, which is enough for hundreds of millions of
5373watchers.
5374.ie n .IP """double"" must hold a time value in seconds with enough accuracy" 4
5375.el .IP "\f(CWdouble\fR must hold a time value in seconds with enough accuracy" 4
5376.IX Item "double must hold a time value in seconds with enough accuracy"
5377The type \f(CW\*(C`double\*(C'\fR is used to represent timestamps. It is required to
5378have at least 51 bits of mantissa (and 9 bits of exponent), which is
5379good enough for at least into the year 4000 with millisecond accuracy
5380(the design goal for libev). This requirement is overfulfilled by
5381implementations using IEEE 754, which is basically all existing ones.
5382.Sp
5383With IEEE 754 doubles, you get microsecond accuracy until at least the
5384year 2255 (and millisecond accuracy till the year 287396 \- by then, libev
5385is either obsolete or somebody patched it to use \f(CW\*(C`long double\*(C'\fR or
5386something like that, just kidding).
5387.PP
5388If you know of other additional requirements drop me a note.
5389.SH "ALGORITHMIC COMPLEXITIES"
5390.IX Header "ALGORITHMIC COMPLEXITIES"
5391In this section the complexities of (many of) the algorithms used inside
5392libev will be documented. For complexity discussions about backends see
5393the documentation for \f(CW\*(C`ev_default_init\*(C'\fR.
5394.PP
5395All of the following are about amortised time: If an array needs to be
5396extended, libev needs to realloc and move the whole array, but this
5397happens asymptotically rarer with higher number of elements, so O(1) might
5398mean that libev does a lengthy realloc operation in rare cases, but on
5399average it is much faster and asymptotically approaches constant time.
5400.IP "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)" 4
5401.IX Item "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)"
5402This means that, when you have a watcher that triggers in one hour and
5403there are 100 watchers that would trigger before that, then inserting will
5404have to skip roughly seven (\f(CW\*(C`ld 100\*(C'\fR) of these watchers.
5405.IP "Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers)" 4
5406.IX Item "Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers)"
5407That means that changing a timer costs less than removing/adding them,
5408as only the relative motion in the event queue has to be paid for.
5409.IP "Starting io/check/prepare/idle/signal/child/fork/async watchers: O(1)" 4
5410.IX Item "Starting io/check/prepare/idle/signal/child/fork/async watchers: O(1)"
5411These just add the watcher into an array or at the head of a list.
5412.IP "Stopping check/prepare/idle/fork/async watchers: O(1)" 4
5413.IX Item "Stopping check/prepare/idle/fork/async watchers: O(1)"
5414.PD 0
5415.IP "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))" 4
5416.IX Item "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))"
5417.PD
5418These watchers are stored in lists, so they need to be walked to find the
5419correct watcher to remove. The lists are usually short (you don\*(Aqt usually
5420have many watchers waiting for the same fd or signal: one is typical, two
5421is rare).
5422.IP "Finding the next timer in each loop iteration: O(1)" 4
5423.IX Item "Finding the next timer in each loop iteration: O(1)"
5424By virtue of using a binary or 4\-heap, the next timer is always found at a
5425fixed position in the storage array.
5426.IP "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 4
5427.IX Item "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)"
5428A change means an I/O watcher gets started or stopped, which requires
5429libev to recalculate its status (and possibly tell the kernel, depending
5430on backend and whether \f(CW\*(C`ev_io_set\*(C'\fR was used).
5431.IP "Activating one watcher (putting it into the pending state): O(1)" 4
5432.IX Item "Activating one watcher (putting it into the pending state): O(1)"
5433.PD 0
5434.IP "Priority handling: O(number_of_priorities)" 4
5435.IX Item "Priority handling: O(number_of_priorities)"
5436.PD
5437Priorities are implemented by allocating some space for each
5438priority. When doing priority\-based operations, libev usually has to
5439linearly search all the priorities, but starting/stopping and activating
5440watchers becomes O(1) with respect to priority handling.
5441.IP "Sending an ev_async: O(1)" 4
5442.IX Item "Sending an ev_async: O(1)"
5443.PD 0
5444.IP "Processing ev_async_send: O(number_of_async_watchers)" 4
5445.IX Item "Processing ev_async_send: O(number_of_async_watchers)"
5446.IP "Processing signals: O(max_signal_number)" 4
5447.IX Item "Processing signals: O(max_signal_number)"
5448.PD
5449Sending involves a system call \fIiff\fR there were no other \f(CW\*(C`ev_async_send\*(C'\fR
5450calls in the current loop iteration and the loop is currently
5451blocked. Checking for async and signal events involves iterating over all
5452running async watchers or all signal numbers.
5453.SH "PORTING FROM LIBEV 3.X TO 4.X"
5454.IX Header "PORTING FROM LIBEV 3.X TO 4.X"
5455The major version 4 introduced some incompatible changes to the API.
5456.PP
5457At the moment, the \f(CW\*(C`ev.h\*(C'\fR header file provides compatibility definitions
5458for all changes, so most programs should still compile. The compatibility
5459layer might be removed in later versions of libev, so better update to the
5460new API early than late.
5461.ie n .IP """EV_COMPAT3"" backwards compatibility mechanism" 4
5462.el .IP "\f(CWEV_COMPAT3\fR backwards compatibility mechanism" 4
5463.IX Item "EV_COMPAT3 backwards compatibility mechanism"
5464The backward compatibility mechanism can be controlled by
5465\&\f(CW\*(C`EV_COMPAT3\*(C'\fR. See "PREPROCESSOR SYMBOLS/MACROS" in the "EMBEDDING"
5466section.
5467.ie n .IP """ev_default_destroy"" and ""ev_default_fork"" have been removed" 4
5468.el .IP "\f(CWev_default_destroy\fR and \f(CWev_default_fork\fR have been removed" 4
5469.IX Item "ev_default_destroy and ev_default_fork have been removed"
5470These calls can be replaced easily by their \f(CW\*(C`ev_loop_xxx\*(C'\fR counterparts:
5471.Sp
5472.Vb 2
5473\& ev_loop_destroy (EV_DEFAULT_UC);
5474\& ev_loop_fork (EV_DEFAULT);
5475.Ve
5476.IP "function/symbol renames" 4
5477.IX Item "function/symbol renames"
5478A number of functions and symbols have been renamed:
5479.Sp
5480.Vb 3
5481\& ev_loop => ev_run
5482\& EVLOOP_NONBLOCK => EVRUN_NOWAIT
5483\& EVLOOP_ONESHOT => EVRUN_ONCE
5484\&
5485\& ev_unloop => ev_break
5486\& EVUNLOOP_CANCEL => EVBREAK_CANCEL
5487\& EVUNLOOP_ONE => EVBREAK_ONE
5488\& EVUNLOOP_ALL => EVBREAK_ALL
5489\&
5490\& EV_TIMEOUT => EV_TIMER
5491\&
5492\& ev_loop_count => ev_iteration
5493\& ev_loop_depth => ev_depth
5494\& ev_loop_verify => ev_verify
5495.Ve
5496.Sp
5497Most functions working on \f(CW\*(C`struct ev_loop\*(C'\fR objects don\*(Aqt have an
5498\&\f(CW\*(C`ev_loop_\*(C'\fR prefix, so it was removed; \f(CW\*(C`ev_loop\*(C'\fR, \f(CW\*(C`ev_unloop\*(C'\fR and
5499associated constants have been renamed to not collide with the \f(CW\*(C`struct
5500ev_loop\*(C'\fR anymore and \f(CW\*(C`EV_TIMER\*(C'\fR now follows the same naming scheme
5501as all other watcher types. Note that \f(CW\*(C`ev_loop_fork\*(C'\fR is still called
5502\&\f(CW\*(C`ev_loop_fork\*(C'\fR because it would otherwise clash with the \f(CW\*(C`ev_fork\*(C'\fR
5503typedef.
5504.ie n .IP """EV_MINIMAL"" mechanism replaced by ""EV_FEATURES""" 4
5505.el .IP "\f(CWEV_MINIMAL\fR mechanism replaced by \f(CWEV_FEATURES\fR" 4
5506.IX Item "EV_MINIMAL mechanism replaced by EV_FEATURES"
5507The preprocessor symbol \f(CW\*(C`EV_MINIMAL\*(C'\fR has been replaced by a different
5508mechanism, \f(CW\*(C`EV_FEATURES\*(C'\fR. Programs using \f(CW\*(C`EV_MINIMAL\*(C'\fR usually compile
5509and work, but the library code will of course be larger.
5510.SH GLOSSARY
5511.IX Header "GLOSSARY"
5512.IP active 4
5513.IX Item "active"
5514A watcher is active as long as it has been started and not yet stopped.
5515See "WATCHER STATES" for details.
5516.IP application 4
5517.IX Item "application"
5518In this document, an application is whatever is using libev.
5519.IP backend 4
5520.IX Item "backend"
5521The part of the code dealing with the operating system interfaces.
5522.IP callback 4
5523.IX Item "callback"
5524The address of a function that is called when some event has been
5525detected. Callbacks are being passed the event loop, the watcher that
5526received the event, and the actual event bitset.
5527.IP "callback/watcher invocation" 4
5528.IX Item "callback/watcher invocation"
5529The act of calling the callback associated with a watcher.
5530.IP event 4
5531.IX Item "event"
5532A change of state of some external event, such as data now being available
5533for reading on a file descriptor, time having passed or simply not having
5534any other events happening anymore.
5535.Sp
5536In libev, events are represented as single bits (such as \f(CW\*(C`EV_READ\*(C'\fR or
5537\&\f(CW\*(C`EV_TIMER\*(C'\fR).
5538.IP "event library" 4
5539.IX Item "event library"
5540A software package implementing an event model and loop.
5541.IP "event loop" 4
5542.IX Item "event loop"
5543An entity that handles and processes external events and converts them
5544into callback invocations.
5545.IP "event model" 4
5546.IX Item "event model"
5547The model used to describe how an event loop handles and processes
5548watchers and events.
5549.IP pending 4
5550.IX Item "pending"
5551A watcher is pending as soon as the corresponding event has been
5552detected. See "WATCHER STATES" for details.
5553.IP "real time" 4
5554.IX Item "real time"
5555The physical time that is observed. It is apparently strictly monotonic :)
5556.IP "wall\-clock time" 4
5557.IX Item "wall-clock time"
5558The time and date as shown on clocks. Unlike real time, it can actually
5559be wrong and jump forwards and backwards, e.g. when you adjust your
5560clock.
5561.IP watcher 4
5562.IX Item "watcher"
5563A data structure that describes interest in certain events. Watchers need
5564to be started (attached to an event loop) before they can receive events.
5565.SH AUTHOR
5566.IX Header "AUTHOR"
5567Marc Lehmann <libev@schmorp.de>, with repeated corrections by Mikael
5568Magnusson and Emanuele Giaquinta, and minor corrections by many others.