// File: /workspace/github_cpp_makefile_star2_O2/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, %r14d
movq %rsi, %r15
movq %rdi, %rbx
cmpl $0x0, 0xf8(%rdi)
je 0xab56
callq 0x16a69
addl 0xf8(%rbx), %eax
movl %eax, 0xfc(%rbx)
movl 0xcc(%rbx), %eax
testl %eax, %eax
je 0xabea
cmpl $0x6, %eax
je 0xabe1
cmpl $0x2, %eax
jne 0xab77
cmpb $0x0, 0xf1(%rbx)
jne 0xabea
movq 0x48(%rbx), %rax
testb $0x4, 0x20(%rax)
je 0xabbe
callq 0x16a89
movq 0x15443(%rip), %rdi     # 0x1ffd0
movq %rax, %rsi
callq 0xa2e0
leaq 0xd50e(%rip), %rsi      # 0x180aa
movq %rax, %rdi
callq 0xa2e0
movq %rax, %rdi
movq %rbx, %rsi
callq 0xa230
leaq 0xd4fd(%rip), %rsi      # 0x180b3
movq %rax, %rdi
callq 0xa2e0
addq $0x88, %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd24c
cmpb $0x0, 0xf3(%rbx)
je 0xab77
leaq 0x88(%rbx), %rdi
cmpl $0x0, 0x90(%rbx)
movq %rdi, -0x60(%rbp)
je 0xac17
movq %r15, %rsi
movl %r14d, %edx
callq 0xd24c
movq 0x88(%rbx), %r15
movl 0x90(%rbx), %r14d
movq %r15, -0x48(%rbp)
movl %r14d, -0x40(%rbp)
cmpl $0x2, 0x78(%rbx)
jne 0xac87
movl 0x7c(%rbx), %esi
leaq 0xd0(%rbx), %r15
subl 0xd8(%rbx), %esi
cmpl %r14d, %esi
jle 0xac4b
leaq -0x48(%rbp), %rsi
movq %r15, %rdi
callq 0xd300
jmp 0xaf27
leaq -0x48(%rbp), %rdi
callq 0xd314
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
movl %edx, 0x8(%rsi)
movq %r15, %rdi
callq 0xd300
movl 0xd8(%rbx), %eax
cmpl 0x7c(%rbx), %eax
jne 0xac7d
movq %rbx, %rdi
callq 0xb128
andl $0x0, 0x78(%rbx)
cmpl $0x0, -0x40(%rbp)
je 0xaf2e
leaq -0x58(%rbp), %r15
andq $0x0, (%r15)
andl $0x0, 0x8(%r15)
leaq 0x18(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x14c(%rbx), %r14
leaq 0xd0(%rbx), %r13
leaq -0x48(%rbp), %r12
movq %r12, %rdi
callq 0xd342
movq %rax, -0x58(%rbp)
movl %edx, -0x50(%rbp)
testq %rax, %rax
je 0xaefe
movq %r15, %rdi
callq 0xd372
cmpl $0x0, -0x50(%rbp)
movl 0x78(%rbx), %eax
je 0xad92
cmpl $0x1, %eax
je 0xadef
testl %eax, %eax
jne 0xacae
andl $0x0, 0xd8(%rbx)
andl $0x0, 0xe8(%rbx)
andq $0x0, 0xa8(%rbx)
andl $0x0, 0xb0(%rbx)
andq $0x0, 0x168(%rbx)
andl $0x0, 0x170(%rbx)
andq $0x0, 0x128(%rbx)
andl $0x0, 0x130(%rbx)
andq $0x0, 0x138(%rbx)
andl $0x0, 0x140(%rbx)
andl $0x0, 0x160(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movb 0xf3(%rbx), %al
testb %al, %al
jne 0xad51
andl $0x0, 0xc0(%rbx)
andl $0x0, 0x7c(%rbx)
andl $0x0, 0xf4(%rbx)
andl $0x0, 0x118(%rbx)
movb $0x0, 0xf2(%rbx)
andl $0x0, 0xc8(%rbx)
movl 0xcc(%rbx), %ecx
cmpl $0x2, %ecx
jne 0xae2e
cmpb $0x0, 0xf1(%rbx)
jne 0xae63
jmp 0xafd2
cmpl $0x1, %eax
jne 0xaf6f
movl $0x3, 0x78(%rbx)
movl 0x7c(%rbx), %eax
testl %eax, %eax
je 0xadff
movl -0x40(%rbp), %esi
cmpl %esi, %eax
cmovll %eax, %esi
movq %r12, %rdi
callq 0xd314
movq %rax, -0x70(%rbp)
movl %edx, -0x68(%rbp)
movq %r13, %rdi
leaq -0x70(%rbp), %rsi
callq 0xd3d0
movl 0xd8(%rbx), %eax
cmpl 0x7c(%rbx), %eax
jl 0xaf20
movl 0x78(%rbx), %eax
andl $0x0, 0x90(%rbx)
cmpl $0x3, %eax
je 0xae06
jmp 0xaf01
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbb12
jmp 0xacae
andl $0x0, 0x90(%rbx)
movq %rbx, %rdi
callq 0xb128
cmpl $0x0, -0x40(%rbp)
je 0xaefe
cmpl $0x0, 0xcc(%rbx)
jne 0xafa3
andl $0x0, 0x78(%rbx)
jmp 0xacae
testb %al, %al
je 0xae3c
cmpl $0x6, %ecx
je 0xae63
jmp 0xb001
movb $0x0, 0xf0(%rbx)
movq 0x120(%rbx), %rdi
testq %rdi, %rdi
je 0xae54
callq 0xa84c
andq $0x0, 0x120(%rbx)
movb $0x0, 0xf1(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xba6a
testl %eax, %eax
jne 0xaf3d
movl $0x1, 0x78(%rbx)
jmp 0xacae
movq %rax, -0x30(%rbp)
cmpl $0x1, %edx
jne 0xb11f
movq -0x30(%rbp), %rdi
callq 0xa110
movq -0x38(%rbp), %rdi
leaq 0xd268(%rip), %rsi      # 0x1810b
callq 0xb93e
movq -0x38(%rbp), %rdi
movl $0xffff8044, %esi       # imm = 0xFFFF8044
callq 0xb9b2
callq 0xa430
jmp 0xacae
movq %rax, -0x30(%rbp)
cmpl $0x1, %edx
jne 0xb11f
movq -0x30(%rbp), %rdi
callq 0xa110
movq -0x38(%rbp), %rdi
leaq 0xd22a(%rip), %rsi      # 0x1810b
callq 0xb93e
movq -0x38(%rbp), %rdi
movl $0xffff8044, %esi       # imm = 0xFFFF8044
callq 0xb9b2
callq 0xa430
jmp 0xae0e
movl 0x78(%rbx), %eax
cmpl $0x2, %eax
jae 0xaf15
leaq -0x48(%rbp), %rsi
movq -0x60(%rbp), %rdi
callq 0xd300
jmp 0xaf2e
cmpl $0x3, %eax
jne 0xaf2e
andl $0x0, 0x78(%rbx)
jmp 0xaf2e
movl $0x2, 0x78(%rbx)
andl $0x0, 0x90(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%rbx), %rax
testb $0x2, 0x20(%rax)
je 0xaf6a
callq 0x16a89
movq 0x1507d(%rip), %rdi     # 0x1ffd0
movq %rax, %rsi
callq 0xa2e0
leaq 0xd237(%rip), %rsi      # 0x18199
movq %rax, %rdi
callq 0xa2e0
orl $-0x1, (%rbx)
jmp 0xaf2e
pushq $0x30
popq %rdi
callq 0xa170
movq %rax, %rbx
leaq 0xd19b(%rip), %rsi      # 0x1811c
movq %rax, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xd3b0
leaq 0x14cd9(%rip), %rsi     # 0x1fc70
leaq 0x3578(%rip), %rdx      # 0xe516
jmp 0xb03c
pushq $0x30
popq %rdi
callq 0xa170
movq %rax, %rbx
leaq 0xd17a(%rip), %rsi      # 0x1812f
leaq 0xd095(%rip), %rdx      # 0x18051
leaq 0xd18d(%rip), %r8       # 0x18150
movq %rax, %rdi
movl $0x8c, %ecx
callq 0xe15c
jmp 0xb02e
pushq $0x30
popq %rdi
callq 0xa170
movq %rax, %rbx
leaq 0xd1a7(%rip), %rsi      # 0x1818b
leaq 0xd066(%rip), %rdx      # 0x18051
leaq 0xd15e(%rip), %r8       # 0x18150
movq %rax, %rdi
movl $0xa7, %ecx
callq 0xe15c
jmp 0xb02e
pushq $0x30
popq %rdi
callq 0xa170
movq %rax, %rbx
leaq 0xd160(%rip), %rsi      # 0x18173
leaq 0xd037(%rip), %rdx      # 0x18051
leaq 0xd12f(%rip), %r8       # 0x18150
movq %rax, %rdi
movl $0x9f, %ecx
callq 0xe15c
leaq 0x14ce3(%rip), %rsi     # 0x1fd18
leaq 0x34da(%rip), %rdx      # 0xe516
movq %rbx, %rdi
callq 0xa450
movq %rax, -0x30(%rbp)
callq 0xa430
jmp 0xb11f
movq %rax, -0x30(%rbp)
callq 0xa430
jmp 0xb11f
movq %rax, -0x30(%rbp)
cmpl $0x1, %edx
jne 0xb11f
movq -0x30(%rbp), %rdi
callq 0xa110
movq 0x48(%rbx), %rax
testb $0x4, 0x20(%rax)
je 0xb0d0
callq 0x16a89
movq 0x14f44(%rip), %rdi     # 0x1ffd0
movq %rax, %rsi
callq 0xa2e0
leaq 0xd04e(%rip), %rsi      # 0x180e9
movq %rax, %rdi
callq 0xa2e0
movl 0xc(%rbx), %esi
movq %rax, %rdi
callq 0xa460
leaq 0xd5f7(%rip), %rsi      # 0x186ac
movq %rax, %rdi
callq 0xa2e0
movq %rax, %rdi
movq %rbx, %rsi
callq 0xa230
movq %rax, %rdi
callq 0xa160
leaq 0x18(%rbx), %r14
leaq 0xd030(%rip), %rsi      # 0x1810b
movq %r14, %rdi
callq 0xb93e
movq %r14, %rdi
movl $0xffff8044, %esi       # imm = 0xFFFF8044
callq 0xb9b2
callq 0xa430
jmp 0xac79
movq %rax, -0x30(%rbp)
callq 0xa430
jmp 0xb11f
movq %rax, %rdi
callq 0xd334
jmp 0xb113
jmp 0xb113
jmp 0xb113
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0xa200
movq -0x30(%rbp), %rdi
callq 0xa470