// File: /workspace/github_cpp_makefile_star2_O1/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 0x3294(%rip), %rsi      # 0x814e
movl $0x6, %edx
callq 0x20f0
cmpl $-0x1, %eax
je 0x50c7
movq %rbx, -0x50(%rbp)
movq %rbx, %rdi
callq 0x7880
testq %rax, %rax
je 0x5030
movq %rax, %r15
leaq -0x48(%rbp), %rbx
leaq -0x450(%rbp), %r12
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq %rbx, %rdi
leaq 0x3253(%rip), %rsi      # 0x8155
leaq 0x324e(%rip), %rdx      # 0x8157
callq 0x64f8
movq %r15, %rdi
callq 0x7544
movq (%rax), %rdi
xorl %esi, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x21b0
movl %eax, %r13d
movq %r15, %rdi
callq 0x7544
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq 0x20d0
movq %rbx, %rdi
leaq 0x31d7(%rip), %rsi      # 0x8122
callq 0x23f0
movl 0x4(%r14), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x20f0
cmpl $-0x1, %eax
je 0x5011
movl 0x4(%r14), %edi
movl $0x7, %edx
leaq 0x3189(%rip), %rsi      # 0x8103
callq 0x20f0
cmpl $-0x1, %eax
je 0x4fb2
movl $0x400, %edx            # imm = 0x400
movl %r13d, %edi
movq %r12, %rsi
callq 0x2300
testl %eax, %eax
jle 0x4fc0
movl 0x4(%r14), %edi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r12, %rsi
movq %rax, %rdx
callq 0x20f0
cmpq $-0x1, %rax
jne 0x4f84
leaq 0x3267(%rip), %rdi      # 0x8220
callq 0x21d0
jmp 0x4f84
movl %r13d, %edi
callq 0x2400
movl 0x4(%r14), %edi
movl $0x5, %edx
leaq 0x326a(%rip), %rsi      # 0x8242
callq 0x20f0
cmpl $-0x1, %eax
je 0x5022
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x4ffb
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
movq %r15, %rdi
callq 0x753a
movq %rax, %r15
testq %rax, %rax
jne 0x4ef0
jmp 0x5030
leaq 0x3208(%rip), %rdi      # 0x8220
callq 0x21d0
jmp 0x4f6a
leaq 0x31f7(%rip), %rdi      # 0x8220
callq 0x21d0
jmp 0x4fe2
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x7880
testq %rax, %rax
jne 0x508b
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x31e7(%rip), %rsi      # 0x8237
leaq 0x31f0(%rip), %rdx      # 0x8247
leaq -0x48(%rbp), %rdi
callq 0x64f8
movl 0x4(%r14), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x20f0
cmpl $-0x1, %eax
je 0x50e6
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x508b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
movl 0x4(%r14), %edi
leaq 0x30b8(%rip), %rsi      # 0x814e
movl $0x6, %edx
callq 0x20f0
cmpl $-0x1, %eax
je 0x50d8
movq %rbx, %rdi
callq 0x77b0
movq %rbx, %rdi
callq 0x77be
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3152(%rip), %rdi      # 0x8220
callq 0x21d0
jmp 0x4ecd
leaq 0x3141(%rip), %rdi      # 0x8220
callq 0x21d0
jmp 0x50a5
leaq 0x3133(%rip), %rdi      # 0x8220
callq 0x21d0
jmp 0x5076
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x511b
jmp 0x5127
jmp 0x5104
movq %rax, %rbx
jmp 0x5127
jmp 0x510b
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5127
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0
nop