// File: /workspace/github_cpp_makefile_star2_O1/lega911[P]ijson/src/connect.cpp
// Function: Connect::on_recv(char*, int)
void Connect::on_recv(char *buf, int size) {
    if(ping) ping_timeout = get_time_sec() + ping;
    if(!(status == Status::net || (status == Status::worker_wait_result && noid) || (status == Status::worker_mode_async && worker_mode))) {
        if(server->log & 4) std::cout << ltime() << "connect " << (void*)this << ", warning: data is come, but connection is not ready\n";
        buffer.add(buf, size);
        return;
    }
    Slice data;
    if(buffer.size()) {
        buffer.add(buf, size);
        data = Slice(buffer);
    } else {
        data = Slice(buf, size);
    }

    if(http_step == HTTP_READ_BODY) {
        int for_read = content_length - body.size();
        if(for_read > data.size()) {
            body.add(data);
            buffer.clear();
            return;
        } else {
            Slice s = data.pop(for_read);
            body.add(s);
            //buffer.add(data);
        }
        if(body.size() == content_length) {
            try {
                this->header_completed();
            } catch (const error::InvalidData &e) {
                if(server->log & 4) std::cout << ltime() << "Error: Invalid data/json, socket " << fd << " " << (void*)this << std::endl;
                this->send.status("400 Invalid data")->done(-32700);
            }
            http_step = HTTP_START;
        }
        if(data.empty()) return;
    }

    Slice line;
    while(true) {
        line = data.pop_line();
        if(!line.valid()) break;  // wait next package
        line.rstrip();

        if(line.empty()) {
            if(http_step != HTTP_HEADER) throw error::InvalidData("Wrong HTTP request");
            http_step = HTTP_REQUEST_COMPLETED;
            if(content_length) {
                int for_read = content_length;
                if(for_read > data.size()) for_read = data.size();
                Slice body_data = data.pop(for_read);
                body.set(body_data);

                if(body.size() < content_length) {
                    http_step = HTTP_READ_BODY;
                };
            };
            //if(data.size()) buffer.set(data);
            buffer.clear();
            if(http_step == HTTP_REQUEST_COMPLETED) {
                try {
                    this->header_completed();
                } catch (const error::InvalidData &e) {
                    this->send.status("400 Invalid data")->done(-32700);
                }

                if(data.size()) {
                    if(status == Status::net) {
                        http_step = HTTP_START;
                        continue;
                    } else THROW("previous request is not finished");
                }
            }
            break;
        }
        if(http_step == HTTP_START) {
            body.clear();
            id.clear();
            header_option.reset();
            info.reset();
            json.reset();
            if(!worker_mode) name.clear();
            content_length = 0;
            priority = 0;
            required_worker.clear();
            no_response = false;
            type = RequestType::none;
            if(status != Status::worker_wait_result) {
                if(worker_mode) {
                    if(status != Status::worker_mode_async) THROW("Wrong status for worker");
                } else {
                    fail_on_disconnect = false;
                    if(client) client->unlink();
                    client = NULL;
                    noid = false;
                }
            } else {
                if(!noid) THROW("noid is false");
            }
            if(this->read_method(line) != 0) {
                if(server->log & 2) std::cout << ltime() << "Wrong http header\n";
                this->close();
                return;
            }
            http_step = HTTP_HEADER;
        } else if(http_step == HTTP_HEADER) {
            try {
                this->read_header(line);
            } catch (const error::InvalidData &e) {
                this->send.status("400 Invalid data")->done(-32700);
            }
        }
    }

    if(http_step == HTTP_REQUEST_COMPLETED) {
        http_step = HTTP_START;
    } else if(http_step == HTTP_READ_BODY) {
    } else if(http_step == HTTP_START || http_step == HTTP_HEADER) {
        buffer.add(data);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r15d
movq %rsi, %r12
movq %rdi, %rbx
cmpl $0x0, 0xf8(%rdi)
je 0x8d1e
callq 0x16511
addl 0xf8(%rbx), %eax
movl %eax, 0xfc(%rbx)
movl 0xcc(%rbx), %eax
testl %eax, %eax
je 0x8d55
cmpl $0x6, %eax
je 0x8d48
cmpl $0x2, %eax
jne 0x8ddb
cmpb $0x0, 0xf1(%rbx)
jne 0x8d55
cmpl $0x6, %eax
jne 0x8ddb
cmpb $0x0, 0xf3(%rbx)
je 0x8ddb
movq $0x0, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
leaq 0x88(%rbx), %rdi
cmpl $0x0, 0x90(%rbx)
movq %rdi, -0x58(%rbp)
je 0x8d91
movq %r12, %rsi
movl %r15d, %edx
callq 0xc0a8
movq 0x88(%rbx), %r12
movl 0x90(%rbx), %r15d
movq %r12, -0x38(%rbp)
movl %r15d, -0x30(%rbp)
cmpl $0x2, 0x78(%rbx)
jne 0x8e5f
movslq 0x7c(%rbx), %r12
leaq 0xd0(%rbx), %r15
movslq 0xd8(%rbx), %rax
subq %rax, %r12
movl -0x30(%rbp), %edx
cmpl %edx, %r12d
jle 0x8e19
movq -0x38(%rbp), %rsi
movq %r15, %rdi
callq 0xc0a8
movl $0x0, 0x90(%rbx)
jmp 0x9217
movq 0x48(%rbx), %rax
testb $0x4, 0x20(%rax)
je 0x91bc
callq 0x16531
testq %rax, %rax
je 0x9164
movq %rax, %r14
movq %rax, %rdi
callq 0x8130
movq 0x151c7(%rip), %rdi     # 0x1dfd0
movq %r14, %rsi
movq %rax, %rdx
callq 0x8350
jmp 0x9182
leaq -0x38(%rbp), %r13
movq %r13, %rdi
movl %r12d, %esi
callq 0xc708
addq %r12, (%r13)
subl %r12d, 0x8(%r13)
movq %r15, %rdi
movq %rax, %rsi
callq 0xc0a8
movl 0xd8(%rbx), %eax
cmpl 0x7c(%rbx), %eax
jne 0x8e55
movq %rbx, %rdi
callq 0x93f0
movl $0x0, 0x78(%rbx)
cmpl $0x0, -0x30(%rbp)
je 0x9217
movq $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xc180
movq %rax, -0x50(%rbp)
movl %edx, -0x48(%rbp)
testq %rax, %rax
je 0x9132
leaq 0x18(%rbx), %rcx
movq %rcx, -0x40(%rbp)
leaq 0x14c(%rbx), %rcx
movq %rcx, -0x60(%rbp)
leaq 0xd0(%rbx), %rcx
movq %rcx, -0x68(%rbp)
movabsq $0x100002400, %r15      # imm = 0x100002400
leaq -0x38(%rbp), %r13
xorl %r12d, %r12d
testl %edx, %edx
jle 0x8edc
movl %edx, %edx
movzbl -0x1(%rax,%rdx), %ecx
cmpq $0x20, %rcx
ja 0x8edc
btq %rcx, %r15
jae 0x8edc
decq %rdx
leaq 0x1(%rdx), %rcx
cmpq $0x1, %rcx
jg 0x8ebc
xorl %edx, %edx
movl %edx, -0x48(%rbp)
movl 0x78(%rbx), %eax
testl %edx, %edx
je 0x8fa7
cmpl $0x1, %eax
je 0x9042
testl %eax, %eax
jne 0x90a3
movl %r12d, 0xd8(%rbx)
movl %r12d, 0xe8(%rbx)
movq %r12, 0xa8(%rbx)
movl %r12d, 0xb0(%rbx)
movq %r12, 0x168(%rbx)
movl %r12d, 0x170(%rbx)
movq %r12, 0x128(%rbx)
movl %r12d, 0x130(%rbx)
movq %r12, 0x138(%rbx)
movl %r12d, 0x140(%rbx)
movl %r12d, 0x160(%rbx)
movq -0x60(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movb 0xf3(%rbx), %al
testb %al, %al
jne 0x8f66
movl $0x0, 0xc0(%rbx)
movl %r12d, 0x7c(%rbx)
movl %r12d, 0xf4(%rbx)
movl %r12d, 0x118(%rbx)
movb $0x0, 0xf2(%rbx)
movl %r12d, 0xc8(%rbx)
movl 0xcc(%rbx), %ecx
cmpl $0x2, %ecx
jne 0x9050
cmpb $0x0, 0xf1(%rbx)
jne 0x9088
jmp 0x928d
cmpl $0x1, %eax
jne 0x9226
movl $0x3, 0x78(%rbx)
movl 0x7c(%rbx), %eax
testl %eax, %eax
je 0x9006
movl -0x30(%rbp), %r14d
cmpl %r14d, %eax
cmovll %eax, %r14d
movq %r13, %rdi
movl %r14d, %esi
callq 0xc708
movslq %r14d, %rcx
addq %rcx, -0x38(%rbp)
subl %ecx, -0x30(%rbp)
movl $0x0, 0xd8(%rbx)
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0xc0a8
movl 0xd8(%rbx), %eax
cmpl 0x7c(%rbx), %eax
jge 0x9006
movl $0x2, 0x78(%rbx)
movl $0x0, 0x90(%rbx)
cmpl $0x3, 0x78(%rbx)
jne 0x9132
movq %rbx, %rdi
callq 0x93f0
cmpl $0x0, -0x30(%rbp)
je 0x9132
cmpl $0x0, 0xcc(%rbx)
jne 0x925c
movl $0x0, 0x78(%rbx)
jmp 0x90a3
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
callq 0xa0de
jmp 0x90a3
testb %al, %al
je 0x905e
cmpl $0x6, %ecx
je 0x9088
jmp 0x92be
movb $0x0, 0xf0(%rbx)
movq 0x120(%rbx), %rdi
testq %rdi, %rdi
je 0x9076
callq 0x898c
movq $0x0, 0x120(%rbx)
movb $0x0, 0xf1(%rbx)
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
callq 0xa034
testl %eax, %eax
jne 0x91df
movl $0x1, 0x78(%rbx)
movq %r13, %rdi
callq 0xc180
movq %rax, -0x50(%rbp)
movl %edx, -0x48(%rbp)
testq %rax, %rax
jne 0x8eb6
jmp 0x9132
movq %rax, %r14
cmpl $0x1, %edx
jne 0x93e8
movq %r14, %rdi
callq 0x8120
movq -0x40(%rbp), %rdi
leaq 0xe02f(%rip), %rsi      # 0x1710b
callq 0x9ee0
movq -0x40(%rbp), %rdi
movl $0xffff8044, %esi       # imm = 0xFFFF8044
callq 0x9f54
callq 0x8450
jmp 0x90a3
movq %rax, %r14
cmpl $0x1, %edx
jne 0x93e8
movq %r14, %rdi
callq 0x8120
movq -0x40(%rbp), %rdi
leaq 0xdff6(%rip), %rsi      # 0x1710b
callq 0x9ee0
movq -0x40(%rbp), %rdi
movl $0xffff8044, %esi       # imm = 0xFFFF8044
callq 0x9f54
callq 0x8450
jmp 0x9022
movl 0x78(%rbx), %eax
cmpl $0x2, %eax
jae 0x914f
movq -0x38(%rbp), %rsi
movl -0x30(%rbp), %edx
movq -0x58(%rbp), %rdi
callq 0xc0a8
jmp 0x9217
cmpl $0x3, %eax
jne 0x9217
movl $0x0, 0x78(%rbx)
jmp 0x9217
movq 0x14e65(%rip), %rax     # 0x1dfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x8470
movq 0x14e47(%rip), %r14     # 0x1dfd0
leaq 0xdf1a(%rip), %rsi      # 0x170aa
movl $0x8, %edx
movq %r14, %rdi
callq 0x8350
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8250
leaq 0xdf04(%rip), %rsi      # 0x170b3
movl $0x35, %edx
movq %rax, %rdi
callq 0x8350
addq $0x88, %rbx
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %edx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc0a8
movq 0x48(%rbx), %rax
testb $0x2, 0x20(%rax)
je 0x9211
callq 0x16531
movq 0x14ddb(%rip), %rdi     # 0x1dfd0
movq %rax, %rsi
callq 0x8300
leaq 0xdf95(%rip), %rsi      # 0x17199
movl $0x12, %edx
movq %rax, %rdi
callq 0x8350
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x30, %edi
callq 0x8170
movq %rax, %rbx
leaq 0xdee2(%rip), %rsi      # 0x1711c
movq %rax, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xc1da
leaq 0x14a20(%rip), %rsi     # 0x1dc70
leaq 0x40b9(%rip), %rdx      # 0xd310
jmp 0x92fb
movl $0x30, %edi
callq 0x8170
movq %rax, %rbx
leaq 0xdebf(%rip), %rsi      # 0x1712f
leaq 0xddda(%rip), %rdx      # 0x17051
leaq 0xded2(%rip), %r8       # 0x17150
movq %rax, %rdi
movl $0x8c, %ecx
callq 0xcd04
jmp 0x92ed
movl $0x30, %edi
callq 0x8170
movq %rax, %rbx
leaq 0xdeea(%rip), %rsi      # 0x1718b
leaq 0xdda9(%rip), %rdx      # 0x17051
leaq 0xdea1(%rip), %r8       # 0x17150
movq %rax, %rdi
movl $0xa7, %ecx
callq 0xcd04
jmp 0x92ed
movl $0x30, %edi
callq 0x8170
movq %rax, %rbx
leaq 0xdea1(%rip), %rsi      # 0x17173
leaq 0xdd78(%rip), %rdx      # 0x17051
leaq 0xde70(%rip), %r8       # 0x17150
movq %rax, %rdi
movl $0x9f, %ecx
callq 0xcd04
leaq 0x14a24(%rip), %rsi     # 0x1dd18
leaq 0x4015(%rip), %rdx      # 0xd310
movq %rbx, %rdi
callq 0x8480
movq %rax, %r14
callq 0x8450
jmp 0x93e8
movq %rax, %r14
callq 0x8450
jmp 0x93e8
movq %rax, %r14
cmpl $0x1, %edx
jne 0x93e8
movq %r14, %rdi
callq 0x8120
movq 0x48(%rbx), %rax
testb $0x4, 0x20(%rax)
je 0x939b
callq 0x16531
movq 0x14c89(%rip), %rdi     # 0x1dfd0
movq %rax, %rsi
callq 0x8300
movq %rax, %r15
leaq 0xdd90(%rip), %rsi      # 0x170e9
movl $0x21, %edx
movq %rax, %rdi
callq 0x8350
movl 0xc(%rbx), %esi
movq %r15, %rdi
callq 0x8490
movq %rax, %r15
leaq 0xe32e(%rip), %rsi      # 0x176a9
movl $0x1, %edx
movq %rax, %rdi
callq 0x8350
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8250
movq %rax, %rdi
callq 0x8160
leaq 0x18(%rbx), %r15
leaq 0xdd65(%rip), %rsi      # 0x1710b
movq %r15, %rdi
callq 0x9ee0
movq %r15, %rdi
movl $0xffff8044, %esi       # imm = 0xFFFF8044
callq 0x9f54
callq 0x8450
jmp 0x8e4e
movq %rax, %r14
callq 0x8450
jmp 0x93e8
movq %rax, %rdi
callq 0xc171
jmp 0x93dd
jmp 0x93dd
jmp 0x93dd
movq %rax, %r14
movq %rbx, %rdi
callq 0x8220
movq %r14, %rdi
callq 0x84a0