// File: /workspace/github_cpp_makefile_star2_O3/billDrett[P]Bulletin-Boards/boardServer.cpp
// Function: BoardServer::sendFiles(Chanel*)
void BoardServer::sendFiles(Chanel* chanelId)
{
    char buff[BUFFERSIZE];
    int file;
    int nread, nwrite;

    if((nwrite = write(pipeServer2Client, "<File>", 6))== -1) //arxh files
    {
        perror("Cant write to pipe S2C");
    }

    for(Node<string>* i = chanelId->get_filesList(); i!= NULL; i = i->get_next()) //pairnw ola ta arxeia
    {
        string tmp ="<:";
        file=open(i->get_data()->c_str(), O_RDONLY, 0644);
        tmp.append(*(i->get_data()));
        tmp.append(">");
        if((nwrite = write(pipeServer2Client, tmp.c_str(), tmp.size()))== -1) //stelnw to onoma tou arxeiou mesa se <: >
        {
            perror("Cant write to pipe S2C");
        }

        if((nwrite = write(pipeServer2Client, "<start>", 7))== -1) //arxh dedomenwn arxeiou
        {
            perror("Cant write to pipe S2C");
        }

        while((nread = read(file, buff, BUFFERSIZE)) > 0) //grafw to arxeio
        {
            if(write(pipeServer2Client, buff, nread) == -1)
            {
                perror("Cant write to pipe S2C");
            }
        }
        close(file);

        if((nwrite = write(pipeServer2Client, "<end>", 5))== -1) //telos
        {
            perror("Cant write to pipe S2C");
        }
    }

    if(chanelId->get_filesList() == NULL) //SYMVASH ama dn yparxoun arxeia gia na steilei stelnei keno
    {
        string tmp = "<: ><start><end>";
        if((nwrite = write(pipeServer2Client, tmp.c_str(), tmp.size()))== -1)
        {
            perror("Cant write to pipe S2C");
        }
    }

    if((nwrite = write(pipeServer2Client, "<File>", 6))== -1)
    {
        perror("Cant write to pipe S2C");
    }

    chanelId->removeAllMessages(); //afairoume ta messages
    chanelId->removeAllFiles(); //kai ta arxeia apo ton server

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rsi, %rbx
movq %rdi, %r14
movl 0x4(%rdi), %edi
leaq 0x32a0(%rip), %rsi      # 0x8162
movl $0x6, %edx
callq 0x20f0
cmpl $-0x1, %eax
je 0x50cf
movq %rbx, -0x50(%rbp)
movq %rbx, %rdi
callq 0x7900
testq %rax, %rax
je 0x5038
movq %rax, %r15
leaq -0x48(%rbp), %rbx
leaq -0x450(%rbp), %r12
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %rbx, %rdi
leaq 0x325f(%rip), %rsi      # 0x8169
leaq 0x325a(%rip), %rdx      # 0x816b
callq 0x651a
movq %r15, %rdi
callq 0x75c4
movq (%rax), %rdi
xorl %esi, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x21b0
movl %eax, %r13d
movq %r15, %rdi
callq 0x75c4
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x20d0
movq %rbx, %rdi
leaq 0x31e3(%rip), %rsi      # 0x8136
callq 0x23f0
movl 0x4(%r14), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x20f0
cmpl $-0x1, %eax
je 0x5019
movl 0x4(%r14), %edi
movl $0x7, %edx
leaq 0x3195(%rip), %rsi      # 0x8117
callq 0x20f0
cmpl $-0x1, %eax
je 0x4fba
movl $0x400, %edx            # imm = 0x400
movl %r13d, %edi
movq %r12, %rsi
callq 0x2300
testl %eax, %eax
jle 0x4fc8
movl 0x4(%r14), %edi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r12, %rsi
movq %rax, %rdx
callq 0x20f0
cmpq $-0x1, %rax
jne 0x4f8c
leaq 0x3273(%rip), %rdi      # 0x8234
callq 0x21d0
jmp 0x4f8c
movl %r13d, %edi
callq 0x2400
movl 0x4(%r14), %edi
movl $0x5, %edx
leaq 0x3276(%rip), %rsi      # 0x8256
callq 0x20f0
cmpl $-0x1, %eax
je 0x502a
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5003
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
movq %r15, %rdi
callq 0x75ba
movq %rax, %r15
testq %rax, %rax
jne 0x4ef8
jmp 0x5038
leaq 0x3214(%rip), %rdi      # 0x8234
callq 0x21d0
jmp 0x4f72
leaq 0x3203(%rip), %rdi      # 0x8234
callq 0x21d0
jmp 0x4fea
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x7900
testq %rax, %rax
jne 0x5093
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x31f3(%rip), %rsi      # 0x824b
leaq 0x31fc(%rip), %rdx      # 0x825b
leaq -0x48(%rbp), %rdi
callq 0x651a
movl 0x4(%r14), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x20f0
cmpl $-0x1, %eax
je 0x50ee
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x5093
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
movl 0x4(%r14), %edi
leaq 0x30c4(%rip), %rsi      # 0x8162
movl $0x6, %edx
callq 0x20f0
cmpl $-0x1, %eax
je 0x50e0
movq %rbx, %rdi
callq 0x7830
movq %rbx, %rdi
callq 0x783e
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x315e(%rip), %rdi      # 0x8234
callq 0x21d0
jmp 0x4ed5
leaq 0x314d(%rip), %rdi      # 0x8234
callq 0x21d0
jmp 0x50ad
leaq 0x313f(%rip), %rdi      # 0x8234
callq 0x21d0
jmp 0x507e
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x5123
jmp 0x512f
jmp 0x510c
movq %rax, %rbx
jmp 0x512f
jmp 0x5113
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x512f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0
nop