1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-10-26 19:57:22 +08:00

start HTTP/2 implementation

This commit is contained in:
stefanocasazza
2015-04-24 20:09:44 +02:00
parent 13e5dd2f97
commit fa9ca91508
100 changed files with 8920 additions and 1298 deletions

View File

@@ -37,6 +37,7 @@ class UFCGIPlugIn;
class USCGIPlugIn;
class UProxyPlugIn;
class UNoCatPlugIn;
class UServer_Base;
class UHttpClient_Base;
class U_EXPORT UClient_Base {
@@ -265,6 +266,7 @@ private:
friend class UHttpPlugIn;
friend class UProxyPlugIn;
friend class UNoCatPlugIn;
friend class UServer_Base;
friend class UHttpClient_Base;
};

View File

@@ -31,6 +31,7 @@
*/
class UHTTP;
class UHTTP2;
class UIPAllow;
class USSIPlugIn;
class UHttpPlugIn;
@@ -45,6 +46,13 @@ template <class T> class UServer;
class U_EXPORT UClientImage_Base : public UEventFd {
public:
// Check for memory error
U_MEMORY_TEST
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
// SERVICES
bool genericRead();
@@ -324,6 +332,9 @@ public:
protected:
USocket* socket;
#ifndef U_HTTP2_DISABLE
void* connection;
#endif
UString* data_pending;
uint32_t start, count;
int sfd, pending_close;
@@ -418,6 +429,7 @@ private:
UClientImage_Base& operator=(const UClientImage_Base&) { return *this; }
friend class UHTTP;
friend class UHTTP2;
friend class USSIPlugIn;
friend class UHttpPlugIn;
friend class UNoCatPlugIn;

View File

@@ -20,9 +20,8 @@
class U_EXPORT UHttpPlugIn : public UServerPlugIn, UEventFd {
public:
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
// Check for memory error
U_MEMORY_TEST
// COSTRUTTORI

View File

@@ -28,8 +28,7 @@ class UDirWalk;
class UIptAccount;
class UNoCatPlugIn;
// sizeof(UModNoCatPeer) 32bit == 196
// sizeof(UModNoCatPeer) 64bit == 304
// sizeof(UModNoCatPeer) 32bit == 212
class UModNoCatPeer : public UEventTime, UIPAddress {
public:
@@ -58,7 +57,7 @@ public:
// COSTRUTTORI
UModNoCatPeer() : UEventTime(0L,1L), mac(*UString::str_without_mac), token(100U), gateway(100U)
UModNoCatPeer() : UEventTime(0L,1L), mac(*UString::str_without_mac)
{
U_TRACE_REGISTER_OBJECT(0, UModNoCatPeer, "", 0)
@@ -244,13 +243,18 @@ protected:
static UString getSignedData(const char* ptr, uint32_t len);
static UString getUrlForSendMsgToPortal(uint32_t index_AUTH, const char* msg, uint32_t msg_len);
static void preallocatePeers() { U_NEW_VECTOR_ULIB_OBJECT(peers_preallocate, num_peers_preallocate, UModNoCatPeer, 0); }
static void getARPCache()
static void preallocatePeers()
{
U_TRACE(0, "UNoCatPlugIn::getARPCache()")
U_TRACE(0+256, "UNoCatPlugIn::preallocatePeers()")
(void) USocketExt::getARPCache(*arp_cache, *varp_cache);
peers_preallocate = new UModNoCatPeer[num_peers_preallocate];
}
static bool getARPCache()
{
U_TRACE(0+256, "UNoCatPlugIn::getARPCache()")
return USocketExt::getARPCache(*arp_cache, *varp_cache);
}
static void sendMsgToAllPortal(const UString& msg)

View File

@@ -55,10 +55,10 @@ const char* dump(bool reset) const { return UServer<socket_type>::dump(reset); }
protected: \
virtual void preallocate() U_DECL_OVERRIDE { \
U_TRACE(5+256, #server_class "::preallocate()") \
(void) U_NEW_VECTOR(UNotifier::max_connection, client_type, &oClientImage); } \
vClientImage = new client_type[UNotifier::max_connection]; } \
virtual void deallocate() U_DECL_OVERRIDE { \
U_TRACE(5+256, #server_class "::deallocate()") \
u_delete_vector<client_type>((client_type*)vClientImage, oClientImage, UNotifier::max_connection); } \
delete[] (client_type*)vClientImage; } \
virtual bool check_memory() U_DECL_OVERRIDE { return u_check_memory_vector<client_type>((client_type*)vClientImage, UNotifier::max_connection); } }
#else
# define U_MACROSERVER(server_class,client_type,socket_type) \
@@ -68,7 +68,7 @@ public: \
~server_class() {} \
protected: \
virtual void preallocate() U_DECL_OVERRIDE { \
(void) U_NEW_VECTOR(UNotifier::max_connection, client_type, &oClientImage); } }
vClientImage = new client_type[UNotifier::max_connection]; } }
#endif
// ---------------------------------------------------------------------------------------------
@@ -94,6 +94,7 @@ virtual void preallocate() U_DECL_OVERRIDE { \
#endif
class UHTTP;
class UHTTP2;
class UCommand;
class USSLSocket;
class USSIPlugIn;
@@ -119,6 +120,13 @@ class UModProxyService;
class U_EXPORT UServer_Base : public UEventFd {
public:
// Check for memory error
U_MEMORY_TEST
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
// -----------------------------------------------------------------------------------------------------------------------------
// UServer - configuration parameters
// -----------------------------------------------------------------------------------------------------------------------------
@@ -257,9 +265,9 @@ public:
sem_t lock_rdb_server;
# ifdef USE_LIBSSL
sem_t lock_ssl_session;
# ifdef ENABLE_THREAD
# if defined(ENABLE_THREAD) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
sem_t lock_ocsp_staple;
# endif
# endif
# endif
sem_t lock_static_date;
sem_t lock_data_session;
@@ -269,9 +277,9 @@ public:
char spinlock_rdb_server[1];
# ifdef USE_LIBSSL
char spinlock_ssl_session[1];
# ifdef ENABLE_THREAD
# if defined(ENABLE_THREAD) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
char spinlock_ocsp_staple[1];
# endif
# endif
# endif
char spinlock_static_date[1];
char spinlock_data_session[1];
@@ -566,8 +574,9 @@ protected:
static UVector<UIPAllow*>* vallow_IP_prv;
#endif
#if defined(USE_LIBSSL) && defined(ENABLE_THREAD)
#if defined(USE_LIBSSL) && defined(ENABLE_THREAD) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
static ULock* lock_ocsp_staple;
static UOCSPStapling* pthread_ocsp;
static void setLockOCSPStaple()
{
@@ -591,10 +600,6 @@ protected:
class U_NO_EXPORT UTimeoutConnection : public UEventTime {
public:
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
// COSTRUTTORI
UTimeoutConnection() : UEventTime(timeoutMS / 1000L, 0L)
@@ -676,6 +681,7 @@ protected:
private:
friend class UHTTP;
friend class UHTTP2;
friend class USSLSocket;
friend class USSIPlugIn;
friend class UWebSocket;
@@ -748,7 +754,11 @@ protected:
// NB: array are not pointers (virtual table can shift the address of this)...
(void) U_NEW_VECTOR(UNotifier::max_connection, client_type, &oClientImage);
vClientImage = new client_type[UNotifier::max_connection];
U_INTERNAL_DUMP("vClientImage = %p pClientIndex = %p", vClientImage, pClientIndex)
U_INTERNAL_ASSERT_EQUALS(vClientImage, pClientIndex)
}
#ifdef DEBUG
@@ -758,7 +768,7 @@ protected:
// NB: array are not pointers (virtual table can shift the address of this)...
u_delete_vector<client_type>((client_type*)vClientImage, oClientImage, UNotifier::max_connection);
delete[] (client_type*)vClientImage;
}
virtual bool check_memory() U_DECL_OVERRIDE { return u_check_memory_vector<client_type>((client_type*)vClientImage, UNotifier::max_connection); }
@@ -822,7 +832,7 @@ protected:
// NB: array are not pointers (virtual table can shift the address of this)...
(void) U_NEW_VECTOR(UNotifier::max_connection, client_type, &oClientImage);
vClientImage = new client_type[UNotifier::max_connection];
}
#ifdef DEBUG
@@ -832,7 +842,7 @@ protected:
// NB: array are not pointers (virtual table can shift the address of this)...
u_delete_vector<client_type>((client_type*)vClientImage, oClientImage, UNotifier::max_connection);
delete[] (client_type*)vClientImage;
}
virtual bool check_memory() U_DECL_OVERRIDE { return u_check_memory_vector<client_type>((client_type*)vClientImage, UNotifier::max_connection); }

View File

@@ -60,6 +60,10 @@ class UFileConfig;
class UServerPlugIn {
public:
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
// COSTRUTTORE
UServerPlugIn() {}

View File

@@ -54,8 +54,9 @@
* they use class UIPAddress instances and port numbers rather than sockaddr structures
*/
class UHTTP;
class UFile;
class UHTTP;
class UHTTP2;
class UNotifier;
class USocketExt;
class UFtpClient;
@@ -289,6 +290,8 @@ public:
void setLocal();
UString getMacAddress(const char* device);
UIPAddress& localIPAddress() __pure;
unsigned int localPortNumber() __pure;
@@ -379,7 +382,18 @@ public:
* socket. At the socket layer, this sends a TCP/IP FIN packet to the receiver
*/
bool shutdown(int how = SHUT_WR);
bool shutdown(int how = SHUT_WR)
{
U_TRACE(1, "USocket::shutdown(%d)", how)
U_CHECK_MEMORY
U_INTERNAL_ASSERT(isOpen())
if (U_SYSCALL(shutdown, "%d,%d", getFd(), how) == 0) U_RETURN(true);
U_RETURN(false);
}
/**
* Stick a TCP cork in the socket. It's not clear that this will help performance, but it might.
@@ -447,7 +461,7 @@ public:
{
U_TRACE(0, "USocket::setTcpLingerOff()")
const struct linger l = { 1, 1 };
const struct linger l = { 1, 0 };
(void) setSockOpt(SOL_SOCKET, SO_LINGER, &l, sizeof(struct linger));
}
@@ -458,6 +472,11 @@ public:
* (for example "write"), and you'll find out right away since the kernel is now just reporting the status of a previously set flag,
* rather than having to wait a few seconds (or much longer in some cases) for network activity to fail. The exact same code logic you
* had for handling the "other side went away unexpectedly" condition will still be used; what changes is the timing (not the method)
*
* Ref1: FIN_WAIT2 [https://kb.iu.edu/d/ajmi]
* Ref2: tcp_fin_timeout [https://www.frozentux.net/ipsysctl-tutorial/chunkyhtml/tcpvariables.html#AEN370]
* Ref3: tcp_retries2 [https://www.frozentux.net/ipsysctl-tutorial/chunkyhtml/tcpvariables.html#AEN444]
* Ref4: tcp_max_orphans [https://www.frozentux.net/ipsysctl-tutorial/chunkyhtml/tcpvariables.html#AEN388]
*/
void setTcpKeepAlive()
@@ -626,6 +645,7 @@ private:
#endif
friend class UHTTP;
friend class UHTTP2;
friend class UFile;
friend class UNotifier;
friend class USocketExt;