1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
This commit is contained in:
stefanocasazza 2020-06-13 17:31:43 +02:00
parent 970bccff52
commit 92ce49bd94
30 changed files with 977 additions and 873 deletions

5
configure vendored
View File

@ -25809,11 +25809,6 @@ $as_echo "#define HAVE_EPOLL_CREATE1 1" >>confdefs.h
$as_echo "#define HAVE_EPOLL_WAIT 1" >>confdefs.h
;;
epoll_ctl_batch)
$as_echo "#define HAVE_EPOLL_CTL_BATCH 1" >>confdefs.h
;;
fallocate)
if true; then

View File

@ -1133,9 +1133,6 @@ for func in accept4 atexit clock_gettime daemon dup3 epoll_create1 epoll_wait ep
epoll_wait)
AC_DEFINE(HAVE_EPOLL_WAIT, [1], [has epoll_wait])
;;
epoll_ctl_batch)
AC_DEFINE(HAVE_EPOLL_CTL_BATCH, [1], [has epoll_ctl_batch])
;;
fallocate)
AM_CONDITIONAL(FALLOCATE, true)
AC_DEFINE(HAVE_FALLOCATE, [1], [has fallocate])

View File

@ -221,7 +221,7 @@ typedef int (*iPFpv) (void*);
typedef bool (*bPFpc) (const char*);
typedef void (*vPFpc) (const char*);
typedef void* (*pvPFpv) (void*);
typedef void (*vpFpcu) (const char*,uint32_t);
typedef void (*vPFpcu) (const char*,uint32_t);
typedef bool (*bPFpcu) (const char*,uint32_t);
typedef void (*vPFpvu) (void*,uint32_t);
typedef int (*iPFpvpv) (void*,void*);

View File

@ -225,7 +225,7 @@ public:
UString print();
#ifdef U_STDCPP_ENABLE
static vpFpcu getValueFromBuffer;
static vPFpcu getValueFromBuffer;
friend U_EXPORT istream& operator>>(istream& is, UCDB& cdb);
friend U_EXPORT ostream& operator<<(ostream& os, UCDB& cdb);

View File

@ -92,8 +92,9 @@ public:
virtual int handlerWrite() { return U_NOTIFIER_DELETE; }
virtual int handlerTimeout() { return U_NOTIFIER_DELETE; }
virtual int handlerConnect() { return U_NOTIFIER_DELETE; }
virtual int handlerRequest() { return 0; }
virtual void handlerDelete() { delete this; }
virtual void handlerDelete() { delete this; }
#ifdef USE_LIBEVENT
UEvent<UEventFd>* pevent;

View File

@ -18,6 +18,7 @@
class UTimer;
class UNotifier;
class UServer_Base;
#ifdef USE_LIBEVENT
template <class T> class UTimerEv;
#endif
@ -305,6 +306,7 @@ private:
friend class UTimer;
friend class UNotifier;
friend class UServer_Base;
};
#endif

View File

@ -156,9 +156,6 @@
/* has epoll_create1 */
#undef HAVE_EPOLL_CREATE1
/* has epoll_ctl_batch */
#undef HAVE_EPOLL_CTL_BATCH
/* has epoll_wait */
#undef HAVE_EPOLL_WAIT

View File

@ -48,10 +48,18 @@ template <class T> class UHashMap;
#define U_ClientImage_request_is_cached UClientImage_Base::cbuffer[0]
#define U_ClientImage_http(obj) (obj)->UClientImage_Base::flag.c[0]
#define U_ClientImage_idle(obj) (obj)->UClientImage_Base::flag.c[1]
#define U_ClientImage_pclose(obj) (obj)->UClientImage_Base::flag.c[2]
#define U_ClientImage_request_is_from_userver(obj) (obj)->UClientImage_Base::flag.c[3]
#define U_ClientImage_is_wsk(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x01) != 0)
#define U_ClientImage_is_http2(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x02) != 0)
#define U_ClientImage_is_http3(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x04) != 0)
#define U_ClientImage_is_idle(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x08) != 0)
#define U_ClientImage_is_close(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x10) != 0)
#define U_ClientImage_is_delete(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x20) != 0)
#define U_ClientImage_user1_flag(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x40) != 0)
#define U_ClientImage_user2_flag(obj) (((obj)->UClientImage_Base::flag.c[0] & 0x80) != 0)
#define U_ClientImage_op_pending(obj) (obj)->UClientImage_Base::flag.c[1]
#define U_ClientImage_idx_buffer(obj) (obj)->UClientImage_Base::flag.c[2]
#define U_ClientImage_user_value(obj) (obj)->UClientImage_Base::flag.c[3]
class U_EXPORT UClientImage_Base : public UEventFd {
public:
@ -84,6 +92,7 @@ public:
virtual int handlerRead() U_DECL_OVERRIDE;
virtual int handlerWrite() U_DECL_FINAL;
virtual int handlerTimeout() U_DECL_FINAL;
virtual int handlerRequest() U_DECL_OVERRIDE;
virtual void handlerDelete() U_DECL_FINAL;
static void init();
@ -145,7 +154,7 @@ public:
{
U_TRACE_NO_PARAM(0, "UClientImage_Base::isRequestNotFound()")
U_INTERNAL_DUMP("U_ClientImage_request = %d %B", U_ClientImage_request, U_ClientImage_request)
U_INTERNAL_DUMP("U_ClientImage_request = %u %B", U_ClientImage_request, U_ClientImage_request)
# ifdef U_CACHE_REQUEST_DISABLE
if (U_ClientImage_request == 0) U_RETURN(true);
@ -250,7 +259,7 @@ public:
{
U_TRACE_NO_PARAM(0, "UClientImage_Base::isRequestRedirected()")
U_INTERNAL_DUMP("U_ClientImage_request = %d %B U_http_info.nResponseCode = %d", U_ClientImage_request,
U_INTERNAL_DUMP("U_ClientImage_request = %u %B U_http_info.nResponseCode = %u", U_ClientImage_request,
U_ClientImage_request, U_http_info.nResponseCode)
if ((U_ClientImage_request & ALREADY_PROCESSED) != 0 &&
@ -270,7 +279,7 @@ public:
# ifndef U_CACHE_REQUEST_DISABLE
U_ClientImage_request |= NO_CACHE;
U_INTERNAL_DUMP("U_ClientImage_request = %d %B", U_ClientImage_request, U_ClientImage_request)
U_INTERNAL_DUMP("U_ClientImage_request = %u %B", U_ClientImage_request, U_ClientImage_request)
# endif
}
@ -384,14 +393,6 @@ protected:
// HTTP3
void* conn;
void* http3;
#ifdef USE_LIBURING
// int pendingOp; // we use UEventFd::op_mask as last operation
uint32_t bufIndex, bufsz;
// turn false if we should close the socket
virtual bool handlerAccept(int newfd);
virtual bool handlerRequest(const UString& req, UString& response);
#endif
#ifndef U_LOG_DISABLE
static int log_request_partial;
@ -487,29 +488,6 @@ protected:
static void manageReadBufferResize(uint32_t n);
static void setSendfile(int fd, off_t start, off_t count);
bool isRequestFromUServer()
{
U_TRACE_NO_PARAM(0, "UClientImage_Base::isRequestFromUServer()")
if (U_ClientImage_request_is_from_userver(this) != false) U_RETURN(true);
U_RETURN(false);
}
void setRequestFromUServer()
{
U_TRACE_NO_PARAM(0, "UClientImage_Base::setRequestFromUServer()")
U_ClientImage_request_is_from_userver(this) = true;
}
void resetRequestFromUServer()
{
U_TRACE_NO_PARAM(0, "UClientImage_Base::resetRequestFromUServer()")
U_ClientImage_request_is_from_userver(this) = true;
}
void prepareForSendfile();
#if defined(U_THROTTLING_SUPPORT) || defined(U_CLIENT_RESPONSE_PARTIAL_WRITE_SUPPORT)
@ -521,7 +499,7 @@ protected:
prepareForSendfile();
U_ClientImage_pclose(this) |= U_CLOSE;
flag.c[0] |= 0x10;
}
#endif

View File

@ -15,7 +15,6 @@
#define U_MOD_NOCAT_H 1
#include <ulib/url.h>
#include <ulib/timer.h>
#include <ulib/command.h>
#include <ulib/net/ping.h>
#include <ulib/net/tcpsocket.h>

View File

@ -15,7 +15,6 @@
#define U_MOD_NODOG_H 1
#include <ulib/url.h>
#include <ulib/timer.h>
#include <ulib/command.h>
#include <ulib/net/tcpsocket.h>
#include <ulib/net/client/http.h>

View File

@ -15,6 +15,7 @@
#define U_SERVER_H 1
#include <ulib/log.h>
#include <ulib/timer.h>
#include <ulib/process.h>
#include <ulib/command.h>
#include <ulib/notifier.h>
@ -693,7 +694,6 @@ public:
static bool isLocalHost() { return csocket->cRemoteAddress.isLocalHost(); }
static void setClientAddress() { setClientAddress(csocket, client_address, client_address_len); }
static in_addr_t getClientAddress() { return csocket->getClientAddress(); }
static UString getIPAddress() { return *IP_address; }
@ -890,7 +890,7 @@ protected:
static USmtpClient* emailClient;
static long last_time_email_crash;
static UString* crashEmailAddress;
static bool monitoring_process, set_realtime_priority, public_address, binsert, set_tcp_keep_alive, called_from_handlerTime;
static bool monitoring_process, set_realtime_priority, public_address, binsert, baffinity, set_tcp_keep_alive, called_from_handlerTime;
static uint32_t vplugin_size;
static UVector<UString>* vplugin_name;
@ -903,8 +903,29 @@ protected:
static void runLoop(const char* user);
static bool handlerTimeoutConnection(void* cimg);
static void postEvent()
{
U_TRACE_NO_PARAM(0, "UServer_Base::postEvent()")
U_INTERNAL_ASSERT_POINTER(ptime)
# if !defined(U_LOG_DISABLE) && defined(DEBUG)
last_event = u_now->tv_sec;
# ifndef _MSWINDOWS_
if (monitoring_process &&
U_SYSCALL_NO_PARAM(getppid) == 1)
{
U_ERROR("the monitoring process has crashed, exiting...");
}
# endif
# endif
UTimer::updateTimeToExpire(ptime);
}
#ifndef U_LOG_DISABLE
static void logNewClient(USocket* psocket, UClientImage_Base* lClientImage);
static void logNewClient(int fd);
#endif
#ifdef U_WELCOME_SUPPORT
@ -1067,45 +1088,44 @@ protected:
static UString* rwBuffers;
static uint32_t bufNextIndex;
static struct io_uring_cqe* cqe;
static struct io_uring io_uring;
static struct io_uring_params params;
static struct io_uring* io_uring;
static void register_files_update(int newfd)
{
U_TRACE(0, "UServer_Base::register_files_update(%d)", newfd)
// ...fd member is the index of the file in the file descriptor array
U_INTERNAL_DUMP("socketfds[%u] = %d", nClientIndex, socketfds[nClientIndex])
int ret = U_SYSCALL(io_uring_register_files_update, "%p,%u,%p,%u", &io_uring, nClientIndex, &(socketfds[nClientIndex] = newfd), 1);
if (ret != 1)
{
U_ERROR("io_uring_register_files_update() failed: %d%R", ret, 0); // NB: the last argument (0) is necessary...
}
pClientImage->fd = newfd;
}
static void wait_cqe()
static int wait_cqe()
{
U_TRACE_NO_PARAM(0, "UServer_Base::wait_cqe()")
int ret = U_SYSCALL(io_uring_wait_cqe, "%p,%p", &io_uring, &cqe);
int ret = U_SYSCALL(io_uring_wait_cqe, "%p,%p", io_uring, &cqe);
if (ret)
{
U_ERROR("io_uring_wait_cqe() failed: %d%R", ret, 0); // NB: the last argument (0) is necessary...
if (ret == -EINTR) UInterrupt::checkForEventSignalPending();
else
{
U_ERROR("io_uring_wait_cqe() failed: %d%R", ret, 0); // NB: the last argument (0) is necessary...
}
}
nClientIndex = (pClientImage = (UClientImage_Base*)cqe->user_data) - vClientImage;
U_RETURN(ret);
}
U_INTERNAL_DUMP("vClientImage[%u].UEventFd::op_mask = %u", nClientIndex, pClientImage->UEventFd::op_mask)
static void insertBatch(int ctl_cmd_cnt)
{
U_TRACE(0, "UServer_Base::insertBatch(%d)", ctl_cmd_cnt)
while (ctl_cmd_cnt--)
{
(void) wait_cqe();
U_INTERNAL_ASSERT_EQUALS(cqe->user_data, 0xff)
U_SYSCALL_VOID(io_uring_cqe_seen, "%p,%p", io_uring, cqe); // signal that we consumed one
}
}
static void submit(int op);
static void findNextClientImage();
static int batch(UEventFd* handler_event);
static void waitForEvent(UEventTime* ptimeout);
#endif
UServer_Base(UFileConfig* cfg = U_NULLPTR);
@ -1140,6 +1160,8 @@ protected:
virtual bool check_memory() = 0;
#endif
virtual bool handlerAccept(int newfd); // turn false if we should close the socket
// SERVICES
static void suspendThread();
@ -1204,16 +1226,14 @@ private:
if (pluginsHandlerSigHUP() != U_PLUGIN_HANDLER_FINISHED) U_WARNING("Plugins stage SigHUP failed...");
}
static void setClientAddress(USocket* psocket, char*& pclient_address, uint32_t& pclient_address_len)
static void setClientAddress()
{
U_TRACE(0, "UServer_Base::setClientAddress(%p,%p,%u)", psocket, pclient_address, pclient_address_len)
U_TRACE_NO_PARAM(0, "UServer_Base::setClientAddress()")
U_INTERNAL_ASSERT(psocket->isConnected())
client_address = UIPAddress::resolveStrAddress(iAddressType, csocket->cRemoteAddress.pcAddress.p, csocket->cRemoteAddress.pcStrAddress);
client_address_len = u__strlen(client_address, __PRETTY_FUNCTION__);
pclient_address = UIPAddress::resolveStrAddress(iAddressType, psocket->cRemoteAddress.pcAddress.p, psocket->cRemoteAddress.pcStrAddress);
pclient_address_len = u__strlen(pclient_address, __PRETTY_FUNCTION__);
U_INTERNAL_DUMP("client_address = %.*S", pclient_address_len, pclient_address)
U_INTERNAL_DUMP("client_address = %.*S", U_CLIENT_ADDRESS_TO_TRACE)
}
static void logMemUsage(const char* signame)
@ -1235,6 +1255,7 @@ private:
# endif
}
static bool postAccept() U_NO_EXPORT;
static bool clientImageHandlerRead() U_NO_EXPORT;
static void loadStaticLinkedModules(const UString& name) U_NO_EXPORT;
static void manageCommand(const char* format, uint32_t fmt_size, ...) U_NO_EXPORT;

View File

@ -82,7 +82,7 @@ class UREDISClient_Base;
#define U_socket_Type(obj) (obj)->USocket::flag[2]
#define U_socket_unused(obj) (obj)->USocket::flag[3]
enum SocketOperation { none, _accept, _read, _write, _close };
enum SocketOperation { none, _accept, _read, _write, _close, _update, _poll };
class U_EXPORT USocket {
public:
@ -843,6 +843,15 @@ protected:
static void setLocalInfo( USocket* p, SocketAddress* cLocal);
static void setRemoteInfo(USocket* p, SocketAddress* cRemote);
static void resetPeerAddr()
{
U_TRACE_NO_PARAM(0, "USocket::resetPeerAddr()")
peer_addr_len = sizeof(peer_addr);
(void) U_SYSCALL(memset, "%p,%d,%u", &peer_addr, 0, U_SIZE_SOCKADDR);
}
/**
* The _socket() function is called to create the socket of the specified type.
* The parameters indicate whether the socket will use IPv6 or IPv4 and the type of socket

View File

@ -110,25 +110,10 @@ public:
static void suspend(UEventFd* item);
static void resume(UEventFd* item, uint32_t flags = EPOLLOUT);
static void waitForEvent();
static void waitForEvent( UEventTime* ptimeout);
static int waitForEvent(int fd_max, fd_set* read_set, fd_set* write_set, UEventTime* ptimeout);
static void waitForEvent1( UEventTime* ptimeout);
static int waitForEvent4(int fd_max, fd_set* read_set, fd_set* write_set, UEventTime* ptimeout);
# ifdef HAVE_EPOLL_CTL_BATCH
static void insertBatch()
{
U_TRACE_NO_PARAM(0, "UNotifier::insertBatch()")
if (ctl_cmd_cnt)
{
(void) U_SYSCALL(epoll_ctl_batch, "%d,%d,%d,%p", epollfd, 0, ctl_cmd_cnt, ctl_cmd);
ctl_cmd_cnt = 0;
}
}
static void batch((UEventFd* handler_event);
# endif
static void waitForEvent(vPFpv waitForEventFunc = (vPFpv)UNotifier::waitForEvent1);
#else
static void init()
{
@ -160,16 +145,16 @@ public:
// TODO: implement resume() for libevent
}
static int waitForEvent(int fd_max, fd_set* read_set, fd_set* write_set, UEventTime* ptimeout)
static int waitForEvent4(int fd_max, fd_set* read_set, fd_set* write_set, UEventTime* ptimeout)
{
U_TRACE(0, "UNotifier::waitForEvent(%d,%p,%p,%p)", fd_max, read_set, write_set, ptimeout)
U_TRACE(0, "UNotifier::waitForEvent4(%d,%p,%p,%p)", fd_max, read_set, write_set, ptimeout)
U_RETURN(-1);
}
static void waitForEvent(UEventTime* ptimeout)
static void waitForEvent1(UEventTime* ptimeout)
{
U_TRACE(0, "UNotifier::waitForEvent(%p)", ptimeout)
U_TRACE(0, "UNotifier::waitForEvent1(%p)", ptimeout)
(void) UDispatcher::dispatch(UDispatcher::ONCE);
}
@ -221,10 +206,6 @@ protected:
# ifdef U_EPOLLET_POSTPONE_STRATEGY
static bool bepollet;
# endif
# ifdef HAVE_EPOLL_CTL_BATCH
static int ctl_cmd_cnt;
static struct epoll_ctl_cmd ctl_cmd[U_EPOLL_CTL_CMD_SIZE];
# endif
# elif defined(HAVE_KQUEUE)
static int kq, nkqevents;
static struct kevent* kqevents;

View File

@ -2369,7 +2369,7 @@ public:
U_INTERNAL_ASSERT(invariant())
}
static vpFpcu printValueToBuffer;
static vPFpcu printValueToBuffer;
void printKeyValue(const char* key, uint32_t keylen, const char* data, uint32_t datalen);

View File

@ -51,17 +51,15 @@ public:
U_RETURN_STRING(result);
}
static void setRemoteInfo(USocket* sk, UString& logbuf)
static void setRemoteInfo(int fd, USocket* sk, UString& logbuf)
{
U_TRACE(0, "USocketExt::setRemoteInfo(%p,%V)", sk, logbuf.rep)
U_TRACE(0, "USocketExt::setRemoteInfo(%d,%p,%V)", fd, sk, logbuf.rep)
UString x(100U);
x.snprintf(U_CONSTANT_TO_PARAM("%2d '%s:%u'"), sk->iSockDesc, sk->cRemoteAddress.pcStrAddress, sk->iRemotePort);
(void) logbuf.insert(0, x);
(void) logbuf.insert(0, u_buffer, u__snprintf(u_buffer, U_BUFFER_SIZE, U_CONSTANT_TO_PARAM("%2d '%s:%u'"), fd, sk->cRemoteAddress.pcStrAddress, sk->iRemotePort));
}
static void setRemoteInfo(USocket* sk, UString& logbuf) { setRemoteInfo(sk->iSockDesc, sk, logbuf); }
static bool getARPCache(UString& cache, UVector<UString>& vec);
static UString getNetworkDevice(const char* exclude = "eth0");

View File

@ -881,7 +881,7 @@ U_NO_EXPORT void UCDB::checkForAllEntry()
// STREAM
#ifdef U_STDCPP_ENABLE
vpFpcu UCDB::getValueFromBuffer;
vPFpcu UCDB::getValueFromBuffer;
class mystreambuf : public streambuf {
public:

View File

@ -129,10 +129,6 @@ UClientImage_Base::UClientImage_Base()
max_limit =
started_at = 0;
#endif
#ifdef USE_LIBURING
bufIndex = bufsz = 0;
UEventFd::op_mask = SocketOperation::none;
#endif
if (UServer_Base::isLog()) U_NEW_STRING(logbuf, UString(200U));
@ -283,15 +279,18 @@ void UClientImage_Base::init()
U_INTERNAL_ASSERT_EQUALS(usp_buffer, U_NULLPTR)
U_INTERNAL_ASSERT_EQUALS(usp_encoded, U_NULLPTR)
U_INTERNAL_ASSERT_EQUALS(request_uri, U_NULLPTR)
U_INTERNAL_ASSERT_EQUALS(environment, U_NULLPTR)
U_INTERNAL_ASSERT_EQUALS(chronometer, U_NULLPTR)
#ifdef USE_LIBURING
if (UServer_Base::brng == false)
if (UServer_Base::brng)
{
U_NEW_STRING(rbuffer, UString);
U_NEW_STRING(wbuffer, UString);
}
else
#endif
{
U_NEW_STRING(body, UString);
U_NEW_STRING(wbuffer, UString(U_CAPACITY));
U_NEW_STRING(request, UString);
uint32_t sz = 8192;
#ifdef USERVER_UDP
@ -299,8 +298,11 @@ void UClientImage_Base::init()
#endif
U_NEW_STRING(rbuffer, UString(sz));
U_NEW_STRING(wbuffer, UString(U_CAPACITY));
}
U_NEW_STRING(body, UString);
U_NEW_STRING(request, UString);
U_NEW_STRING(request_uri, UString);
U_NEW_STRING(environment, UString(U_CAPACITY));
@ -323,11 +325,19 @@ void UClientImage_Base::clear()
{
U_TRACE_NO_PARAM(0, "UClientImage_Base::clear()")
if (request_uri)
if (body)
{
U_INTERNAL_ASSERT_POINTER(rbuffer)
U_INTERNAL_ASSERT_POINTER(wbuffer)
U_INTERNAL_ASSERT_POINTER(request)
U_INTERNAL_ASSERT_POINTER(request_uri)
U_INTERNAL_ASSERT_POINTER(environment)
U_INTERNAL_ASSERT_POINTER(chronometer)
U_DELETE(body)
U_DELETE(wbuffer)
U_DELETE(rbuffer)
U_DELETE(request)
U_DELETE(request_uri)
U_DELETE(environment)
U_DELETE(chronometer)
@ -342,18 +352,6 @@ void UClientImage_Base::clear()
U_DELETE(usp_buffer)
U_DELETE(usp_encoded)
}
if (body)
{
U_INTERNAL_ASSERT_POINTER(wbuffer)
U_INTERNAL_ASSERT_POINTER(request)
U_INTERNAL_ASSERT_POINTER(rbuffer)
U_DELETE(body)
U_DELETE(wbuffer)
U_DELETE(request)
U_DELETE(rbuffer)
}
}
// Check whether the ip address client ought to be allowed
@ -575,14 +573,14 @@ void UClientImage_Base::handlerDelete()
bsocket_open = false;
}
U_INTERNAL_DUMP("U_ClientImage_http = %C U_http_version = %C", U_ClientImage_http(this), U_http_version)
U_INTERNAL_DUMP("U_ClientImage_is_http2 = %b U_ClientImage_is_wsk = %b U_http_version = %C", U_ClientImage_is_http2(this), U_ClientImage_is_wsk(this), U_http_version)
#ifndef U_HTTP2_DISABLE
if (U_ClientImage_http(this) == '2') UHTTP2::handlerDelete(this, bsocket_open);
if (U_ClientImage_is_http2(this)) UHTTP2::handlerDelete(this, bsocket_open);
#endif
#ifndef U_WEBSOCKET_PARALLELIZATION
if (U_ClientImage_http(this) == '0')
if (U_ClientImage_is_wsk(this))
{
if (bsocket_open &&
(UWebSocket::status_code == U_WS_STATUS_CODE_GOING_AWAY || UWebSocket::sendClose(true, socket)))
@ -617,10 +615,10 @@ void UClientImage_Base::handlerDelete()
}
else if (isPendingSendfile())
{
U_INTERNAL_DUMP("sfd = %d count = %I UEventFd::op_mask = %B U_ClientImage_pclose(this) = %d %B",
sfd, count, UEventFd::op_mask, U_ClientImage_pclose(this), U_ClientImage_pclose(this))
U_INTERNAL_DUMP("sfd = %d count = %I UEventFd::op_mask = %B U_ClientImage_is_close(this) = %b",
sfd, count, UEventFd::op_mask, U_ClientImage_is_close(this))
if ((U_ClientImage_pclose(this) & U_CLOSE) != 0)
if ((U_ClientImage_is_close(this)))
{
# ifdef DEBUG
if (UNLIKELY(sfd <= 0))
@ -688,9 +686,9 @@ int UClientImage_Base::handlerTimeout()
}
#endif
U_INTERNAL_DUMP("U_ClientImage_idle(this) = %d %B", U_ClientImage_idle(this), U_ClientImage_idle(this))
U_INTERNAL_DUMP("U_ClientImage_is_idle(this) = %b", U_ClientImage_is_idle(this))
if (U_ClientImage_idle(this) != U_YES) // U_YES = 0x0001
if (U_ClientImage_is_idle(this))
{
// NB: maybe we have some more data to read...
@ -966,9 +964,9 @@ void UClientImage_Base::manageReadBufferResize(uint32_t n)
}
#ifndef U_HTTP2_DISABLE
U_INTERNAL_DUMP("U_ClientImage_http = %C U_http_version = %C", U_ClientImage_http(UServer_Base::pClientImage), U_http_version)
U_INTERNAL_DUMP("U_ClientImage_is_http2 = %b U_http_version = %C", U_ClientImage_is_http2(UServer_Base::pClientImage), U_http_version)
if (U_ClientImage_http(UServer_Base::pClientImage) != '2')
if (U_ClientImage_is_http2(UServer_Base::pClientImage) == false)
#endif
{
if (U_http_method_type)
@ -1077,8 +1075,6 @@ void UClientImage_Base::prepareForRead()
return;
}
# endif
// resetRequestFromUServer();
}
else
{
@ -1091,8 +1087,6 @@ void UClientImage_Base::prepareForRead()
U_INTERNAL_ASSERT_EQUALS(UServer_Base::pClientImage, this)
UEventFd::fd = socket->iSockDesc;
// setRequestFromUServer();
}
#ifdef U_EVASIVE_SUPPORT
@ -1217,6 +1211,15 @@ bool UClientImage_Base::genericRead()
U_RETURN(true);
}
int UClientImage_Base::handlerRequest()
{
U_TRACE(0, "UClientImage_Base::handlerRequest()")
wbuffer->size_adjust_constant(0U);
U_RETURN(U_PLUGIN_HANDLER_PROCESSED);
}
int UClientImage_Base::handlerRead() // Connection-wide hooks
{
U_TRACE_NO_PARAM(0, "UClientImage_Base::handlerRead()")
@ -1355,9 +1358,9 @@ data_missing:
resetBuffer();
#ifndef U_WEBSOCKET_PARALLELIZATION
U_INTERNAL_DUMP("U_ClientImage_http = %C U_http_version = %C", U_ClientImage_http(this), U_http_version)
U_INTERNAL_DUMP("U_ClientImage_is_wsk = %b U_http_version = %C", U_ClientImage_is_wsk(this), U_http_version)
if (U_ClientImage_http(this) == '0')
if (U_ClientImage_is_wsk(this))
{
if (UWebSocket::handleDataFraming(rbuffer, socket) == U_WS_STATUS_CODE_OK)
{
@ -2009,8 +2012,8 @@ void UClientImage_Base::prepareForSendfile()
if (U_ClientImage_close)
{
U_ClientImage_close = false;
U_ClientImage_pclose(this) = U_YES;
flag.c[0] |= 0x20;
U_ClientImage_close = false;
}
if (U_ClientImage_pipeline) resetPipeline();
@ -2090,9 +2093,9 @@ write:
count = 0;
sfd = -1;
if ((U_ClientImage_pclose(this) & U_CLOSE) != 0) UFile::close(sfd);
if (U_ClientImage_is_close(this)) UFile::close(sfd);
if ((U_ClientImage_pclose(this) & U_YES) != 0) U_RETURN(U_NOTIFIER_DELETE);
if (U_ClientImage_is_delete(this)) U_RETURN(U_NOTIFIER_DELETE);
U_RETURN(U_NOTIFIER_OK);
}
@ -2128,38 +2131,22 @@ wait: socket->setBlocking();
}
end:
U_SRV_LOG("sendfile failed - sock_fd: %d sfd: %d count: %I U_ClientImage_pclose(this): %d %B", socket->iSockDesc, sfd, count, U_ClientImage_pclose(this), U_ClientImage_pclose(this));
U_SRV_LOG("sendfile failed - sock_fd: %d sfd: %d count: %I U_ClientImage_is_close(this): %b", socket->iSockDesc, sfd, count, U_ClientImage_is_close(this));
if (U_ClientImage_parallelization != U_PARALLELIZATION_CHILD)
{
if ((U_ClientImage_pclose(this) & U_CLOSE) != 0) UFile::close(sfd);
if (U_ClientImage_is_close(this)) UFile::close(sfd);
offset =
count = 0;
sfd = -1;
U_ClientImage_pclose(this) = 0;
flag.c[0] = 0;
}
U_RETURN(U_NOTIFIER_DELETE);
}
#ifdef USE_LIBURING
bool UClientImage_Base::handlerAccept(int newfd)
{
U_TRACE(0, "UClientImage_Base::handlerAccept(%d)", fd)
U_RETURN(true);
}
bool UClientImage_Base::handlerRequest(const UString& req, UString& response)
{
U_TRACE(0, "UClientImage_Base::handlerRequest(%V,%p)", req.rep, &response)
U_RETURN(true);
}
#endif
// DEBUG
#if defined(U_STDCPP_ENABLE) && defined(DEBUG)

File diff suppressed because it is too large Load Diff

View File

@ -99,30 +99,9 @@ void UEventFd::operator()(int _fd, short event)
int UNotifier::epollfd;
struct epoll_event* UNotifier::events;
struct epoll_event* UNotifier::pevents;
# ifdef U_EPOLLET_POSTPONE_STRATEGY
# ifdef U_EPOLLET_POSTPONE_STRATEGY
bool UNotifier::bepollet;
# endif
# ifdef HAVE_EPOLL_CTL_BATCH
int UNotifier::ctl_cmd_cnt;
struct epoll_ctl_cmd UNotifier::ctl_cmd[U_EPOLL_CTL_CMD_SIZE];
void UNotifier::batch(UEventFd* item)
{
U_TRACE(0, "UNotifier::batch(%p)", item)
U_INTERNAL_ASSERT_POINTER(item)
U_INTERNAL_DUMP("item->fd = %d item->op_mask = %B num_connection = %d", item->fd, item->op_mask, num_connection)
U_INTERNAL_ASSERT_EQUALS(ctl_cmd[ctl_cmd_cnt].op, EPOLL_CTL_ADD)
U_INTERNAL_ASSERT_EQUALS(ctl_cmd[ctl_cmd_cnt].events, EPOLLIN | EPOLLRDHUP | EPOLLET)
ctl_cmd[ctl_cmd_cnt].fd = item->fd;
ctl_cmd[ctl_cmd_cnt].data = item;
if (++ctl_cmd_cnt >= U_EPOLL_CTL_CMD_SIZE) insertBatch();
}
# endif
# elif defined(HAVE_KQUEUE)
int UNotifier::kq;
int UNotifier::nkqevents;
@ -299,20 +278,12 @@ next:
{
createMapFd();
#ifdef HAVE_EPOLL_WAIT
# ifdef HAVE_EPOLL_WAIT
U_INTERNAL_ASSERT_EQUALS(events, U_NULLPTR)
events =
pevents = (struct epoll_event*) UMemoryPool::cmalloc(max_connection+1, sizeof(struct epoll_event), true);
# ifdef HAVE_EPOLL_CTL_BATCH
for (int i = 0; i < U_EPOLL_CTL_CMD_SIZE; ++i)
{
ctl_cmd[i].op = EPOLL_CTL_ADD;
ctl_cmd[i].events = EPOLLIN | EPOLLRDHUP | EPOLLET;
}
# endif
#endif
}
}
@ -374,9 +345,9 @@ void UNotifier::suspend(UEventFd* item)
#endif
}
int UNotifier::waitForEvent(int fd_max, fd_set* read_set, fd_set* write_set, UEventTime* ptimeout)
int UNotifier::waitForEvent4(int fd_max, fd_set* read_set, fd_set* write_set, UEventTime* ptimeout)
{
U_TRACE(1, "UNotifier::waitForEvent(%d,%p,%p,%p)", fd_max, read_set, write_set, ptimeout)
U_TRACE(1, "UNotifier::waitForEvent4(%d,%p,%p,%p)", fd_max, read_set, write_set, ptimeout)
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD)
@ -413,9 +384,9 @@ int UNotifier::waitForEvent(int fd_max, fd_set* read_set, fd_set* write_set, UEv
U_RETURN(result);
}
void UNotifier::waitForEvent(UEventTime* ptimeout)
void UNotifier::waitForEvent1(UEventTime* ptimeout)
{
U_TRACE(0, "UNotifier::waitForEvent(%p)", ptimeout)
U_TRACE(0, "UNotifier::waitForEvent1(%p)", ptimeout)
#if !defined(HAVE_EPOLL_WAIT) && !defined(HAVE_KQUEUE)
fd_set read_set, write_set;
@ -425,7 +396,7 @@ loop:
if (fd_read_cnt) read_set = fd_set_read;
if (fd_write_cnt) write_set = fd_set_write;
nfd_ready = waitForEvent(fd_set_max,
nfd_ready = waitForEvent4(fd_set_max,
(fd_read_cnt ? &read_set
: 0),
(fd_write_cnt ? &write_set
@ -674,9 +645,9 @@ loop2: if (pevents->events)
}
}
void UNotifier::waitForEvent()
void UNotifier::waitForEvent(vPFpv waitForEventFunc)
{
U_TRACE_NO_PARAM(0, "UNotifier::waitForEvent()")
U_TRACE(0, "UNotifier::waitForEvent(%p)", waitForEventFunc)
#ifdef DEBUG
++nwatches;
@ -689,7 +660,7 @@ loop:
last_event = u_now->tv_sec;
waitForEvent(ptimeout = UTimer::getTimeout());
waitForEventFunc(ptimeout = UTimer::getTimeout());
if (nfd_ready == 0 &&
ptimeout != U_NULLPTR)
@ -1356,7 +1327,7 @@ int UNotifier::waitForRead(int fd, int timeoutMS)
FD_ZERO(&fdmask);
FD_SET(fd, &fdmask);
int ret = waitForEvent(fd + 1, &fdmask, 0, ptime);
int ret = waitForEvent4(fd + 1, &fdmask, 0, ptime);
#endif
U_RETURN(ret);
@ -1481,7 +1452,7 @@ int UNotifier::waitForWrite(int fd, int timeoutMS)
FD_ZERO(&fdmask);
FD_SET(fd, &fdmask);
int ret = waitForEvent(fd + 1, 0, &fdmask, ptime);
int ret = waitForEvent4(fd + 1, 0, &fdmask, ptime);
#endif
U_RETURN(ret);

View File

@ -16,7 +16,7 @@
#include <ulib/utility/escape.h>
#include <ulib/internal/chttp.h>
vpFpcu UString::printValueToBuffer;
vPFpcu UString::printValueToBuffer;
UString* UString::string_null = ULib::uustringnull.p2;
UString* UString::string_u_buffer = ULib::uustringubuffer.p2;
UStringRep* UStringRep::string_rep_null = ULib::uustringrepnull.p2;

View File

@ -3231,7 +3231,7 @@ bool UHTTP2::initRequest()
{
if (pConnection->state == CONN_STATE_OPEN)
{
U_INTERNAL_ASSERT_EQUALS(U_ClientImage_http(UServer_Base::pClientImage), '2')
U_INTERNAL_ASSERT(U_ClientImage_is_http2(UServer_Base::pClientImage))
do {
U_INTERNAL_DUMP("pStreamEnd->id = %u pStreamEnd->state = %u", pStreamEnd->id, pStreamEnd->state)
@ -3263,7 +3263,7 @@ void UHTTP2::handlerRequest()
{
U_TRACE_NO_PARAM(0, "UHTTP2::handlerRequest()")
U_INTERNAL_DUMP("U_ClientImage_http(%p) = %C U_http_version = %C", UServer_Base::pClientImage, U_ClientImage_http(UServer_Base::pClientImage), U_http_version)
U_INTERNAL_DUMP("U_ClientImage_is_http2 = %b U_http_version = %C", U_ClientImage_is_http2(UServer_Base::pClientImage), U_http_version)
U_INTERNAL_ASSERT_EQUALS(U_http_version, '2')
@ -3277,7 +3277,7 @@ void UHTTP2::handlerRequest()
if ((bsetting_ack =
bsetting_send = initRequest()) == false)
{
U_ClientImage_http(UServer_Base::pClientImage) = '2';
UServer_Base::pClientImage_Base->flag.c[0] |= 0x02;
U_INTERNAL_DUMP("U_http2_settings_len = %u", U_http2_settings_len)

View File

@ -196,9 +196,7 @@ bool UHTTP3::handlerRead()
while (true)
{
peer_addr_len = sizeof(peer_addr);
(void) U_SYSCALL(memset, "%p,%d,%u", &peer_addr, 0, U_SIZE_SOCKADDR);
USocket::resetPeerAddr();
iBytesRead = U_SYSCALL(recvfrom, "%d,%p,%u,%u,%p,%p", fd, data, 65535, 0, (struct sockaddr*)&peer_addr, &peer_addr_len);

View File

@ -393,8 +393,8 @@ void UInterrupt::getSignalInfo(int signo, siginfo_t* info)
# else
CYAN, errlist[index], info->si_code, errlist[index+1], YELLOW,
# endif
CYAN, (double)vsz / (1024.0 * 1024.0), YELLOW,
CYAN, (double)rss / (1024.0 * 1024.0), YELLOW);
CYAN, (double)rss / (1024.0 * 1024.0), YELLOW,
CYAN, (double)vsz / (1024.0 * 1024.0), YELLOW);
}
# endif
}

View File

@ -3881,9 +3881,9 @@ int UHTTP::handlerREAD()
#endif
#ifndef U_HTTP2_DISABLE
U_INTERNAL_DUMP("U_ClientImage_http = %C", U_ClientImage_http(UServer_Base::pClientImage))
U_INTERNAL_DUMP("U_ClientImage_is_http2 = %b", U_ClientImage_is_http2(UServer_Base::pClientImage))
if (U_ClientImage_http(UServer_Base::pClientImage) == '2')
if (U_ClientImage_is_http2(UServer_Base::pClientImage))
{
U_http_version = '2';
@ -4908,7 +4908,7 @@ from_cache:
if (UServer_Base::startParallelization() == false) UWebSocket::handlerRequest(); // child
# else
U_ClientImage_http(UServer_Base::pClientImage) = '0';
UClientImage_Base::flag.c[0] |= 0x01;
U_ClientImage_parallelization = U_PARALLELIZATION_PARENT;
@ -10774,7 +10774,7 @@ U_NO_EXPORT bool UHTTP::manageSendfile(const char* ptr, uint32_t len)
if (file_data->fd != UServer_Base::pClientImage->sfd) file->close();
else
{
U_ClientImage_pclose(UServer_Base::pClientImage) = U_CLOSE;
UServer_Base::pClientImage->flag.c[0] |= 0x10;
}
}

View File

@ -1 +1 @@
0892
08EA

View File

@ -6,13 +6,6 @@
start_msg tsa_https
#UTRACE="0 5M -1"
#UTRACE_SIGNAL="0 5M -1"
#UOBJDUMP="0 1M 100"
#USIMERR="error.sim"
#VALGRIND=valgrind
export UTRACE UTRACE_SIGNAL UOBJDUMP USIMERR VALGRIND
DOC_ROOT=TSA
rm -rf $DOC_ROOT/*log \
@ -20,6 +13,16 @@ rm -rf $DOC_ROOT/*log \
trace.*userver_*.[0-9]* object.*userver_*.[0-9]* stack.*userver_*.[0-9]* mempool.*userver_*.[0-9]* \
$DOC_ROOT/trace.*userver_*.[0-9]* $DOC_ROOT/object.*userver_*.[0-9]* $DOC_ROOT/stack.*userver_*.[0-9]* $DOC_ROOT/mempool.*userver_*.[0-9]*
#UTRACE="0 5M 0"
#UTRACE_SIGNAL="0 5M -1"
UTRACE_FOLDER=/tmp
MIMALLOC_VERBOSE=1
MIMALLOC_SHOW_ERRORS=1
#UOBJDUMP="0 1M 100"
#USIMERR="error.sim"
#VALGRIND=valgrind
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL UMEMUSAGE UTRACE_FOLDER TMPDIR MIMALLOC_VERBOSE MIMALLOC_SHOW_ERRORS
# usage: openssl s_client args
# ----------------------------------------------------------------
# -host host - use -connect instead

View File

@ -7,21 +7,50 @@
start_msg ioring
rm -rf err/ioring.err \
trace.*ioring*.[0-9]* object.*ioring*.[0-9]* stack.*ioring*.[0-9]*
trace.*ioring*.[0-9]* object.*ioring*.[0-9]* stack.*ioring*.[0-9]* mempool.*ioring*.[0-9]* \
/tmp/trace.*ioring*.[0-9]* /tmp/object.*ioring*.[0-9]* /tmp/stack.*ioring*.[0-9]* /tmp/mempool.*ioring*.[0-9]*
UTRACE="0 50M 0"
#UTRACE_SIGNAL="0 10M 0"
UTRACE_FOLDER=/tmp
MIMALLOC_VERBOSE=1
MIMALLOC_SHOW_ERRORS=1
#UOBJDUMP="0 100k 10"
#USIMERR="error.sim"
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL UMEMUSAGE UTRACE_FOLDER TMPDIR MIMALLOC_VERBOSE MIMALLOC_SHOW_ERRORS
prepare_usp
check_for_netcat
cat <<EOF >../examples/inp/webserver.cfg
userver {
PORT 8080
RUN_AS_USER nobody
#MIN_SIZE_FOR_SENDFILE 1k
#REQ_TIMEOUT 5
DOS_WHITE_LIST 127.0.0.1,10.30.0.0/16
LOG_FILE /tmp/ioring.log
LOG_FILE_SZ 1M
LOG_MSG_SIZE -1
DOCUMENT_ROOT .
PLUGIN "echo http"
PLUGIN_DIR ../../src/ulib/net/server/plugin/.libs
ORM_DRIVER_DIR ../../src/ulib/orm/driver/.libs
PREFORK_CHILD 0
#CRASH_COUNT 1
#CRASH_EMAIL_NOTIFY mail.unirel.com:stefano.casazza@unirel.com
}
http {
CACHE_FILE_MASK _off_
#REQUEST_READ_TIMEOUT 30
APACHE_LIKE_LOG /var/log/httpd/access_log
}
EOF
#VALGRIND=valgrind # --gen-suppressions=all
#STRACE=$TRUSS
start_prg_background ioring ../../src/ulib/net/server/plugin/.libs '"echo http"' # '"soap http"'
start_prg_background ioring ../examples/inp/webserver.cfg
wait_server_ready localhost 8080

View File

@ -9,10 +9,18 @@ rm -rf /tmp/ssl_session.txt
start_msg ssl_server
start_msg ssl_client
#UTRACE="0 5M 0"
rm -rf err/ssl*.err \
trace.*ssl*.[0-9]* object.*ssl*.[0-9]* stack.*ssl*.[0-9]* mempool.*ssl*.[0-9]* \
/tmp/trace.*ssl*.[0-9]* /tmp/object.*ssl*.[0-9]* /tmp/stack.*ssl*.[0-9]* /tmp/mempool.*ssl*.[0-9]*
#UTRACE="0 50M 0"
#UTRACE_SIGNAL="0 10M 0"
UTRACE_FOLDER=/tmp
MIMALLOC_VERBOSE=1
MIMALLOC_SHOW_ERRORS=1
#UOBJDUMP="0 100k 10"
#USIMERR="error.sim"
export UTRACE UOBJDUMP USIMERR
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL UMEMUSAGE UTRACE_FOLDER TMPDIR MIMALLOC_VERBOSE MIMALLOC_SHOW_ERRORS
#----------------------------------------------------------------------------------------------------------------------
# use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options are 'ored' with SSL_VERIFY_PEER if they are desired

View File

@ -13,10 +13,14 @@ U_EXPORT main(int argc, char* argv[])
U_TRACE(5,"main(%d)",argc)
UServer_Base::brng = true;
UFileConfig fcg;
UServerExample server(U_NULLPTR);
UServer_Base::brng = true;
fcg.UFile::setPath(UString(argv[1]));
UServerExample server(&fcg);
/*
UString plugin_dir(argv[1]), plugin_list(argv[2]);
if (argv[3])
@ -35,6 +39,7 @@ U_EXPORT main(int argc, char* argv[])
server.loadPlugins(plugin_dir, plugin_list);
server.port = 8080;
*/
server.run();
}

View File

@ -431,7 +431,7 @@ int U_EXPORT main(int argc, char* argv[])
(void) U_SYSCALL(write, "%d,%p,%u", fd_output, U_CONSTANT_TO_PARAM("hello, world"));
UNotifier::waitForEvent(&timeout);
UNotifier::waitForEvent1(&timeout);
(void) UNotifier::waitForRead(fds[0], 500);
U_NEW_WITHOUT_CHECK_MEMORY(MyAlarm1, a, MyAlarm1(1L, 0L));