// File: 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
subq $0x520, %rsp            # imm = 0x520
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x490(%rbp)
movl 0x4(%rax), %edi
leaq 0x4bec(%rip), %rsi      # 0xb124
movl $0x6, %edx
callq 0x3110
movl %eax, -0x41c(%rbp)
cmpl $-0x1, %eax
jne 0x6559
leaq 0x4ca2(%rip), %rdi      # 0xb1f6
callq 0x3260
movq -0x10(%rbp), %rdi
callq 0xae10
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
je 0x682a
leaq -0x449(%rbp), %rdi
movq %rdi, -0x498(%rbp)
callq 0x34c0
movq -0x498(%rbp), %rdx
leaq 0x4b93(%rip), %rsi      # 0xb12b
leaq -0x448(%rbp), %rdi
callq 0x88a0
jmp 0x65a6
leaq -0x449(%rbp), %rdi
callq 0x3320
movq -0x428(%rbp), %rdi
callq 0xa990
movq %rax, -0x4a0(%rbp)
jmp 0x65c7
movq -0x4a0(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
xorl %esi, %esi
movb %sil, %al
movl $0x1a4, %edx            # imm = 0x1A4
callq 0x3230
movl %eax, -0x4a4(%rbp)
jmp 0x65ed
movl -0x4a4(%rbp), %eax
movl %eax, -0x414(%rbp)
movq -0x428(%rbp), %rdi
callq 0xa990
movq %rax, -0x4b0(%rbp)
jmp 0x660e
movq -0x4b0(%rbp), %rsi
leaq -0x448(%rbp), %rdi
callq 0x3510
jmp 0x6623
leaq 0x4ace(%rip), %rsi      # 0xb0f8
leaq -0x448(%rbp), %rdi
callq 0x3500
jmp 0x6638
movq -0x490(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x4c4(%rbp)
leaq -0x448(%rbp), %rdi
movq %rdi, -0x4d0(%rbp)
callq 0x3130
movq -0x4d0(%rbp), %rdi
movq %rax, -0x4c0(%rbp)
callq 0x3210
movl -0x4c4(%rbp), %edi
movq -0x4c0(%rbp), %rsi
movq %rax, %rdx
callq 0x3110
movq %rax, -0x4b8(%rbp)
jmp 0x668c
movq -0x4b8(%rbp), %rax
movl %eax, -0x41c(%rbp)
cmpl $-0x1, %eax
jne 0x66f4
leaq 0x4b51(%rip), %rdi      # 0xb1f6
callq 0x3260
jmp 0x66ac
jmp 0x66f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x458(%rbp)
movl %eax, -0x45c(%rbp)
leaq -0x449(%rbp), %rdi
callq 0x3320
jmp 0x6987
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x458(%rbp)
movl %eax, -0x45c(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x31f0
jmp 0x6987
movq -0x490(%rbp), %rax
movl 0x4(%rax), %edi
leaq 0x49d4(%rip), %rsi      # 0xb0d9
movl $0x7, %edx
callq 0x3110
movq %rax, -0x4d8(%rbp)
jmp 0x6718
movq -0x4d8(%rbp), %rax
movl %eax, -0x41c(%rbp)
cmpl $-0x1, %eax
jne 0x673a
leaq 0x4ac5(%rip), %rdi      # 0xb1f6
callq 0x3260
jmp 0x6738
jmp 0x673a
jmp 0x673c
movl -0x414(%rbp), %edi
leaq -0x410(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x3400
movq %rax, -0x4e0(%rbp)
jmp 0x675c
movq -0x4e0(%rbp), %rax
movl %eax, -0x418(%rbp)
cmpl $0x0, %eax
jle 0x67b3
movq -0x490(%rbp), %rax
movl 0x4(%rax), %edi
movslq -0x418(%rbp), %rdx
leaq -0x410(%rbp), %rsi
callq 0x3110
movq %rax, -0x4e8(%rbp)
jmp 0x6794
movq -0x4e8(%rbp), %rax
cmpq $-0x1, %rax
jne 0x67b1
leaq 0x4a4e(%rip), %rdi      # 0xb1f6
callq 0x3260
jmp 0x67af
jmp 0x67b1
jmp 0x673c
movl -0x414(%rbp), %edi
callq 0x3520
jmp 0x67c0
movq -0x490(%rbp), %rax
movl 0x4(%rax), %edi
leaq 0x4a47(%rip), %rsi      # 0xb218
movl $0x5, %edx
callq 0x3110
movq %rax, -0x4f0(%rbp)
jmp 0x67e4
movq -0x4f0(%rbp), %rax
movl %eax, -0x41c(%rbp)
cmpl $-0x1, %eax
jne 0x6806
leaq 0x49f9(%rip), %rdi      # 0xb1f6
callq 0x3260
jmp 0x6804
jmp 0x6806
leaq -0x448(%rbp), %rdi
callq 0x31f0
movq -0x428(%rbp), %rdi
callq 0xa970
movq %rax, -0x428(%rbp)
jmp 0x6569
movq -0x10(%rbp), %rdi
callq 0xae10
cmpq $0x0, %rax
jne 0x693a
leaq -0x481(%rbp), %rdi
movq %rdi, -0x4f8(%rbp)
callq 0x34c0
movq -0x4f8(%rbp), %rdx
leaq 0x49af(%rip), %rsi      # 0xb20d
leaq -0x480(%rbp), %rdi
callq 0x88a0
jmp 0x686c
leaq -0x481(%rbp), %rdi
callq 0x3320
movq -0x490(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x50c(%rbp)
leaq -0x480(%rbp), %rdi
movq %rdi, -0x518(%rbp)
callq 0x3130
movq -0x518(%rbp), %rdi
movq %rax, -0x508(%rbp)
callq 0x3210
movl -0x50c(%rbp), %edi
movq -0x508(%rbp), %rsi
movq %rax, %rdx
callq 0x3110
movq %rax, -0x500(%rbp)
jmp 0x68cc
movq -0x500(%rbp), %rax
movl %eax, -0x41c(%rbp)
cmpl $-0x1, %eax
jne 0x692e
leaq 0x4911(%rip), %rdi      # 0xb1f6
callq 0x3260
jmp 0x68ec
jmp 0x692e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x458(%rbp)
movl %eax, -0x45c(%rbp)
leaq -0x481(%rbp), %rdi
callq 0x3320
jmp 0x6987
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x458(%rbp)
movl %eax, -0x45c(%rbp)
leaq -0x480(%rbp), %rdi
callq 0x31f0
jmp 0x6987
leaq -0x480(%rbp), %rdi
callq 0x31f0
movq -0x490(%rbp), %rax
movl 0x4(%rax), %edi
leaq 0x47d9(%rip), %rsi      # 0xb124
movl $0x6, %edx
callq 0x3110
movl %eax, -0x41c(%rbp)
cmpl $-0x1, %eax
jne 0x696c
leaq 0x488f(%rip), %rdi      # 0xb1f6
callq 0x3260
movq -0x10(%rbp), %rdi
callq 0xacf0
movq -0x10(%rbp), %rdi
callq 0xad20
addq $0x520, %rsp            # imm = 0x520
popq %rbp
retq
movq -0x458(%rbp), %rdi
callq 0x34b0
nopw %cs:(%rax,%rax)