// File: /workspace/github_cpp_makefile_star2_O2/billDrett[P]Bulletin-Boards/boardPost.cpp
// Function: BoardPost::sendFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void BoardPost::sendFile(string file, int Id)
{
    int fp, found;
    int nread, nwrite;
    char buff[BUFFERSIZE];
    string name, tmpName;
    char convert[24];

    fp =open(file.c_str(), O_RDONLY, 0644);
    if(fp == -1) return;

    if((nwrite = write(pipeBoardPost2Server, "<File>", 6))== -1) //stelnoume ta tags gia arxh File
    {
        perror("Cant write to pipe BP2S");
    }
    if((nwrite = write(pipeBoardPost2Server, "<start>", 7))== -1)
    {
        perror("Cant write to pipe C2S");
    }
    sprintf(convert, "%d", Id);
    name.append(convert); //stelnw to chanel
    name.append(" ");
    found = file.find_last_of("/"); //prepei na parw to onoma, epeidh mporei na einai path pairnw to string meta to teleutaio "/"
    if(found ==  string::npos)
    {
        tmpName = file;
    }
    else
    {
        tmpName = file.substr(found+1);
    }
    name.append(tmpName);

    for(int i = name.size(); i <30; i++) //SYMVASH ta prwta 30 tha einai gia to chanelId kai to onoma tou arxeiou ara gemizw to ypoloipo me space
    {
        name.append(" ");
    }

    if((nwrite = write(pipeBoardPost2Server, name.c_str(), name.size()))== -1)
    {
        perror("Cant write to pipe BP2S");
    }

    while((nread = read(fp, buff, BUFFERSIZE)) > 0) //stelnw to arxeio
    {
        if(write(pipeBoardPost2Server, buff, nread) == -1)
        {
            perror("Cant write to pipe BP2S");
        }
    }

    if((nwrite = write(pipeBoardPost2Server, "<end>", 5))== -1)
    {
        perror("Cant write to pipe C2S");
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x58(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
movq (%rsi), %rdi
xorl %esi, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x2120
movl %eax, %r14d
cmpl $-0x1, %eax
je 0x2e7d
movl (%rbx), %edi
leaq 0x13ee(%rip), %rsi      # 0x40d3
pushq $0x6
popq %rdx
callq 0x2090
cmpl $-0x1, %eax
je 0x2de6
movl (%rbx), %edi
leaq 0x13a0(%rip), %rsi      # 0x409f
pushq $0x7
popq %rdx
callq 0x2090
cmpl $-0x1, %eax
je 0x2df7
leaq 0x13a8(%rip), %rsi      # 0x40bf
leaq -0xa0(%rbp), %r13
movq %r13, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2030
leaq -0x48(%rbp), %rdi
movq %r13, %rsi
callq 0x2250
leaq 0x13d8(%rip), %rsi      # 0x4116
leaq -0x48(%rbp), %rdi
callq 0x2250
leaq 0x12c6(%rip), %rsi      # 0x4014
pushq $-0x1
popq %rdx
movq %r15, %rdi
callq 0x2160
cmpl $-0x1, %eax
jne 0x2d6c
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
callq 0x2100
jmp 0x2d9e
incl %eax
movslq %eax, %rdx
leaq -0x88(%rbp), %rdi
pushq $-0x1
popq %rcx
movq %r15, %rsi
callq 0x21a0
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %r15
movq %r15, %rsi
callq 0x21c0
movq %r15, %rdi
callq 0x20c0
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2270
leaq -0x48(%rbp), %r15
movl 0x8(%r15), %r13d
leaq 0x135c(%rip), %r12      # 0x4116
cmpl $0x1e, %r13d
jge 0x2dd0
movq %r15, %rdi
movq %r12, %rsi
callq 0x2250
incl %r13d
jmp 0x2dba
movl (%rbx), %edi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x2090
cmpl $-0x1, %eax
je 0x2e12
jmp 0x2e1e
leaq 0x12ba(%rip), %rdi      # 0x40a7
callq 0x2130
jmp 0x2cf6
leaq 0x12dc(%rip), %rdi      # 0x40da
callq 0x2130
jmp 0x2d10
jmp 0x2ebf
jmp 0x2ebf
leaq 0x128e(%rip), %rdi      # 0x40a7
callq 0x2130
leaq -0x4a0(%rbp), %r15
movl $0x400, %edx            # imm = 0x400
movl %r14d, %edi
movq %r15, %rsi
callq 0x2210
movl (%rbx), %edi
testl %eax, %eax
jle 0x2e53
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rsi
movq %rax, %rdx
callq 0x2090
cmpq $-0x1, %rax
jne 0x2e25
jmp 0x2e12
leaq 0x1236(%rip), %rsi      # 0x4090
pushq $0x5
popq %rdx
callq 0x2090
cmpl $-0x1, %eax
je 0x2ea1
movl (%rbx), %edi
leaq 0x1263(%rip), %rsi      # 0x40d3
pushq $0x6
popq %rdx
callq 0x2090
cmpl $-0x1, %eax
je 0x2eaf
leaq -0x68(%rbp), %rdi
callq 0x20c0
leaq -0x48(%rbp), %rdi
callq 0x20c0
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1232(%rip), %rdi      # 0x40da
callq 0x2130
jmp 0x2e67
leaq 0x11f1(%rip), %rdi      # 0x40a7
callq 0x2130
jmp 0x2e7d
jmp 0x2ebf
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20c0
leaq -0x48(%rbp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2240