// File: /workspace/github_cpp_makefile_star2_O2/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 $0x438, %rsp            # imm = 0x438
movq %rsi, %rbx
movq %rdi, %r14
movl 0x4(%rdi), %edi
leaq 0x2fda(%rip), %rsi      # 0x714a
pushq $0x6
popq %rdx
callq 0x20e0
cmpl $-0x1, %eax
je 0x4339
movq %rbx, -0x38(%rbp)
movq %rbx, %rdi
callq 0x65c0
movq %rax, %r12
leaq -0x58(%rbp), %r13
leaq -0x460(%rbp), %rbx
testq %r12, %r12
je 0x42ba
movq %r13, %rdi
leaq 0x2fa3(%rip), %rsi      # 0x7151
leaq -0x29(%rbp), %rdx
callq 0x529a
movq %r12, %rdi
callq 0x634e
movq (%rax), %rdi
xorl %esi, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x21c0
movl %eax, %r15d
movq %r12, %rdi
callq 0x634e
movq %r13, %rdi
movq %rax, %rsi
callq 0x23e0
movq %r13, %rdi
leaq 0x2f2e(%rip), %rsi      # 0x711e
callq 0x23c0
movl 0x4(%r14), %edi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x20e0
cmpl $-0x1, %eax
je 0x429b
movl 0x4(%r14), %edi
leaq 0x2ee5(%rip), %rsi      # 0x70ff
pushq $0x7
popq %rdx
callq 0x20e0
cmpl $-0x1, %eax
je 0x4255
movl $0x400, %edx            # imm = 0x400
movl %r15d, %edi
movq %rbx, %rsi
callq 0x2300
testl %eax, %eax
jle 0x4263
movl 0x4(%r14), %edi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rbx, %rsi
movq %rax, %rdx
callq 0x20e0
cmpq $-0x1, %rax
jne 0x4227
leaq 0x2fc0(%rip), %rdi      # 0x721c
callq 0x21e0
jmp 0x4227
movl %r15d, %edi
callq 0x23f0
movl 0x4(%r14), %edi
leaq 0x2fc8(%rip), %rsi      # 0x723e
pushq $0x5
popq %rdx
callq 0x20e0
cmpl $-0x1, %eax
je 0x42ac
movq %r13, %rdi
callq 0x2130
movq %r12, %rdi
callq 0x6344
movq %rax, %r12
jmp 0x419b
leaq 0x2f7a(%rip), %rdi      # 0x721c
callq 0x21e0
jmp 0x420f
leaq 0x2f69(%rip), %rdi      # 0x721c
callq 0x21e0
jmp 0x4283
movq -0x38(%rbp), %rdi
callq 0x65c0
testq %rax, %rax
jne 0x42fb
leaq 0x2f64(%rip), %rsi      # 0x7233
leaq -0x58(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x529a
movl 0x4(%r14), %edi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x20e0
cmpl $-0x1, %eax
je 0x4358
leaq -0x58(%rbp), %rdi
callq 0x2130
movl 0x4(%r14), %edi
leaq 0x2e44(%rip), %rsi      # 0x714a
pushq $0x6
popq %rdx
callq 0x20e0
cmpl $-0x1, %eax
je 0x434a
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x6528
movq %rbx, %rdi
callq 0x6536
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2edc(%rip), %rdi      # 0x721c
callq 0x21e0
jmp 0x4181
leaq 0x2ecb(%rip), %rdi      # 0x721c
callq 0x21e0
jmp 0x4313
leaq 0x2ebd(%rip), %rdi      # 0x721c
callq 0x21e0
jmp 0x42f2
jmp 0x4371
jmp 0x436a
movq %rax, %rbx
jmp 0x437d
jmp 0x4371
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x2390
nop