Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Nov 29, 2019
1 parent 50c395c commit 5afe520
Show file tree
Hide file tree
Showing 11 changed files with 44,103 additions and 28,071 deletions.
95 changes: 95 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# IDE
.vs
.vscode
.DS_Store

tags
cscope*
Expand All @@ -25,6 +26,7 @@ tmp
lib
bin
dist
build

# test
test
Expand Down
3 changes: 2 additions & 1 deletion base/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions base/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/*
* queue
* FIFO: push_back,pop_front
* stack
* LIFO: push_back,pop_back
*/

#include <assert.h> // for assert
Expand Down
3 changes: 1 addition & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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."
3 changes: 1 addition & 2 deletions hconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@
#define HAVE_GETTIMEOFDAY 1
#endif

#endif // HW_CONFIG_H_

#endif // HW_CONFIG_H_
55 changes: 28 additions & 27 deletions http/server/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -182,9 +182,10 @@ static void on_recv(hio_t* io, void* _buf, int readbytes) {
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();
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions main.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions scripts/create_pro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5afe520

Please sign in to comment.