mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
sync+fix
This commit is contained in:
parent
4c48d701e9
commit
224f4cc5b4
|
@ -39,9 +39,11 @@ class U_EXPORT ULog : public UFile {
|
|||
public:
|
||||
|
||||
typedef struct log_date {
|
||||
char date1[17+1]; // 18/06/12 18:45:56
|
||||
char date2[26+1]; // 04/Jun/2012:18:18:37 +0200
|
||||
char date3[6+29+2+12+2+19+1]; // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\nConnection: close\r\n
|
||||
char date1[17+1]; // 18/06/12 18:45:56
|
||||
char date2[26+1]; // 04/Jun/2012:18:18:37 +0200
|
||||
char header1[17]; // HTTP/1.1 200 OK\r\n
|
||||
char date3[6+29]; // Date: Wed, 20 Jun 2012 11:43:17 GMT
|
||||
char header2[2+12+2+19+1]; // \r\nServer: ULib\r\nConnection: close\r\n
|
||||
} log_date;
|
||||
|
||||
typedef struct log_data {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define ULIB_REDIS_H 1
|
||||
|
||||
#include <ulib/notifier.h>
|
||||
#include <ulib/net/unixsocket.h>
|
||||
#include <ulib/net/client/client.h>
|
||||
|
||||
/**
|
||||
|
@ -356,7 +357,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::geoadd(%.*S,%u)", len, param, len)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("GEOADD"), param, len)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("GEOADD"), param, len)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -377,7 +378,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::sadd(%.*S,%u,%.*S,%u)", keylen, key, keylen, len, param, len)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("SADD"), key, keylen, param, len)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("SADD"), key, keylen, param, len)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -446,7 +447,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::srem(%.*S,%u,%.*S,%u)", keylen, key, keylen, len, param, len)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("SREM"), key, keylen, param, len)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("SREM"), key, keylen, param, len)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -516,11 +517,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::exists(%.*S,%u)", keylen, key, keylen)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXISTS"), key, keylen) &&
|
||||
getUInt8())
|
||||
{
|
||||
U_RETURN(true);
|
||||
}
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXISTS"), key, keylen)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -529,11 +526,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::hexists(%.*S,%u,%.*S,%u)", keylen, key, keylen, fieldlen, field, fieldlen)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("HEXISTS"), key, keylen, field, fieldlen) &&
|
||||
getUInt8())
|
||||
{
|
||||
U_RETURN(true);
|
||||
}
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("HEXISTS"), key, keylen, field, fieldlen)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -594,7 +587,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::persist(%.*S,%u)", keylen, key, keylen)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PERSIST"), key, keylen)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PERSIST"), key, keylen)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -605,7 +598,7 @@ public:
|
|||
|
||||
U_INTERNAL_ASSERT_EQUALS(u_buffer_len, 0)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("MOVE"), key, keylen, u_buffer, u_num2str32(destination_db, u_buffer) - u_buffer)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("MOVE"), key, keylen, u_buffer, u_num2str32(destination_db, u_buffer) - u_buffer)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -616,7 +609,7 @@ public:
|
|||
|
||||
U_INTERNAL_ASSERT_EQUALS(u_buffer_len, 0)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXPIRE"), key, keylen, u_buffer, u_num2str32(sec, u_buffer) - u_buffer)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXPIRE"), key, keylen, u_buffer, u_num2str32(sec, u_buffer) - u_buffer)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -627,7 +620,7 @@ public:
|
|||
|
||||
U_INTERNAL_ASSERT_EQUALS(u_buffer_len, 0)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PEXPIRE"), key, keylen, u_buffer, u_num2str32(millisec, u_buffer) - u_buffer)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PEXPIRE"), key, keylen, u_buffer, u_num2str32(millisec, u_buffer) - u_buffer)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -639,9 +632,9 @@ public:
|
|||
U_INTERNAL_ASSERT_EQUALS(u_buffer_len, 0)
|
||||
|
||||
# if SIZEOF_TIME_T == 8
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXPIREAT"), key, keylen, u_buffer, u_num2str64(timestamp, u_buffer) - u_buffer)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXPIREAT"), key, keylen, u_buffer, u_num2str64(timestamp, u_buffer) - u_buffer)) return getUInt8();
|
||||
# else
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXPIREAT"), key, keylen, u_buffer, u_num2str32(timestamp, u_buffer) - u_buffer)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXPIREAT"), key, keylen, u_buffer, u_num2str32(timestamp, u_buffer) - u_buffer)) return getUInt8();
|
||||
# endif
|
||||
|
||||
U_RETURN(false);
|
||||
|
@ -653,7 +646,7 @@ public:
|
|||
|
||||
U_INTERNAL_ASSERT_EQUALS(u_buffer_len, 0)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PEXPIREAT"), key, keylen, u_buffer, u_num2str64(timestamp, u_buffer) - u_buffer)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PEXPIREAT"), key, keylen, u_buffer, u_num2str64(timestamp, u_buffer) - u_buffer)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -705,7 +698,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::publish(%.*S,%u,%.*S,%u)", channel_len, channel, channel_len, msg_len, msg, msg_len)
|
||||
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PUBLISH"), channel, channel_len, msg, msg_len)) return getBool();
|
||||
if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("PUBLISH"), channel, channel_len, msg, msg_len)) return getUInt8();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -771,6 +764,7 @@ protected:
|
|||
err = 0;
|
||||
}
|
||||
|
||||
void init();
|
||||
void processResponse();
|
||||
bool processRequest(char recvtype);
|
||||
|
||||
|
@ -862,4 +856,51 @@ private:
|
|||
U_DISALLOW_COPY_AND_ASSIGN(UREDISClient)
|
||||
};
|
||||
|
||||
template <> class U_EXPORT UREDISClient<UUnixSocket> : public UREDISClient_Base {
|
||||
public:
|
||||
|
||||
UREDISClient() : UREDISClient_Base()
|
||||
{
|
||||
U_TRACE_CTOR(0, UREDISClient<UUnixSocket>, "")
|
||||
|
||||
U_NEW(UUnixSocket, UClient_Base::socket, UUnixSocket(false));
|
||||
}
|
||||
|
||||
~UREDISClient()
|
||||
{
|
||||
U_TRACE_DTOR(0, UREDISClient<UUnixSocket>)
|
||||
}
|
||||
|
||||
// Connect to REDIS server via pathname (unix socket)
|
||||
|
||||
bool connect(const char* pathname = "/tmp/redis.sock", unsigned int _port = 6379)
|
||||
{
|
||||
U_TRACE(0, "UREDISClient<UUnixSocket>::connect(%S,%u)", pathname, _port)
|
||||
|
||||
UString path(pathname);
|
||||
|
||||
if (UClient_Base::socket->connectServer(path, port))
|
||||
{
|
||||
UREDISClient_Base::init();
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
||||
UClient_Base::response.snprintf(U_CONSTANT_TO_PARAM("Sorry, couldn't connect to unix socket %v%R"), path.rep, 0); // NB: the last argument (0) is necessary...
|
||||
|
||||
U_CLIENT_LOG("%v", UClient_Base::response.rep)
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
|
||||
#if defined(U_STDCPP_ENABLE) && defined(DEBUG)
|
||||
const char* dump(bool _reset) const { return UREDISClient_Base::dump(_reset); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
U_DISALLOW_COPY_AND_ASSIGN(UREDISClient<UUnixSocket>)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -100,22 +100,8 @@ public:
|
|||
U_TRACE(0, "UClientImage_Base::setHeaderForResponse(%u)", len)
|
||||
|
||||
iov_vec[1].iov_len = len;
|
||||
}
|
||||
|
||||
static void setNoHeaderForResponse()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UClientImage_Base::setNoHeaderForResponse()")
|
||||
|
||||
iov_vec[0].iov_len = 0;
|
||||
}
|
||||
|
||||
static bool isNoHeaderForResponse()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UClientImage_Base::isNoHeaderForResponse()")
|
||||
|
||||
if (UNLIKELY(iov_vec[0].iov_len == 0)) U_RETURN(true);
|
||||
|
||||
U_RETURN(false);
|
||||
U_INTERNAL_DUMP("UClientImage_Base::iov_vec[1] = %.*S", UClientImage_Base::iov_vec[1].iov_len, UClientImage_Base::iov_vec[1].iov_base)
|
||||
}
|
||||
|
||||
// manage if other data already available... (pipelining)
|
||||
|
@ -327,7 +313,7 @@ public:
|
|||
static UString* rbuffer;
|
||||
static UString* wbuffer;
|
||||
static UString* request;
|
||||
static bool bIPv6, bsendGzipBomb;
|
||||
static bool bIPv6, bsendGzipBomb, bnoheader;
|
||||
|
||||
static char cbuffer[128];
|
||||
static UString* request_uri;
|
||||
|
@ -365,40 +351,20 @@ public:
|
|||
|
||||
U_ASSERT(body->empty())
|
||||
U_INTERNAL_ASSERT_MAJOR(sz, 0)
|
||||
U_INTERNAL_ASSERT_EQUALS(U_http_info.nResponseCode, 200)
|
||||
|
||||
iov_vec[2].iov_len = sz;
|
||||
iov_vec[2].iov_base = (caddr_t)wbuffer->data();
|
||||
|
||||
U_INTERNAL_DUMP("iov_vec[0].iov_len = %u iov_vec[1].iov_len = %u", iov_vec[0].iov_len, iov_vec[1].iov_len)
|
||||
U_INTERNAL_DUMP("iov_vec[1].iov_len = %u", iov_vec[1].iov_len)
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(iov_vec[0].iov_len, 17)
|
||||
U_INTERNAL_ASSERT_EQUALS(iov_vec[1].iov_len, 51)
|
||||
U_INTERNAL_ASSERT_EQUALS(iov_vec[1].iov_len, 17+51) // HTTP/1.1 200 OK\r\nDate: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
# ifndef U_PIPELINE_HOMOGENEOUS_DISABLE
|
||||
if (nrequest)
|
||||
{
|
||||
struct iovec iov[256];
|
||||
|
||||
U_INTERNAL_ASSERT_MAJOR(nrequest, 1)
|
||||
|
||||
char* ptr = (char*)iov;
|
||||
|
||||
U_MEMCPY(ptr, iov_vec, sizeof(struct iovec) * 3);
|
||||
|
||||
for (uint32_t i = 1; i < nrequest; ++i)
|
||||
{
|
||||
ptr += sizeof(struct iovec) * 3;
|
||||
U_MEMCPY(ptr, iov_vec, sizeof(struct iovec) * 3);
|
||||
}
|
||||
|
||||
(void) USocketExt::writev(socket, iov, 3*nrequest, (17+51+sz)*nrequest, 0);
|
||||
}
|
||||
else
|
||||
if (nrequest <= 1)
|
||||
# endif
|
||||
{
|
||||
U_INTERNAL_ASSERT_EQUALS(nrequest, 0)
|
||||
|
||||
(void) USocketExt::writev(socket, iov_vec, 3, 17+51+sz, 0);
|
||||
(void) USocketExt::writev(socket, iov_vec+1, 2, 17+51+sz, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,6 +429,8 @@ protected:
|
|||
{
|
||||
U_TRACE_NO_PARAM(0, "UClientImage::handlerResponse()")
|
||||
|
||||
bnoheader = true;
|
||||
|
||||
if (writeResponse()) U_RETURN(U_NOTIFIER_OK);
|
||||
|
||||
U_RETURN(U_NOTIFIER_DELETE);
|
||||
|
|
|
@ -937,8 +937,9 @@ protected:
|
|||
*UClientImage_Base::wbuffer = *UClientImage_Base::rbuffer; // echo server
|
||||
}
|
||||
|
||||
UClientImage_Base::bnoheader = true;
|
||||
|
||||
UClientImage_Base::setRequestProcessed();
|
||||
UClientImage_Base::setNoHeaderForResponse();
|
||||
|
||||
U_RETURN(U_PLUGIN_HANDLER_FINISHED);
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ private:
|
|||
|
||||
// write data from multiple buffers
|
||||
|
||||
static uint32_t iov_resize(struct iovec* liov, struct iovec* iov, int iovcnt, uint32_t byte_written);
|
||||
static uint32_t iov_resize(struct iovec* liov, const struct iovec* iov, int iovcnt, uint32_t byte_written);
|
||||
|
||||
static uint32_t writev(USocket* sk, struct iovec* iov, int iovcnt, uint32_t count, int timeoutMS);
|
||||
|
||||
|
|
|
@ -1375,7 +1375,7 @@ private:
|
|||
#endif
|
||||
|
||||
private:
|
||||
static uint32_t old_response_code, is_response_compressed;
|
||||
static uint32_t is_response_compressed;
|
||||
|
||||
static void setMimeIndex()
|
||||
{
|
||||
|
|
|
@ -222,13 +222,11 @@ int UEventDB::handlerRead()
|
|||
U_INTERNAL_ASSERT(num_handler <= U_QUERY_INFO_SZ)
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
# ifdef DEBUG
|
||||
U_INTERNAL_DUMP("bsend = %b bnotifier = %b busy = %b", bsend, bnotifier, *pbusy)
|
||||
|
||||
U_INTERNAL_ASSERT(bnotifier)
|
||||
|
||||
#ifdef DEBUG
|
||||
if (max_num_handler < num_handler) max_num_handler = num_handler;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
pid_t pid = (num_handler <= 1 || *pbusy ? 1 : (*pbusy = true, UServer_Base::startNewChild()));
|
||||
|
||||
|
|
|
@ -159,9 +159,9 @@ void ULog::initDate()
|
|||
tv_sec_old_2 =
|
||||
tv_sec_old_3 = u_now->tv_sec;
|
||||
|
||||
(void) u_strftime2(date.date1, 17, U_CONSTANT_TO_PARAM("%d/%m/%y %T"), u_get_localtime(tv_sec_old_1));
|
||||
(void) u_strftime2(date.date2, 26, U_CONSTANT_TO_PARAM("%d/%b/%Y:%T %z"), u_get_localtime(tv_sec_old_2));
|
||||
(void) u_strftime2(date.date3, 6+29+2+12+2+17+2, U_CONSTANT_TO_PARAM("Date: %a, %d %b %Y %T GMT\r\nServer: ULib\r\nConnection: close\r\n"), tv_sec_old_3);
|
||||
(void) u_strftime2(date.date1, 17, U_CONSTANT_TO_PARAM("%d/%m/%y %T"), u_get_localtime(tv_sec_old_1));
|
||||
(void) u_strftime2(date.date2, 26, U_CONSTANT_TO_PARAM("%d/%b/%Y:%T %z"), u_get_localtime(tv_sec_old_2));
|
||||
(void) u_strftime2(date.date3, 6+29, U_CONSTANT_TO_PARAM("Date: %a, %d %b %Y %T GMT"), tv_sec_old_3);
|
||||
}
|
||||
|
||||
void ULog::startup()
|
||||
|
|
|
@ -21,6 +21,23 @@ UREDISClient_Base* UREDISClient_Base::pthis;
|
|||
|
||||
// Connect to REDIS server
|
||||
|
||||
void UREDISClient_Base::init()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UREDISClient_Base::init()")
|
||||
|
||||
U_DUMP("getRedisVersion() = %V", getRedisVersion().rep)
|
||||
|
||||
clear();
|
||||
|
||||
pthis = this;
|
||||
|
||||
UClient_Base::response.clear();
|
||||
|
||||
UClient_Base::reserve(UString::_getReserveNeed());
|
||||
|
||||
UClient_Base::setForResizeResponseBuffer(manageResponseBufferResize);
|
||||
}
|
||||
|
||||
bool UREDISClient_Base::connect(const char* phost, unsigned int _port)
|
||||
{
|
||||
U_TRACE(0, "UREDISClient_Base::connect(%S,%u)", phost, _port)
|
||||
|
@ -49,17 +66,7 @@ bool UREDISClient_Base::connect(const char* phost, unsigned int _port)
|
|||
if (UClient_Base::setHostPort(host, _port) &&
|
||||
UClient_Base::connect())
|
||||
{
|
||||
U_DUMP("getRedisVersion() = %V", getRedisVersion().rep)
|
||||
|
||||
clear();
|
||||
|
||||
pthis = this;
|
||||
|
||||
UClient_Base::response.clear();
|
||||
|
||||
UClient_Base::reserve(UString::_getReserveNeed());
|
||||
|
||||
UClient_Base::setForResizeResponseBuffer(manageResponseBufferResize);
|
||||
init();
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
@ -503,15 +510,14 @@ bool UREDISClient_Base::deleteKeys(const char* pattern, uint32_t len) // Delete
|
|||
{
|
||||
U_TRACE(0, "UREDISClient_Base::deleteKeys(%.*S,%u)", len, pattern, len)
|
||||
|
||||
char buf[4096];
|
||||
uint32_t buf_len = u__snprintf(buf, U_CONSTANT_SIZE(buf), U_CONSTANT_TO_PARAM("MATCH %.*s COUNT 1000"), len, pattern);
|
||||
char buf[4096], ncursor[22];
|
||||
uint32_t cursor = 0, buf_len = u__snprintf(buf, U_CONSTANT_SIZE(buf), U_CONSTANT_TO_PARAM("MATCH %.*s COUNT 1000"), len, pattern);
|
||||
|
||||
if (processRequest(U_RC_MULTIBULK, U_CONSTANT_TO_PARAM("SCAN"), U_CONSTANT_TO_PARAM("0"), buf, buf_len))
|
||||
while (processRequest(U_RC_MULTIBULK, U_CONSTANT_TO_PARAM("SCAN"), ncursor, u_num2str32(cursor,ncursor)-ncursor, buf, buf_len))
|
||||
{
|
||||
char ncursor[22];
|
||||
uint32_t cursor = getULong();
|
||||
cursor = getULong();
|
||||
|
||||
loop: if (setMultiBulk())
|
||||
if (setMultiBulk())
|
||||
{
|
||||
x.unQuote();
|
||||
|
||||
|
@ -519,13 +525,6 @@ loop: if (setMultiBulk())
|
|||
}
|
||||
|
||||
if (cursor == 0) U_RETURN(true);
|
||||
|
||||
if (processRequest(U_RC_MULTIBULK, U_CONSTANT_TO_PARAM("SCAN"), ncursor, u__snprintf(ncursor, u_num2str32(cursor,ncursor)-ncursor, buf, buf_len)))
|
||||
{
|
||||
cursor = getULong();
|
||||
|
||||
goto loop;
|
||||
}
|
||||
}
|
||||
|
||||
U_RETURN(true);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
int UClientImage_Base::idx;
|
||||
int UClientImage_Base::iovcnt;
|
||||
bool UClientImage_Base::bIPv6;
|
||||
bool UClientImage_Base::bnoheader;
|
||||
bool UClientImage_Base::bsendGzipBomb;
|
||||
char UClientImage_Base::cbuffer[128];
|
||||
long UClientImage_Base::time_run;
|
||||
|
@ -1170,7 +1171,6 @@ int UClientImage_Base::handlerRead() // Connection-wide hooks
|
|||
{
|
||||
U_TRACE_NO_PARAM(0, "UClientImage_Base::handlerRead()")
|
||||
|
||||
int result;
|
||||
uint32_t sz;
|
||||
|
||||
prepareForRead();
|
||||
|
@ -1200,8 +1200,6 @@ start:
|
|||
U_ASSERT(isOpen())
|
||||
|
||||
UServer_Base::nread++;
|
||||
|
||||
U_INTERNAL_DUMP("iov_vec[0].iov_len = %u iov_vec[1].iov_len = %u", iov_vec[0].iov_len, iov_vec[1].iov_len)
|
||||
#endif
|
||||
|
||||
loop:
|
||||
|
@ -1384,9 +1382,9 @@ next2:
|
|||
resto = (sz % size_request);
|
||||
uint32_t n = (sz / size_request);
|
||||
|
||||
U_INTERNAL_DUMP("n = %u resto = %u size_request = %u", n, resto, size_request)
|
||||
U_INTERNAL_DUMP("n = %u resto = %u size_request = %u wbuffer(%u) = %V", n, resto, size_request, wbuffer->size(), wbuffer->rep)
|
||||
|
||||
if (n > 1 &&
|
||||
if (n &&
|
||||
*wbuffer &&
|
||||
callerIsValidRequest(ptr1, size_request) &&
|
||||
(resto == 0 || callerIsValidMethod(rbuffer->c_pointer(sz-resto))))
|
||||
|
@ -1398,7 +1396,9 @@ next2:
|
|||
|
||||
while (true)
|
||||
{
|
||||
# if !defined(U_SERVER_CAPTIVE_PORTAL) || !defined(ENABLE_THREAD)
|
||||
if (memcmp(ptr, ptr1, size_request) != 0) break;
|
||||
# endif
|
||||
|
||||
ptr1 += size_request;
|
||||
|
||||
|
@ -1421,7 +1421,6 @@ next2:
|
|||
check: U_INTERNAL_DUMP("nrequest = %u resto = %u", nrequest, resto)
|
||||
|
||||
U_INTERNAL_ASSERT(nrequest <= n)
|
||||
U_INTERNAL_ASSERT_DIFFERS(nrequest, 1)
|
||||
|
||||
if (resto ||
|
||||
nrequest != n)
|
||||
|
@ -1433,8 +1432,14 @@ check: U_INTERNAL_DUMP("nrequest = %u resto = %u", nrequest, resto)
|
|||
|
||||
U_INTERNAL_DUMP("rstart = %u request(%u) = %V", rstart, request->size(), request->rep)
|
||||
|
||||
goto write;
|
||||
# if defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
|
||||
goto write1;
|
||||
# else
|
||||
goto write2;
|
||||
# endif
|
||||
}
|
||||
|
||||
resto = 0;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
@ -1457,12 +1462,50 @@ check: U_INTERNAL_DUMP("nrequest = %u resto = %u", nrequest, resto)
|
|||
#if defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
|
||||
else
|
||||
{
|
||||
#ifndef U_PIPELINE_HOMOGENEOUS_DISABLE
|
||||
write1:
|
||||
#endif
|
||||
writeResponseCompact();
|
||||
|
||||
U_INTERNAL_DUMP("U_ClientImage_request_is_cached = %b", U_ClientImage_request_is_cached)
|
||||
|
||||
if (U_ClientImage_request_is_cached == false) endRequest();
|
||||
|
||||
# ifndef U_PIPELINE_HOMOGENEOUS_DISABLE
|
||||
U_INTERNAL_DUMP("nrequest = %u resto = %u U_ClientImage_pipeline = %b U_ClientImage_close = %b rstart = %u",
|
||||
nrequest, resto, U_ClientImage_pipeline, U_ClientImage_close, rstart)
|
||||
|
||||
if (nrequest > 1)
|
||||
{
|
||||
U_INTERNAL_ASSERT_RANGE(2,nrequest,64)
|
||||
|
||||
struct iovec iov[64];
|
||||
|
||||
char* ptr = (char*)iov;
|
||||
|
||||
U_MEMCPY(ptr, iov_vec+1, sizeof(struct iovec) * 2);
|
||||
|
||||
for (uint32_t i = 1; i < nrequest; ++i)
|
||||
{
|
||||
ptr += sizeof(struct iovec) * 2;
|
||||
U_MEMCPY(ptr, iov_vec+1, sizeof(struct iovec) * 2);
|
||||
}
|
||||
|
||||
(void) USocketExt::writev(socket, iov, 2*nrequest, (17+51+iov_vec[2].iov_len)*nrequest, 0);
|
||||
}
|
||||
|
||||
nrequest = 0;
|
||||
|
||||
if (resto)
|
||||
{
|
||||
resto = 0;
|
||||
|
||||
U_ASSERT_EQUALS(*request, rbuffer->substr(rstart))
|
||||
|
||||
goto data_missing;
|
||||
}
|
||||
# endif
|
||||
|
||||
U_RETURN(U_NOTIFIER_OK);
|
||||
}
|
||||
#endif
|
||||
|
@ -1482,41 +1525,44 @@ check: U_INTERNAL_DUMP("nrequest = %u resto = %u", nrequest, resto)
|
|||
|
||||
if (count == 0)
|
||||
{
|
||||
#ifndef U_PIPELINE_HOMOGENEOUS_DISABLE
|
||||
write:
|
||||
#if !defined(U_PIPELINE_HOMOGENEOUS_DISABLE) && (!defined(U_SERVER_CAPTIVE_PORTAL) || !defined(ENABLE_THREAD))
|
||||
write2:
|
||||
#endif
|
||||
U_INTERNAL_DUMP("U_ClientImage_pipeline = %b U_ClientImage_data_missing = %b", U_ClientImage_pipeline, U_ClientImage_data_missing)
|
||||
|
||||
result = (writeResponse() ? U_NOTIFIER_OK : U_NOTIFIER_DELETE);
|
||||
if (writeResponse() == false)
|
||||
{
|
||||
# ifndef U_PIPELINE_HOMOGENEOUS_DISABLE
|
||||
resto =
|
||||
nrequest = 0;
|
||||
# endif
|
||||
|
||||
goto error;
|
||||
}
|
||||
|
||||
# ifndef U_PIPELINE_HOMOGENEOUS_DISABLE
|
||||
U_INTERNAL_DUMP("nrequest = %u resto = %u U_ClientImage_pipeline = %b U_ClientImage_close = %b rstart = %u",
|
||||
nrequest, resto, U_ClientImage_pipeline, U_ClientImage_close, rstart)
|
||||
|
||||
|
||||
if (nrequest)
|
||||
{
|
||||
nrequest = 0;
|
||||
|
||||
if (resto)
|
||||
{
|
||||
resto = 0;
|
||||
U_ClientImage_pipeline = false;
|
||||
}
|
||||
|
||||
if (result == U_NOTIFIER_DELETE) goto error;
|
||||
if (resto)
|
||||
{
|
||||
resto = 0;
|
||||
|
||||
endRequest();
|
||||
endRequest();
|
||||
|
||||
goto data_missing;
|
||||
}
|
||||
U_ASSERT_EQUALS(*request, rbuffer->substr(rstart))
|
||||
|
||||
if (U_ClientImage_pipeline &&
|
||||
(rstart == 0 || resto == 0))
|
||||
{
|
||||
U_ClientImage_pipeline = false;
|
||||
}
|
||||
goto data_missing;
|
||||
}
|
||||
# endif
|
||||
|
||||
if (result == U_NOTIFIER_DELETE) goto error;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1583,8 +1629,6 @@ error:
|
|||
{
|
||||
end: if (U_ClientImage_parallelization == U_PARALLELIZATION_CHILD) goto death;
|
||||
|
||||
setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
U_RETURN(U_NOTIFIER_DELETE);
|
||||
}
|
||||
|
||||
|
@ -1628,15 +1672,16 @@ bool UClientImage_Base::writeResponse()
|
|||
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_PARENT)
|
||||
|
||||
struct iovec* iov;
|
||||
#if !defined(U_PIPELINE_HOMOGENEOUS_DISABLE) || defined(U_CLIENT_RESPONSE_PARTIAL_WRITE_SUPPORT)
|
||||
struct iovec liov[256];
|
||||
#endif
|
||||
bool bresult, bclose = false;
|
||||
uint32_t iBytesWrite,
|
||||
sz1 = wbuffer->size(),
|
||||
sz2 = (U_http_method_type == HTTP_HEAD ? 0 : body->size());
|
||||
#ifndef U_LOG_DISABLE
|
||||
uint32_t msg_len = (U_ClientImage_pipeline ? U_CONSTANT_SIZE("[pipeline] ") : 0);
|
||||
#endif
|
||||
#if !defined(U_PIPELINE_HOMOGENEOUS_DISABLE) || defined(U_CLIENT_RESPONSE_PARTIAL_WRITE_SUPPORT)
|
||||
struct iovec liov[256];
|
||||
#endif
|
||||
|
||||
iov_vec[2].iov_len = sz1;
|
||||
iov_vec[2].iov_base = (caddr_t)wbuffer->data();
|
||||
|
@ -1645,8 +1690,10 @@ bool UClientImage_Base::writeResponse()
|
|||
|
||||
ncount = sz1 + sz2;
|
||||
|
||||
if (isNoHeaderForResponse())
|
||||
if (bnoheader)
|
||||
{
|
||||
bnoheader = false;
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(nrequest, 0)
|
||||
|
||||
U_SRV_LOG_WITH_ADDR("send response (%u bytes) %.*s%#.*S to", ncount, msg_len, "[pipeline] ", iov_vec[2].iov_len, iov_vec[2].iov_base);
|
||||
|
@ -1667,8 +1714,25 @@ bool UClientImage_Base::writeResponse()
|
|||
}
|
||||
else
|
||||
{
|
||||
idx = 0;
|
||||
iovcnt = 4;
|
||||
U_INTERNAL_DUMP("iov_vec[1].iov_len = %u", iov_vec[1].iov_len)
|
||||
|
||||
if (iov_vec[1].iov_len == 17+6+29+2+12+2) // HTTP/1.1 200 OK\r\nDate: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
{
|
||||
idx = 1;
|
||||
iovcnt = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
idx = 0;
|
||||
iovcnt = 4;
|
||||
|
||||
ncount += iov_vec[0].iov_len;
|
||||
|
||||
iov_vec[1].iov_base = (char*)iov_vec[1].iov_base + 17; // HTTP/1.1 200 OK\r\n
|
||||
|
||||
U_INTERNAL_DUMP("U_http_info.nResponseCode = %u UClientImage_Base::iov_vec[0] = %.*S",
|
||||
U_http_info.nResponseCode, UClientImage_Base::iov_vec[0].iov_len, UClientImage_Base::iov_vec[0].iov_base)
|
||||
}
|
||||
|
||||
# ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE)
|
||||
U_INTERNAL_DUMP("UHTTP::sse_func = %p", UHTTP::sse_func)
|
||||
|
@ -1679,18 +1743,15 @@ bool UClientImage_Base::writeResponse()
|
|||
if (U_ClientImage_close &&
|
||||
U_ClientImage_pipeline == false)
|
||||
{
|
||||
iov_vec[1].iov_len = 6+29+2+12+2+17+2; // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\nConnection: close\r\n
|
||||
bclose = true;
|
||||
|
||||
iov_vec[1].iov_len += 17+2; // Connection: close\r\n
|
||||
}
|
||||
}
|
||||
|
||||
ncount += iov_vec[0].iov_len +
|
||||
iov_vec[1].iov_len;
|
||||
|
||||
# if defined(U_LINUX) && defined(ENABLE_THREAD) && !defined(U_SERVER_CAPTIVE_PORTAL)
|
||||
U_INTERNAL_ASSERT_EQUALS(iov_vec[1].iov_base, ULog::ptr_shared_date->date3)
|
||||
# else
|
||||
U_INTERNAL_ASSERT_EQUALS(iov_vec[1].iov_base, ULog::date.date3)
|
||||
ncount += iov_vec[1].iov_len;
|
||||
|
||||
# if !defined(U_LINUX) || !defined(ENABLE_THREAD)
|
||||
ULog::updateDate3(U_NULLPTR);
|
||||
# endif
|
||||
|
||||
|
@ -1702,9 +1763,9 @@ bool UClientImage_Base::writeResponse()
|
|||
iov = iov_vec+idx;
|
||||
|
||||
#ifndef U_PIPELINE_HOMOGENEOUS_DISABLE
|
||||
if (nrequest)
|
||||
if (nrequest > 1)
|
||||
{
|
||||
U_INTERNAL_ASSERT_MAJOR(nrequest, 1)
|
||||
U_INTERNAL_ASSERT_RANGE(2,nrequest,256)
|
||||
|
||||
char* ptr = (char*)liov;
|
||||
uint32_t sz = sizeof(struct iovec) * iovcnt;
|
||||
|
@ -1725,7 +1786,7 @@ bool UClientImage_Base::writeResponse()
|
|||
else
|
||||
#endif
|
||||
{
|
||||
U_INTERNAL_ASSERT_EQUALS(nrequest, 0)
|
||||
U_INTERNAL_ASSERT_MINOR(nrequest, 2)
|
||||
|
||||
iBytesWrite = USocketExt::writev(socket, iov, iovcnt, ncount, U_ClientImage_pipeline ? U_TIMEOUT_MS : 0);
|
||||
}
|
||||
|
@ -1737,48 +1798,60 @@ bool UClientImage_Base::writeResponse()
|
|||
if (iBytesWrite > 0) UServer_Base::stats_bytes += iBytesWrite;
|
||||
#endif
|
||||
|
||||
if (iBytesWrite == ncount) U_RETURN(true);
|
||||
|
||||
U_SRV_LOG("write failed (remain %u bytes) - sock_fd %u", ncount - iBytesWrite, socket->iSockDesc);
|
||||
|
||||
if (socket->isClosed()) U_RETURN(false);
|
||||
|
||||
#ifndef U_CLIENT_RESPONSE_PARTIAL_WRITE_SUPPORT
|
||||
resetPipelineAndSetCloseConnection();
|
||||
|
||||
U_RETURN(false);
|
||||
#else
|
||||
U_INTERNAL_ASSERT_EQUALS(UServer_Base::bssl, false)
|
||||
U_INTERNAL_ASSERT_EQUALS(UEventFd::op_mask, EPOLLIN | EPOLLRDHUP | EPOLLET)
|
||||
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) // NB: we must not have pending write...
|
||||
|
||||
sfd = UFile::mkTemp();
|
||||
|
||||
if (sfd == -1)
|
||||
if ((bresult = (iBytesWrite == ncount)) == false)
|
||||
{
|
||||
U_SRV_LOG("partial write failed: (remain %u bytes) - error on create temporary file - sock_fd %u", ncount, socket->iSockDesc);
|
||||
U_SRV_LOG("writev failed (remain %u bytes) - sock_fd %u", ncount - iBytesWrite, socket->iSockDesc);
|
||||
|
||||
U_RETURN(false);
|
||||
if (socket->isOpen())
|
||||
{
|
||||
# ifndef U_CLIENT_RESPONSE_PARTIAL_WRITE_SUPPORT
|
||||
resetPipelineAndSetCloseConnection();
|
||||
# else
|
||||
U_INTERNAL_ASSERT_EQUALS(UServer_Base::bssl, false)
|
||||
U_INTERNAL_ASSERT_EQUALS(UEventFd::op_mask, EPOLLIN | EPOLLRDHUP | EPOLLET)
|
||||
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) // NB: we must not have pending write...
|
||||
|
||||
sfd = UFile::mkTemp();
|
||||
|
||||
if ((bresult = (sfd != -1)) == false)
|
||||
{
|
||||
U_SRV_LOG("partial write failed: (remain %u bytes) - error on create temporary file - sock_fd %u", ncount - iBytesWrite, socket->iSockDesc);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncount -= iBytesWrite;
|
||||
|
||||
iBytesWrite = UFile::writev(sfd, liov, USocketExt::iov_resize(liov, iov, iovcnt, iBytesWrite));
|
||||
|
||||
if ((bresult = (iBytesWrite == ncount)))
|
||||
{
|
||||
U_SRV_LOG("partial write: (remain %u bytes) - create temporary file - sock_fd %u sfd %u", ncount, socket->iSockDesc, sfd);
|
||||
|
||||
setPendingSendfile(); // NB: now we have a pending sendfile...
|
||||
}
|
||||
else
|
||||
{
|
||||
U_SRV_LOG("partial write failed: (remain %u bytes) - error on write (%u bytes) on temporary file - sock_fd %u sfd %u", ncount, iBytesWrite, socket->iSockDesc, sfd);
|
||||
|
||||
UFile::close(sfd);
|
||||
sfd = -1;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
iBytesWrite = UFile::writev(sfd, liov, USocketExt::iov_resize(liov, iov, iovcnt, iBytesWrite));
|
||||
U_INTERNAL_DUMP("bclose = %b idx = %u bresult = %b", bclose, idx, bresult)
|
||||
|
||||
if (iBytesWrite != ncount)
|
||||
if (bclose ||
|
||||
idx == 0)
|
||||
{
|
||||
U_SRV_LOG("partial write failed: (remain %u bytes) - error on write (%u bytes) on temporary file - sock_fd %u sfd %u", ncount, iBytesWrite, socket->iSockDesc, sfd);
|
||||
if (idx == 0) iov_vec[1].iov_base = (char*)iov_vec[1].iov_base - 17; // HTTP/1.1 200 OK\r\n
|
||||
|
||||
UFile::close(sfd);
|
||||
sfd = -1;
|
||||
|
||||
U_RETURN(false);
|
||||
setHeaderForResponse(17+6+29+2+12+2); // HTTP/1.1 200 OK\r\nDate: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
}
|
||||
|
||||
U_SRV_LOG("partial write: (remain %u bytes) - create temporary file - sock_fd %u sfd %u", ncount, socket->iSockDesc, sfd);
|
||||
|
||||
setPendingSendfile(); // NB: now we have a pending sendfile...
|
||||
|
||||
U_RETURN(true);
|
||||
#endif
|
||||
U_RETURN(bresult);
|
||||
}
|
||||
|
||||
void UClientImage_Base::close()
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
//
|
||||
// ============================================================================
|
||||
|
||||
#include <ulib/utility/uhttp.h>
|
||||
#include <ulib/net/server/client_image.h>
|
||||
#include <ulib/net/server/server_plugin.h>
|
||||
#include <ulib/net/server/plugin/mod_echo.h>
|
||||
|
@ -42,8 +43,9 @@ int UEchoPlugIn::handlerRequest()
|
|||
|
||||
U_ASSERT(UClientImage_Base::body->empty())
|
||||
|
||||
UClientImage_Base::bnoheader = true;
|
||||
|
||||
UClientImage_Base::setRequestProcessed();
|
||||
UClientImage_Base::setNoHeaderForResponse();
|
||||
|
||||
#ifndef U_ECHO_RESPONSE_FOR_TEST
|
||||
UClientImage_Base::wbuffer->replace(*UClientImage_Base::request);
|
||||
|
@ -51,5 +53,7 @@ int UEchoPlugIn::handlerRequest()
|
|||
(void) UClientImage_Base::wbuffer->assign(U_CONSTANT_TO_PARAM(U_ECHO_RESPONSE_FOR_TEST));
|
||||
#endif
|
||||
|
||||
// *UClientImage_Base::body = *UHTTP::body;
|
||||
|
||||
U_RETURN(U_PLUGIN_HANDLER_PROCESSED);
|
||||
}
|
||||
|
|
|
@ -458,6 +458,15 @@ int UHttpPlugIn::handlerInit()
|
|||
{
|
||||
U_TRACE_NO_PARAM(0, "UHttpPlugIn::handlerInit()")
|
||||
|
||||
U_MEMCPY(ULog::date.header1, "HTTP/1.1 200 OK\r\n",
|
||||
U_CONSTANT_SIZE("HTTP/1.1 200 OK\r\n")); // 17
|
||||
|
||||
U_MEMCPY(ULog::date.header2, "\r\nServer: ULib\r\nConnection: close\r\n",
|
||||
U_CONSTANT_SIZE("\r\nServer: ULib\r\nConnection: close\r\n")); // 2+12+2+17+2
|
||||
|
||||
UClientImage_Base::iov_vec[1].iov_len = 17+6+29+2+12+2; //+17+2;
|
||||
UClientImage_Base::iov_vec[1].iov_base = (caddr_t)ULog::date.header1; // HTTP/1.1 200 OK\r\nDate: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\nConnection: close\r\n
|
||||
|
||||
#ifdef USE_LIBSSL
|
||||
if (UServer_Base::bssl)
|
||||
{
|
||||
|
@ -526,14 +535,11 @@ int UHttpPlugIn::handlerRun() // NB: we use this method instead of handlerInit()
|
|||
UServer_Base::update_date =
|
||||
UServer_Base::update_date3 = true;
|
||||
|
||||
UClientImage_Base::iov_vec[1].iov_len = 6+29+2+12+2; //+17+2;
|
||||
UClientImage_Base::iov_vec[1].iov_base = (caddr_t)ULog::date.date3; // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\nConnection: close\r\n
|
||||
|
||||
#if defined(U_LINUX) && defined(ENABLE_THREAD) && !defined(U_SERVER_CAPTIVE_PORTAL)
|
||||
U_INTERNAL_ASSERT_POINTER(UServer_Base::ptr_shared_data)
|
||||
|
||||
UClientImage_Base::callerHandlerCache = UHTTP::handlerCache;
|
||||
UClientImage_Base::iov_vec[1].iov_base = (caddr_t)UServer_Base::ptr_shared_data->log_date_shared.date3;
|
||||
UClientImage_Base::iov_vec[1].iov_base = (caddr_t)UServer_Base::ptr_shared_data->log_date_shared.header1;
|
||||
#endif
|
||||
|
||||
U_INTERNAL_DUMP("UClientImage_Base::iov_vec[0] = %.*S UClientImage_Base::iov_vec[1] = %.*S",
|
||||
|
|
|
@ -176,7 +176,7 @@ int UProxyPlugIn::handlerRequest()
|
|||
if (result == false) UClientImage_Base::setRequestProcessed();
|
||||
else
|
||||
{
|
||||
UClientImage_Base::setNoHeaderForResponse();
|
||||
UClientImage_Base::bnoheader = true;
|
||||
|
||||
U_INTERNAL_DUMP("U_http_data_chunked = %b U_ClientImage_close = %b client_http->data_chunked = %b", U_http_data_chunked, U_ClientImage_close, client_http->data_chunked)
|
||||
|
||||
|
|
|
@ -91,6 +91,8 @@ int URpcPlugIn::handlerRequest()
|
|||
if (UServer_Base::isLog()) (void) UClientImage_Base::request_uri->assign(method);
|
||||
# endif
|
||||
|
||||
UClientImage_Base::bnoheader = true;
|
||||
|
||||
UClientImage_Base::setRequestProcessed();
|
||||
|
||||
U_RETURN(U_PLUGIN_HANDLER_PROCESSED);
|
||||
|
|
|
@ -1,18 +1,30 @@
|
|||
<!--#declaration
|
||||
static char* ptr;
|
||||
-->
|
||||
<!--#header
|
||||
-->
|
||||
<!--#code
|
||||
char* pwbuffer = UClientImage_Base::wbuffer->data();
|
||||
|
||||
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
||||
u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('1','3','\r','\n'));
|
||||
u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','t','e'));
|
||||
u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('x','t','/','p','l','a','i','n'));
|
||||
u_put_unalignedp32(pwbuffer+44, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
|
||||
U_INTERNAL_DUMP("pwbuffer = %#.10S", pwbuffer)
|
||||
|
||||
if (u_get_unalignedp64(pwbuffer+36) != U_MULTICHAR_CONSTANT64('x','t','/','p','l','a','i','n'))
|
||||
{
|
||||
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
||||
u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('1','3','\r','\n'));
|
||||
u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','t','e'));
|
||||
u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('x','t','/','p','l','a','i','n'));
|
||||
u_put_unalignedp32(pwbuffer+44, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
|
||||
|
||||
ptr = pwbuffer + U_CONSTANT_SIZE("Content-Length: 13\r\nContent-Type: text/plain\r\n\r\n");
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->data()), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
|
||||
|
||||
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('H','e','l','l','o',',',' ','W'));
|
||||
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('o','r','l','d','!','\0','\0','\0'));
|
||||
|
||||
UClientImage_Base::wbuffer->size_adjust_constant(U_CONSTANT_SIZE("Content-Length: 13\r\nContent-Type: text/plain\r\n\r\n") + 13);
|
||||
|
||||
u_put_unalignedp64(pwbuffer+48, U_MULTICHAR_CONSTANT64('H','e','l','l','o',',',' ','W'));
|
||||
u_put_unalignedp64(pwbuffer+56, U_MULTICHAR_CONSTANT64('o','r','l','d','!','\0','\0','\0'));
|
||||
-->
|
||||
|
|
|
@ -190,7 +190,8 @@ UVector<UIPAllow*>* UServer_Base::vallow_IP_prv;
|
|||
#endif
|
||||
|
||||
//#define U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY 1
|
||||
#ifdef U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY
|
||||
|
||||
#if defined(U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY) && defined(DEBUG)
|
||||
static uint32_t max_accepted;
|
||||
#endif
|
||||
|
||||
|
@ -2222,10 +2223,6 @@ void UServer_Base::loadConfigParam()
|
|||
|
||||
U_INTERNAL_DUMP("UNotifier::max_connection = %u USocket::iBackLog = %u", UNotifier::max_connection, USocket::iBackLog)
|
||||
|
||||
#ifdef U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY
|
||||
max_accepted = USocket::iBackLog;
|
||||
#endif
|
||||
|
||||
#ifdef USERVER_UDP
|
||||
if (budp &&
|
||||
u_printf_string_max_length == -1)
|
||||
|
@ -3754,8 +3751,8 @@ RETSIGTYPE UServer_Base::handlerForSigTERM(int signo)
|
|||
if (isLog()) logMemUsage("SIGTERM");
|
||||
# endif
|
||||
|
||||
# ifdef U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY
|
||||
U_WARNING("Max connections accepted simultaneously = %u", USocket::iBackLog - max_accepted);
|
||||
# if defined(U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY) && defined(DEBUG)
|
||||
U_WARNING("Max connections accepted simultaneously = %u", max_accepted);
|
||||
# endif
|
||||
|
||||
U_EXIT(0);
|
||||
|
@ -3842,10 +3839,8 @@ int UServer_Base::handlerRead()
|
|||
|
||||
U_INTERNAL_ASSERT_MINOR(nClientIndex, UNotifier::max_connection)
|
||||
|
||||
#ifndef U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY
|
||||
uint32_t accepted = 10;
|
||||
#else
|
||||
uint32_t accepted = USocket::iBackLog;
|
||||
#ifdef U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY
|
||||
uint32_t accepted = 10; // USocket::iBackLog;
|
||||
#endif
|
||||
|
||||
// This loops until the accept() fails, trying to start new connections as fast as possible so we don't overrun the listen queue
|
||||
|
@ -3999,7 +3994,7 @@ try_accept:
|
|||
if (CSOCKET->iState == -EAGAIN) U_ClientImage_state = U_PLUGIN_HANDLER_AGAIN;
|
||||
# endif
|
||||
|
||||
# ifdef U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY
|
||||
# if defined(U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY) && defined(DEBUG)
|
||||
if (accepted < max_accepted &&
|
||||
CSOCKET->iState == -EAGAIN)
|
||||
{
|
||||
|
@ -4243,33 +4238,35 @@ next:
|
|||
goto end;
|
||||
#endif
|
||||
|
||||
#ifdef U_MAX_CONNECTIONS_ACCEPTED_SIMULTANEOUSLY
|
||||
U_INTERNAL_DUMP("accepted = %u", accepted)
|
||||
|
||||
if (--accepted > 0)
|
||||
#endif
|
||||
{
|
||||
#if defined(ENABLE_THREAD) && defined(U_SERVER_THREAD_APPROACH_SUPPORT)
|
||||
if (preforked_num_kids != -1)
|
||||
#endif
|
||||
{
|
||||
U_INTERNAL_ASSERT_DIFFERS(socket_flags & O_NONBLOCK, 0)
|
||||
|
||||
U_INTERNAL_DUMP("cround = %u UNotifier::num_connection = %u num_client_threshold = %u", cround, UNotifier::num_connection, num_client_threshold)
|
||||
|
||||
if (num_client_threshold > UNotifier::num_connection) cround = 0;
|
||||
else
|
||||
{
|
||||
# if defined(ENABLE_THREAD) && defined(U_SERVER_THREAD_APPROACH_SUPPORT)
|
||||
if (preforked_num_kids != -1)
|
||||
# endif
|
||||
{
|
||||
U_INTERNAL_ASSERT_DIFFERS(socket_flags & O_NONBLOCK, 0)
|
||||
cround = 2;
|
||||
|
||||
U_INTERNAL_DUMP("cround = %u UNotifier::num_connection = %u num_client_threshold = %u", cround, UNotifier::num_connection, num_client_threshold)
|
||||
CLIENT_IMAGE = vClientImage;
|
||||
|
||||
if (num_client_threshold > UNotifier::num_connection) cround = 0;
|
||||
else
|
||||
{
|
||||
cround = 2;
|
||||
|
||||
CLIENT_IMAGE = vClientImage;
|
||||
|
||||
U_DEBUG("It has passed the client threshold(%u): preallocation(%u) num_connection(%u)",
|
||||
num_client_threshold, UNotifier::max_connection, UNotifier::num_connection - UNotifier::min_connection)
|
||||
}
|
||||
|
||||
goto loop;
|
||||
}
|
||||
U_DEBUG("It has passed the client threshold(%u): preallocation(%u) num_connection(%u)",
|
||||
num_client_threshold, UNotifier::max_connection, UNotifier::num_connection - UNotifier::min_connection)
|
||||
}
|
||||
|
||||
goto loop;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
#if defined(HAVE_EPOLL_CTL_BATCH) && !defined(USE_LIBEVENT)
|
||||
UNotifier::insertBatch();
|
||||
|
|
|
@ -2678,12 +2678,8 @@ void UHTTP2::handlerResponse()
|
|||
|
||||
if (dyntbl->num_entries == 0)
|
||||
{
|
||||
# if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_base, ULog::ptr_shared_date->date3)
|
||||
# else
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_base, ULog::date.date3)
|
||||
|
||||
ULog::updateDate3(0);
|
||||
# if !defined(U_LINUX) || !defined(ENABLE_THREAD)
|
||||
ULog::updateDate3(U_NULLPTR);
|
||||
# endif
|
||||
|
||||
UString date((void*)(((char*)UClientImage_Base::iov_vec[1].iov_base)+6), 29);
|
||||
|
@ -2707,11 +2703,7 @@ void UHTTP2::handlerResponse()
|
|||
|
||||
char* ptr_date = entry->value->data();
|
||||
|
||||
# if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_base, ULog::ptr_shared_date->date3)
|
||||
# else
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_base, ULog::date.date3)
|
||||
|
||||
# if !defined(U_LINUX) || !defined(ENABLE_THREAD)
|
||||
ULog::updateDate3(ptr_date);
|
||||
# endif
|
||||
|
||||
|
|
|
@ -463,7 +463,7 @@ loop:
|
|||
|
||||
// write data from multiple buffers
|
||||
|
||||
uint32_t USocketExt::iov_resize(struct iovec* liov, struct iovec* iov, int iovcnt, uint32_t byte_written)
|
||||
uint32_t USocketExt::iov_resize(struct iovec* liov, const struct iovec* iov, int iovcnt, uint32_t byte_written)
|
||||
{
|
||||
U_TRACE(0, "USocketExt::iov_resize(%p,%p,%d,%u)", liov, iov, iovcnt, byte_written)
|
||||
|
||||
|
@ -476,8 +476,8 @@ uint32_t USocketExt::iov_resize(struct iovec* liov, struct iovec* iov, int iovcn
|
|||
// iov[idx].iov_len = 0;
|
||||
}
|
||||
|
||||
liov = iov + idx;
|
||||
liovcnt = iovcnt - idx;
|
||||
liov = (struct iovec*)iov + idx;
|
||||
liovcnt = iovcnt - idx;
|
||||
|
||||
if (byte_written)
|
||||
{
|
||||
|
|
|
@ -109,7 +109,6 @@ UString* UHTTP::set_cookie_option;
|
|||
UString* UHTTP::user_authentication;
|
||||
UString* UHTTP::string_HTTP_Variables;
|
||||
uint32_t UHTTP::old_path_len;
|
||||
uint32_t UHTTP::old_response_code;
|
||||
uint32_t UHTTP::sid_counter_gen;
|
||||
uint32_t UHTTP::sid_counter_cur;
|
||||
uint32_t UHTTP::is_response_compressed;
|
||||
|
@ -1348,8 +1347,6 @@ void UHTTP::init()
|
|||
|
||||
setStatusDescription();
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(old_response_code, HTTP_OK)
|
||||
|
||||
U_MEMCPY(response_buffer, UClientImage_Base::iov_vec[0].iov_base, UClientImage_Base::iov_vec[0].iov_len);
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(strncmp(response_buffer, U_CONSTANT_TO_PARAM("HTTP/1.1 200 OK\r\n")), 0)
|
||||
|
@ -3784,8 +3781,6 @@ bool UHTTP::handlerCache()
|
|||
if (U_ClientImage_advise_for_parallelization == 2) U_RETURN(true);
|
||||
# endif
|
||||
|
||||
UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
# ifndef U_LOG_DISABLE
|
||||
if (UServer_Base::apache_like_log)
|
||||
{
|
||||
|
@ -4013,10 +4008,6 @@ int UHTTP::handlerREAD()
|
|||
{
|
||||
U_http_info.nResponseCode = HTTP_OK;
|
||||
|
||||
setStatusDescription();
|
||||
|
||||
UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
UClientImage_Base::setCloseConnection();
|
||||
|
||||
UClientImage_Base::setRequestProcessed();
|
||||
|
@ -4499,8 +4490,8 @@ file_in_cache:
|
|||
usp->runDynamicPage();
|
||||
# endif
|
||||
|
||||
U_DUMP("U_http_info.nResponseCode = %u U_ClientImage_parallelization = %d UClientImage_Base::isNoHeaderForResponse() = %b",
|
||||
U_http_info.nResponseCode, U_ClientImage_parallelization, UClientImage_Base::isNoHeaderForResponse())
|
||||
U_DUMP("U_http_info.nResponseCode = %u U_ClientImage_parallelization = %d UClientImage_Base::bnoheader = %b",
|
||||
U_http_info.nResponseCode, U_ClientImage_parallelization, UClientImage_Base::bnoheader)
|
||||
|
||||
if (U_http_info.nResponseCode == HTTP_OK)
|
||||
{
|
||||
|
@ -4514,7 +4505,7 @@ file_in_cache:
|
|||
# endif
|
||||
{
|
||||
# ifdef USE_LOAD_BALANCE
|
||||
if (UClientImage_Base::isNoHeaderForResponse() == false)
|
||||
if (UClientImage_Base::bnoheader == false)
|
||||
# endif
|
||||
setDynamicResponse();
|
||||
}
|
||||
|
@ -4728,7 +4719,7 @@ bool UHTTP::manageRequestOnRemoteServer()
|
|||
|
||||
if (client_http->sendRequestAndReadResponse(*UClientImage_Base::request, *UClientImage_Base::body))
|
||||
{
|
||||
UClientImage_Base::setNoHeaderForResponse();
|
||||
UClientImage_Base::bnoheader = true;
|
||||
|
||||
*UClientImage_Base::wbuffer = client_http->getResponse();
|
||||
|
||||
|
@ -6530,128 +6521,126 @@ void UHTTP::setStatusDescription()
|
|||
{
|
||||
U_TRACE_NO_PARAM(0, "UHTTP::setStatusDescription()")
|
||||
|
||||
U_INTERNAL_DUMP("old_response_code = %u U_http_info.nResponseCode = %u UClientImage_Base::iov_vec[0] = %.*S", old_response_code,
|
||||
U_http_info.nResponseCode, UClientImage_Base::iov_vec[0].iov_len, UClientImage_Base::iov_vec[0].iov_base)
|
||||
U_INTERNAL_DUMP("U_http_info.nResponseCode = %u UClientImage_Base::iov_vec[0] = %.*S",
|
||||
U_http_info.nResponseCode, UClientImage_Base::iov_vec[0].iov_len, UClientImage_Base::iov_vec[0].iov_base)
|
||||
|
||||
if (old_response_code != U_http_info.nResponseCode ||
|
||||
UClientImage_Base::iov_vec[0].iov_len == 0)
|
||||
switch (U_http_info.nResponseCode)
|
||||
{
|
||||
switch ((old_response_code = U_http_info.nResponseCode))
|
||||
// 1xx indicates an informational message only
|
||||
case HTTP_SWITCH_PROT:
|
||||
{
|
||||
// 1xx indicates an informational message only
|
||||
case HTTP_SWITCH_PROT:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 101 Switching Protocols\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 101 Switching Protocols\r\n");
|
||||
}
|
||||
break;
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 101 Switching Protocols\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 101 Switching Protocols\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
// 2xx indicates success of some kind
|
||||
case HTTP_OK:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 200 OK\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 200 OK\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NO_CONTENT:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 204 No Content\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 204 No Content\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_PARTIAL:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 206 Partial Content\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 206 Partial Content\r\n");
|
||||
}
|
||||
break;
|
||||
// 2xx indicates success of some kind
|
||||
case HTTP_OK:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 200 OK\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 200 OK\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NO_CONTENT:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 204 No Content\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 204 No Content\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_PARTIAL:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 206 Partial Content\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 206 Partial Content\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
// 3xx Redirection - Further action must be taken in order to complete the request
|
||||
case HTTP_MOVED_TEMP:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 302 Moved Temporarily\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 302 Moved Temporarily\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NOT_MODIFIED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 304 Not Modified\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 304 Not Modified\r\n");
|
||||
}
|
||||
break;
|
||||
// 3xx Redirection - Further action must be taken in order to complete the request
|
||||
case HTTP_MOVED_TEMP:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 302 Moved Temporarily\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 302 Moved Temporarily\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NOT_MODIFIED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 304 Not Modified\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 304 Not Modified\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
// 4xx indicates an error on the client's part
|
||||
case HTTP_BAD_REQUEST:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 400 Bad Request\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 400 Bad Request\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_UNAUTHORIZED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 401 Authorization Required\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 401 Authorization Required\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_FORBIDDEN:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 403 Forbidden\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 403 Forbidden\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NOT_FOUND:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 404 Not Found\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 404 Not Found\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_LENGTH_REQUIRED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 411 Length Required\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 411 Length Required\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_ENTITY_TOO_LARGE:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 413 Request Entity Too Large\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 413 Request Entity Too Large\r\n");
|
||||
}
|
||||
break;
|
||||
// 4xx indicates an error on the client's part
|
||||
case HTTP_BAD_REQUEST:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 400 Bad Request\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 400 Bad Request\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_UNAUTHORIZED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 401 Authorization Required\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 401 Authorization Required\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_FORBIDDEN:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 403 Forbidden\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 403 Forbidden\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NOT_FOUND:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 404 Not Found\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 404 Not Found\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_LENGTH_REQUIRED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 411 Length Required\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 411 Length Required\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_ENTITY_TOO_LARGE:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 413 Request Entity Too Large\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 413 Request Entity Too Large\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
// 5xx indicates an error on the server's part
|
||||
case HTTP_INTERNAL_ERROR:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 500 Internal Server Error\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 500 Internal Server Error\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NOT_IMPLEMENTED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 501 Not Implemented\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 501 Not Implemented\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_VERSION:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 505 HTTP Version Not Supported\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 505 HTTP Version Not Supported\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NETWORK_AUTHENTICATION_REQUIRED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 511 Network authentication required\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 511 Network authentication required\r\n");
|
||||
}
|
||||
break;
|
||||
// 5xx indicates an error on the server's part
|
||||
case HTTP_INTERNAL_ERROR:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 500 Internal Server Error\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 500 Internal Server Error\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NOT_IMPLEMENTED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 501 Not Implemented\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 501 Not Implemented\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_VERSION:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 505 HTTP Version Not Supported\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 505 HTTP Version Not Supported\r\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_NETWORK_AUTHENTICATION_REQUIRED:
|
||||
{
|
||||
UClientImage_Base::iov_vec[0].iov_base = (caddr_t) "HTTP/1.1 511 Network authentication required\r\n";
|
||||
UClientImage_Base::iov_vec[0].iov_len = U_CONSTANT_SIZE("HTTP/1.1 511 Network authentication required\r\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
uint32_t sz;
|
||||
const char* status = getStatusDescription(&sz);
|
||||
default:
|
||||
{
|
||||
uint32_t sz;
|
||||
const char* status = getStatusDescription(&sz);
|
||||
|
||||
UClientImage_Base::iov_vec[0].iov_base = response_buffer;
|
||||
UClientImage_Base::iov_vec[0].iov_len = 9+u__snprintf(response_buffer+9, sizeof(response_buffer)-9, U_CONSTANT_TO_PARAM("%u %.*s\r\n"), old_response_code, sz, status);
|
||||
}
|
||||
// 9 => U_CONSTANT_SIZE("HTTP/1.1 ")
|
||||
|
||||
UClientImage_Base::iov_vec[0].iov_base = response_buffer;
|
||||
UClientImage_Base::iov_vec[0].iov_len = 9+u__snprintf(response_buffer+9, sizeof(response_buffer)-9, U_CONSTANT_TO_PARAM("%u %.*s\r\n"), U_http_info.nResponseCode, sz, status);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6686,14 +6675,6 @@ void UHTTP::handlerResponse()
|
|||
else
|
||||
#endif
|
||||
{
|
||||
U_INTERNAL_DUMP("UClientImage_Base::iov_vec[0].iov_len = %u UClientImage_Base::iov_vec[1].iov_len = %u", UClientImage_Base::iov_vec[0].iov_len, UClientImage_Base::iov_vec[1].iov_len)
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_len, 51)
|
||||
|
||||
// UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
setStatusDescription();
|
||||
|
||||
// NB: all other responses must include an entity body or a Content-Length header field defined with a value of zero (0)
|
||||
|
||||
char* ptr;
|
||||
|
@ -6789,10 +6770,7 @@ void UHTTP::handlerResponse()
|
|||
{
|
||||
UClientImage_Base::wbuffer->swap(*ext);
|
||||
|
||||
U_INTERNAL_DUMP("UClientImage_Base::wbuffer(%u) = %#V", UClientImage_Base::wbuffer->size(), UClientImage_Base::wbuffer->rep)
|
||||
U_INTERNAL_DUMP("UClientImage_Base::body(%u) = %V", UClientImage_Base::body->size(), UClientImage_Base::body->rep)
|
||||
|
||||
return;
|
||||
goto end;
|
||||
}
|
||||
|
||||
ptr2 = ext->data();
|
||||
|
@ -6808,20 +6786,32 @@ void UHTTP::handlerResponse()
|
|||
|
||||
// A server implements an HSTS policy by supplying a header over an HTTPS connection (HSTS headers over HTTP are ignored)
|
||||
|
||||
# if defined(USE_LIBSSL) && defined(U_HTTP_STRICT_TRANSPORT_SECURITY)
|
||||
# if defined(USE_LIBSSL) && defined(U_HTTP_STRICT_TRANSPORT_SECURITY)
|
||||
if (UServer_Base::bssl &&
|
||||
uri_strict_transport_security_mask == (void*)1L)
|
||||
{
|
||||
ptr2 = "Strict-Transport-Security: max-age=31536000; includeSubDomains; preload\r\nContent-Length: 0\r\n\r\n";
|
||||
sz2 = U_CONSTANT_SIZE("Strict-Transport-Security: max-age=31536000; includeSubDomains; preload\r\nContent-Length: 0\r\n\r\n");
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
U_MEMCPY(ptr, ptr2, sz2);
|
||||
|
||||
UClientImage_Base::wbuffer->size_adjust(sz1 + sz2);
|
||||
|
||||
end:
|
||||
U_INTERNAL_DUMP("UClientImage_Base::iov_vec[0].iov_len = %u UClientImage_Base::iov_vec[1].iov_len = %u", UClientImage_Base::iov_vec[0].iov_len, UClientImage_Base::iov_vec[1].iov_len)
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_len, 17+6+29+2+12+2) // HTTP/1.1 200 OK\r\nDate: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
if (U_http_info.nResponseCode != HTTP_OK)
|
||||
{
|
||||
setStatusDescription();
|
||||
|
||||
UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
}
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("UClientImage_Base::wbuffer(%u) = %#V", UClientImage_Base::wbuffer->size(), UClientImage_Base::wbuffer->rep)
|
||||
|
@ -7386,10 +7376,6 @@ void UHTTP::setDynamicResponse()
|
|||
|
||||
UClientImage_Base::setRequestProcessed();
|
||||
|
||||
UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
setStatusDescription();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -10863,7 +10849,7 @@ loop:
|
|||
noparse:
|
||||
U_ASSERT(UClientImage_Base::body->empty())
|
||||
|
||||
UClientImage_Base::setNoHeaderForResponse();
|
||||
UClientImage_Base::bnoheader = true;
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
@ -12015,22 +12001,19 @@ loop: while (u__isalpha(*++ptr1)) {}
|
|||
{
|
||||
old_sz = sz;
|
||||
|
||||
ULog::updateDate3(U_NULLPTR);
|
||||
|
||||
U_http_info.nResponseCode = HTTP_OK;
|
||||
|
||||
UClientImage_Base::body->clear();
|
||||
UClientImage_Base::wbuffer->size_adjust_constant(0U);
|
||||
|
||||
UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
setStatusDescription();
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_base, ULog::date.date3)
|
||||
|
||||
ULog::updateDate3(U_NULLPTR);
|
||||
|
||||
# ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
UServer_Base::handler_db1->reset();
|
||||
UServer_Base::handler_db2->reset();
|
||||
if (UServer_Base::handler_db1)
|
||||
{
|
||||
UServer_Base::handler_db1->reset();
|
||||
UServer_Base::handler_db2->reset();
|
||||
}
|
||||
# endif
|
||||
|
||||
next: if (*ptr1 == '?')
|
||||
|
|
|
@ -1 +1 @@
|
|||
0374
|
||||
03C8
|
||||
|
|
|
@ -1,18 +1,30 @@
|
|||
<!--#declaration
|
||||
static char* ptr;
|
||||
-->
|
||||
<!--#header
|
||||
-->
|
||||
<!--#code
|
||||
char* pwbuffer = UClientImage_Base::wbuffer->data();
|
||||
|
||||
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
||||
u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('1','3','\r','\n'));
|
||||
u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','t','e'));
|
||||
u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('x','t','/','p','l','a','i','n'));
|
||||
u_put_unalignedp32(pwbuffer+44, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
|
||||
U_INTERNAL_DUMP("pwbuffer = %#.10S", pwbuffer)
|
||||
|
||||
if (u_get_unalignedp64(pwbuffer+36) != U_MULTICHAR_CONSTANT64('x','t','/','p','l','a','i','n'))
|
||||
{
|
||||
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
|
||||
u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('1','3','\r','\n'));
|
||||
u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
|
||||
u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','t','e'));
|
||||
u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('x','t','/','p','l','a','i','n'));
|
||||
u_put_unalignedp32(pwbuffer+44, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
|
||||
|
||||
ptr = pwbuffer + U_CONSTANT_SIZE("Content-Length: 13\r\nContent-Type: text/plain\r\n\r\n");
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->data()), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
|
||||
|
||||
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('H','e','l','l','o',',',' ','W'));
|
||||
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('o','r','l','d','!','\0','\0','\0'));
|
||||
|
||||
UClientImage_Base::wbuffer->size_adjust_constant(U_CONSTANT_SIZE("Content-Length: 13\r\nContent-Type: text/plain\r\n\r\n") + 13);
|
||||
|
||||
u_put_unalignedp64(pwbuffer+48, U_MULTICHAR_CONSTANT64('H','e','l','l','o',',',' ','W'));
|
||||
u_put_unalignedp64(pwbuffer+56, U_MULTICHAR_CONSTANT64('o','r','l','d','!','\0','\0','\0'));
|
||||
-->
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
start_msg redis
|
||||
|
||||
UTRACE="0 50M 0"
|
||||
#UTRACE="0 50M 0"
|
||||
#UTRACE_SIGNAL="0 100M 0"
|
||||
#UOBJDUMP="0 50M 1000"
|
||||
#USIMERR="error.sim"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// test_redis.cpp
|
||||
|
||||
#include <ulib/net/tcpsocket.h>
|
||||
#include <ulib/net/client/redis.h>
|
||||
|
||||
int main(int argc, char *argv[], char* env[])
|
||||
|
@ -9,7 +8,7 @@ int main(int argc, char *argv[], char* env[])
|
|||
|
||||
U_TRACE(5,"main(%d)",argc)
|
||||
|
||||
UREDISClient<UTCPSocket> rc;
|
||||
UREDISClient<UUnixSocket> rc;
|
||||
|
||||
if (rc.connect())
|
||||
{
|
||||
|
@ -69,8 +68,6 @@ int main(int argc, char *argv[], char* env[])
|
|||
|
||||
ok = rc.sadd(U_CONSTANT_TO_PARAM("MY_SET"), U_CONSTANT_TO_PARAM("123 14"));
|
||||
|
||||
U_INTERNAL_ASSERT(ok)
|
||||
|
||||
ok = rc.smembers(U_CONSTANT_TO_PARAM("MY_SET"));
|
||||
|
||||
U_INTERNAL_ASSERT(ok)
|
||||
|
|
Loading…
Reference in New Issue
Block a user