ithewei 6 anni fa
parent
commit
5afe52038f
11 ha cambiato i file con 1269 aggiunte e 148 eliminazioni
  1. 95 0
      .clang-format
  2. 2 0
      .gitignore
  3. 2 1
      base/heap.h
  4. 2 0
      base/queue.h
  5. 1 2
      configure
  6. 1 2
      hconfig.h
  7. 28 27
      http/server/HttpServer.cpp
  8. 3 3
      main.cpp.tmpl
  9. 1 0
      scripts/create_pro.sh
  10. 484 58
      sqlite/sqlite3.c
  11. 650 55
      sqlite/sqlite3.h

+ 95 - 0
.clang-format

@@ -0,0 +1,95 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: true
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: Inline
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:   
+  AfterClass:      false
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     true
+  BeforeElse:      true
+  IndentBraces:    false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     200
+CommentPragmas:  '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: true
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeCategories: 
+  - Regex:           '.*'
+    Priority:        1
+  - Regex:           '^".*/'
+    Priority:        2
+  - Regex:           '^<)'
+    Priority:        3
+IncludeIsMainRegex: '$'
+IndentCaseLabels: false
+IndentWidth:     4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+ReflowComments:  true
+SortIncludes:    false
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        4
+UseTab:          Never
+...
+

+ 2 - 0
.gitignore

@@ -8,6 +8,7 @@
 # IDE
 .vs
 .vscode
+.DS_Store
 
 tags
 cscope*
@@ -25,6 +26,7 @@ tmp
 lib
 bin
 dist
+build
 
 # test
 test

+ 2 - 1
base/heap.h

@@ -14,7 +14,8 @@ struct heap_node {
 typedef int (*heap_compare_fn)(const struct heap_node* lhs, const struct heap_node* rhs);
 struct heap {
     struct heap_node* root;
-    int nelts; // if compare is less_than, root is min of heap
+    int nelts;
+    // if compare is less_than, root is min of heap
     // if compare is larger_than, root is max of heap
     heap_compare_fn compare;
 };

+ 2 - 0
base/queue.h

@@ -4,6 +4,8 @@
 /*
  * queue
  * FIFO: push_back,pop_front
+ * stack
+ * LIFO: push_back,pop_back
  */
 
 #include <assert.h> // for assert

+ 1 - 2
configure

@@ -125,8 +125,7 @@ function=gettimeofday && header=sys/time.h && check_funtion
 
 # end confile
 cat << END >> $confile
-#endif // HW_CONFIG_H_
-
+#endif  // HW_CONFIG_H_
 END
 
 echo "configure done."

+ 1 - 2
hconfig.h

@@ -45,5 +45,4 @@
 #define HAVE_GETTIMEOFDAY 1
 #endif
 
-#endif // HW_CONFIG_H_
-
+#endif  // HW_CONFIG_H_

+ 28 - 27
http/server/HttpServer.cpp

@@ -26,7 +26,7 @@ static void master_init(void* userdata) {
 }
 
 static void master_proc(void* userdata) {
-    while(1) sleep(1);
+    while (1) sleep(1);
 }
 
 static void worker_init(void* userdata) {
@@ -39,7 +39,7 @@ static void worker_init(void* userdata) {
 }
 
 static void on_recv(hio_t* io, void* _buf, int readbytes) {
-    //printf("on_recv fd=%d readbytes=%d\n", hio_fd(io), readbytes);
+    // printf("on_recv fd=%d readbytes=%d\n", hio_fd(io), readbytes);
     const char* buf = (const char*)_buf;
     HttpHandler* handler = (HttpHandler*)hevent_userdata(io);
     // HTTP1 / HTTP2 -> HttpSession -> InitRequest
@@ -115,32 +115,32 @@ static void on_recv(hio_t* io, void* _buf, int readbytes) {
 
     // Upgrade: h2
     {
-    auto iter_upgrade = req->headers.find("upgrade");
-    if (iter_upgrade != req->headers.end()) {
-        hlogi("[%s:%d] Upgrade: %s", handler->ip, handler->port, iter_upgrade->second.c_str());
-        // h2/h2c
-        if (strnicmp(iter_upgrade->second.c_str(), "h2", 2) == 0) {
-            hio_write(io, HTTP2_UPGRADE_RESPONSE, strlen(HTTP2_UPGRADE_RESPONSE));
-            SAFE_DELETE(handler->session);
-            session = handler->session = HttpSession::New(HTTP_SERVER, HTTP_V2);
-            if (session == NULL) {
-                hloge("[%s:%d] unsupported HTTP2", handler->ip, handler->port);
+        auto iter_upgrade = req->headers.find("upgrade");
+        if (iter_upgrade != req->headers.end()) {
+            hlogi("[%s:%d] Upgrade: %s", handler->ip, handler->port, iter_upgrade->second.c_str());
+            // h2/h2c
+            if (strnicmp(iter_upgrade->second.c_str(), "h2", 2) == 0) {
+                hio_write(io, HTTP2_UPGRADE_RESPONSE, strlen(HTTP2_UPGRADE_RESPONSE));
+                SAFE_DELETE(handler->session);
+                session = handler->session = HttpSession::New(HTTP_SERVER, HTTP_V2);
+                if (session == NULL) {
+                    hloge("[%s:%d] unsupported HTTP2", handler->ip, handler->port);
+                    hio_close(io);
+                    return;
+                }
+                HttpRequest http1_req = *req;
+                session->InitRequest(req);
+                *req = http1_req;
+                req->http_major = 2;
+                req->http_minor = 0;
+                // HTTP2_Settings: ignore
+                // session->FeedRecvData(HTTP2_Settings, );
+            }
+            else {
                 hio_close(io);
                 return;
             }
-            HttpRequest http1_req = *req;
-            session->InitRequest(req);
-            *req = http1_req;
-            req->http_major = 2;
-            req->http_minor = 0;
-            // HTTP2_Settings: ignore
-            //session->FeedRecvData(HTTP2_Settings, );
         }
-        else {
-            hio_close(io);
-            return;
-        }
-    }
     }
 #endif
 
@@ -182,9 +182,10 @@ handle_request:
             sendbuf = handler->fc->httpbuf;
         }
         else {
-            if (content_length > (1<<20)) {
+            if (content_length > (1 << 20)) {
                 send_in_one_packet = false;
-            } else if (content_length != 0) {
+            }
+            else if (content_length != 0) {
                 header.insert(header.size(), (const char*)res->Content(), content_length);
             }
             sendbuf.base = (char*)header.c_str();
@@ -302,7 +303,7 @@ static void worker_proc(void* userdata) {
     hlog_disable_fsync();
     hidle_add(loop, fsync_logfile, INFINITE);
     // timer handle_cached_files
-    htimer_t* timer = htimer_add(loop, handle_cached_files, s_filecache.file_cached_time*1000);
+    htimer_t* timer = htimer_add(loop, handle_cached_files, s_filecache.file_cached_time * 1000);
     hevent_set_userdata(timer, &s_filecache);
     hloop_run(loop);
     hloop_free(&loop);

+ 3 - 3
main.cpp.tmpl

@@ -189,7 +189,7 @@ int main(int argc, char** argv) {
         print_help();
         exit(10);
     }
-    //int ret = parse_opt(argc, argv, options);
+    // int ret = parse_opt(argc, argv, options);
     int ret = parse_opt_long(argc, argv, long_options, ARRAY_SIZE(long_options));
     if (ret != 0) {
         print_help();
@@ -298,9 +298,9 @@ int main(int argc, char** argv) {
 }
 
 void master_proc(void* userdata) {
-    while(1) sleep(1);
+    while (1) sleep(1);
 }
 
 void worker_proc(void* userdata) {
-    while(1) sleep(1);
+    while (1) sleep(1);
 }

+ 1 - 0
scripts/create_pro.sh

@@ -7,6 +7,7 @@ git init
 # personal
 git submodule add https://github.com/ithewei/hw.git src/hw
 cp src/hw/.gitignore .
+cp src/hw/.clang-format .
 cp src/hw/Makefile .
 cp -r src/hw/etc/* etc
 cp src/hw/main.cpp.tmpl src/main.cpp

File diff suppressed because it is too large
+ 484 - 58
sqlite/sqlite3.c


File diff suppressed because it is too large
+ 650 - 55
sqlite/sqlite3.h


Some files were not shown because too many files changed in this diff