// File: lega911[P]ijson/src/connect.cpp
// Function: Connect::pub(ISlice&)
void Connect::pub(ISlice &name) {
    QueueLine *ql = server->get_queue(name);
    if(!ql) {
        if(server->log & 4) std::cout << ltime() << "404 no method " << name.as_string() << std::endl;
        this->send.status("404 Not Found")->done(-32601);
        return;
    }

    auto *dm = new DirectMessage();
    dm->link();
    Buffer *data = &dm->data;
    data->add("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nName: ");
    data->add(name);
    data->add("\r\nAsync: true\r\n");
    if(body.size() == 0) {
        data->add("Content-Length: 0\r\n\r\n");
    } else {
        data->add("Content-Length: ");
        data->add_number(body.size());
        data->add("\r\n\r\n");
        data->add(body);
    };

    LOCK _l(ql->workers.lock);
    auto *item = ql->workers.head;
    for(;item;item=item->next) {
        auto *worker = item->conn;

        bool send = false;
        if(worker->status == Status::worker_wait_job) {
            worker->mutex.lock();
            if(worker->status == Status::worker_wait_job) {
                worker->status = Status::busy;
                send = true;
            }
            worker->mutex.unlock();
        };

        if(send) {
            if(worker->worker_mode) worker->status = Status::worker_mode_async;
            else worker->status = Status::net;

            dm->link();
            worker->direct_message.push_back(dm);
            worker->write_mode(true);
        } else if(worker->noid) {
            dm->link();
            worker->direct_message.push_back(dm);
        }
    }
    this->send.status("200 OK")->done(1);
    if(dm->unlink() == 0) delete dm;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rsi
movl -0x20(%rbp), %edx
xorl %ecx, %ecx
callq 0x281f0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1c39e
movq -0x90(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x20(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1c375
callq 0x36960
movq %rax, %rsi
movq 0x2ace5(%rip), %rdi     # 0x46fd0
callq 0x192e0
movq %rax, %rdi
leaq 0x1c3ac(%rip), %rsi     # 0x386a6
callq 0x192e0
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f340
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x19290
movq %rax, -0x98(%rbp)
jmp 0x1c33b
movq -0x98(%rbp), %rdi
movq 0x2ac67(%rip), %rsi     # 0x46fb0
callq 0x19320
jmp 0x1c350
leaq -0x48(%rbp), %rdi
callq 0x191e0
jmp 0x1c375
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x191e0
jmp 0x1c6a2
movq -0x90(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1c32e(%rip), %rsi     # 0x386b5
callq 0x1b6d0
movq %rax, %rdi
movl $0xffff80a7, %esi       # imm = 0xFFFF80A7
callq 0x1b770
jmp 0x1c699
movl $0x40, %edi
callq 0x27250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
callq 0x1f9d0
jmp 0x1c3bc
movq -0xb0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x1fa20
movq -0x60(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
leaq 0x1c2dc(%rip), %rsi     # 0x386c3
callq 0x1f2c0
movq -0x68(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1ea60
movq -0x68(%rbp), %rdi
leaq 0x1c2ef(%rip), %rsi     # 0x386f3
callq 0x1f2c0
movq -0x90(%rbp), %rdi
addq $0xd0, %rdi
callq 0x1e6d0
cmpl $0x0, %eax
jne 0x1c458
movq -0x68(%rbp), %rdi
leaq 0x1c2d7(%rip), %rsi     # 0x38703
callq 0x1f2c0
jmp 0x1c4bc
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x40, %esi
callq 0x19300
jmp 0x1c6a2
movq -0x68(%rbp), %rdi
leaq 0x1c2b6(%rip), %rsi     # 0x38719
callq 0x1f2c0
movq -0x90(%rbp), %rdi
movq -0x68(%rbp), %rax
movq %rax, -0xb8(%rbp)
addq $0xd0, %rdi
callq 0x1e6d0
movq -0xb8(%rbp), %rdi
movslq %eax, %rsi
callq 0x1f1d0
movq -0x68(%rbp), %rdi
leaq 0x1c274(%rip), %rsi     # 0x38714
callq 0x1f2c0
movq -0x90(%rbp), %rsi
movq -0x68(%rbp), %rdi
addq $0xd0, %rsi
callq 0x1ea60
movq -0x18(%rbp), %rsi
addq $0x58, %rsi
leaq -0x70(%rbp), %rdi
callq 0x1f5d0
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x1c611
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x80(%rbp)
movb $0x0, -0x81(%rbp)
movq -0x80(%rbp), %rax
cmpl $0x1, 0xcc(%rax)
jne 0x1c565
movq -0x80(%rbp), %rdi
addq $0x50, %rdi
callq 0x1fa50
jmp 0x1c516
movq -0x80(%rbp), %rax
cmpl $0x1, 0xcc(%rax)
jne 0x1c554
movq -0x80(%rbp), %rax
movl $0x5, 0xcc(%rax)
movb $0x1, -0x81(%rbp)
jmp 0x1c554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x1f880
jmp 0x1c6a2
movq -0x80(%rbp), %rdi
addq $0x50, %rdi
callq 0x1fa80
jmp 0x1c563
jmp 0x1c565
testb $0x1, -0x81(%rbp)
je 0x1c5cc
movq -0x80(%rbp), %rax
testb $0x1, 0xf3(%rax)
je 0x1c58b
movq -0x80(%rbp), %rax
movl $0x6, 0xcc(%rax)
jmp 0x1c599
movq -0x80(%rbp), %rax
movl $0x0, 0xcc(%rax)
movq -0x60(%rbp), %rdi
callq 0x1fa20
jmp 0x1c5a4
movq -0x80(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
leaq -0x60(%rbp), %rsi
callq 0x1faa0
jmp 0x1c5ba
movq -0x80(%rbp), %rdi
movl $0x1, %esi
callq 0x19a10
jmp 0x1c5ca
jmp 0x1c5fe
movq -0x80(%rbp), %rax
testb $0x1, 0xf1(%rax)
je 0x1c5fc
movq -0x60(%rbp), %rdi
callq 0x1fa20
jmp 0x1c5e4
movq -0x80(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
leaq -0x60(%rbp), %rsi
callq 0x1faa0
jmp 0x1c5fa
jmp 0x1c5fc
jmp 0x1c5fe
jmp 0x1c600
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x1c4dc
movq -0x90(%rbp), %rdi
addq $0x18, %rdi
leaq 0x1bc0e(%rip), %rsi     # 0x38231
callq 0x1b6d0
movq %rax, -0xc0(%rbp)
jmp 0x1c631
movq -0xc0(%rbp), %rdi
movl $0x1, %esi
callq 0x1b770
jmp 0x1c644
movq -0x60(%rbp), %rdi
callq 0x1fb00
movl %eax, -0xc4(%rbp)
jmp 0x1c655
movl -0xc4(%rbp), %eax
cmpl $0x0, %eax
jne 0x1c690
movq -0x60(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
je 0x1c68e
movq -0xd0(%rbp), %rdi
callq 0x1fb20
movq -0xd0(%rbp), %rdi
movl $0x40, %esi
callq 0x19300
jmp 0x1c690
leaq -0x70(%rbp), %rdi
callq 0x1f880
addq $0xd0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x194a0
nopl (%rax,%rax)