// File: /workspace/github_cpp_makefile_star2_O2/billDrett[P]Bulletin-Boards/boardServer.cpp
// Function: BoardServer::readFromBp2S()
void BoardServer::readFromBp2S() //diavasma apo pipe boardPost to server
{
    char buffer[BUFFERSIZE];
    char* tmp;
    int nread;
    string tmpTag;
    int state;
    void (BoardServer::*f)(char* buffer, int nread, int state, string& previousRead);

    while((nread = read(pipeBoardPost2Server, buffer + tmpTag.size(), BUFFERSIZE - tmpTag.size())) > 0) //an exw lavei meros ena tag entolis tote ksanadiavazw gia na parw to ypoleipo
    {
        strncpy(buffer, tmpTag.c_str(), tmpTag.size());
        nread += tmpTag.size();
        tmp = buffer;
        tmpTag = "";
        while(1) //se ena read mporei na exw panw apo mia entoli gia auto mpainei se loop while 1 pou termatizetai otan dn yparxoun alloi xaraktires gia epeksergasia 'h parw meros tag
        {
            if(nread == 0)return;

            strncpy(buffer, tmpTag.c_str(), tmpTag.size());
            tmpTag = "";
            state = this->nextState(tmp, nread, "<Chanels>", "<Message>", "<File>", tmpTag) -1; //ta states ksekinan apo 0 oxi apo 1

            if(state == -2) //exei kopei entoli sthn mesh ara na ksanadiavasw
            {
                if(tmpTag.size() == 0) return;
                break;
            }
            else if(state==chanelist)
            {
                tmp = getAfterTag(tmp, "<Chanels>", nread);
                if(pipeServer2BoardPost < 0) //an dn to exw anoiskei hdh to anoigw
                {
                    if((pipeServer2BoardPost = open(Server2BoardPost.c_str(), O_WRONLY)) < 0)
                    {
                        perror("fifo S2BP not found");
                        exit(1);
                    }
                }
                this->sendChanelsList();

            }
            else if(state == message)
            {
                f = &BoardServer::parseGetMessage;
                this->parseCommandPrototype(tmp, nread, "<Message>", f, pipeBoardPost2Server);
            }
            else //file
            {
                f = &BoardServer::parseGetFiles;
                this->parseCommandPrototype(tmp, nread, "<File>", f, pipeBoardPost2Server);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
movq %rdi, %rbx
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x108(%rbp), %r15
xorl %eax, %eax
movq %rdi, -0x48(%rbp)
movl 0x8(%rbx), %edi
leaq (%rax,%rbp), %rsi
addq $-0x510, %rsi           # imm = 0xFAF0
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
callq 0x2300
movq %rax, %r12
movl %r12d, -0x30(%rbp)
testl %r12d, %r12d
jle 0x4989
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %r13
leaq -0x510(%rbp), %rdi
movq %r13, %rdx
callq 0x2180
addl %r12d, %r13d
movl %r13d, -0x30(%rbp)
leaq -0x68(%rbp), %rdi
leaq 0x2a57(%rip), %rsi      # 0x721b
callq 0x23d0
leaq -0x510(%rbp), %r12
movq %r12, -0x40(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x4989
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x510(%rbp), %rdi
callq 0x2180
leaq -0x68(%rbp), %rdi
leaq 0x2a1e(%rip), %rsi      # 0x721b
callq 0x23d0
movl -0x30(%rbp), %r13d
leaq -0x88(%rbp), %rdi
leaq 0x2a30(%rip), %rsi      # 0x7244
leaq -0x29(%rbp), %rdx
callq 0x529a
leaq -0xe8(%rbp), %rbx
movq %r15, %rdi
leaq 0x28e1(%rip), %rsi      # 0x710f
leaq -0x32(%rbp), %rdx
callq 0x529a
movq %rbx, %rdi
leaq 0x2909(%rip), %rsi      # 0x714a
leaq -0x31(%rbp), %rdx
callq 0x529a
movq %rbx, %r12
leaq -0x68(%rbp), %rax
movq %rax, (%rsp)
movq -0x40(%rbp), %rsi
movl %r13d, %edx
leaq -0x88(%rbp), %r14
movq %r14, %rcx
movq %r15, %rbx
movq %r15, %r8
movq %r12, %r9
callq 0x4a22
movl %eax, %r13d
movq %r12, %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x2130
movq %r14, %rdi
callq 0x2130
cmpl $0x2, %r13d
je 0x48e9
cmpl $0x1, %r13d
leaq -0xa8(%rbp), %rbx
je 0x4934
cmpl $-0x1, %r13d
je 0x4978
movq %rbx, %rdi
leaq 0x2890(%rip), %rsi      # 0x714a
leaq -0x29(%rbp), %rdx
callq 0x529a
movq -0x48(%rbp), %rdi
movl 0x8(%rdi), %eax
movl %eax, (%rsp)
movq -0x40(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
leaq 0x74f(%rip), %r8        # 0x502e
xorl %r9d, %r9d
callq 0x4c24
jmp 0x4927
leaq -0xc8(%rbp), %rbx
movq %rbx, %rdi
leaq 0x2815(%rip), %rsi      # 0x710f
leaq -0x29(%rbp), %rdx
callq 0x529a
movq -0x48(%rbp), %rdi
movl 0x8(%rdi), %eax
movl %eax, (%rsp)
movq -0x40(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rcx
leaq 0x603(%rip), %r8        # 0x4f22
xorl %r9d, %r9d
callq 0x4c24
movq %rbx, %rdi
callq 0x2130
jmp 0x47d4
movq -0x40(%rbp), %rdi
leaq 0x2905(%rip), %rsi      # 0x7244
leaq -0x30(%rbp), %rdx
callq 0x5421
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rbx
cmpl $0x0, 0xc(%rbx)
jns 0x496b
movq 0x10(%rbx), %rdi
pushq $0x1
popq %rsi
xorl %eax, %eax
callq 0x21c0
movl %eax, 0xc(%rbx)
testl %eax, %eax
js 0x49a4
movq %rbx, %rdi
callq 0x3e18
jmp 0x47d4
movq -0x60(%rbp), %rax
testq %rax, %rax
movq -0x48(%rbp), %rbx
jne 0x4770
leaq -0x68(%rbp), %rdi
callq 0x2130
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28a3(%rip), %rdi      # 0x724e
callq 0x21e0
pushq $0x1
popq %rdi
callq 0x2290
jmp 0x4a0d
jmp 0x4a0d
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
jmp 0x4a06
jmp 0x4a0d
jmp 0x4a0d
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
jmp 0x4a06
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x2130
jmp 0x49f3
movq %rax, %rbx
jmp 0x49ff
jmp 0x4a0d
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x2130
leaq -0x88(%rbp), %rdi
callq 0x2130
jmp 0x4a10
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x2390
nop