1 #include <lib/base/filepush.h>
2 #include <lib/base/eerror.h>
6 eFilePushThread::eFilePushThread()
9 m_buf_start = m_buf_end = 0;
12 static void signal_handler(int x)
16 void eFilePushThread::thread()
19 eDebug("FILEPUSH THREAD START");
20 // this is a race. FIXME.
22 /* we set the signal to not restart syscalls, so we can detect our signal. */
24 act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR
26 sigaction(SIGUSR1, &act, 0);
28 dest_pos = lseek(m_fd_dest, 0, SEEK_CUR);
29 /* m_stop must be evaluated after each syscall. */
32 /* first try flushing the bufptr */
33 if (m_buf_start != m_buf_end)
35 // TODO: take care of boundaries.
36 int w = write(m_fd_dest, m_buffer + m_buf_start, m_buf_end - m_buf_start);
41 eDebug("eFilePushThread *write error* - not yet handled");
42 // ... we would stop the thread
45 posix_fadvise(m_fd_dest, dest_pos, w, POSIX_FADV_DONTNEED);
48 // printf("FILEPUSH: wrote %d bytes\n", w);
53 /* now fill our buffer. */
55 m_buf_end = read(m_fd_source, m_buffer, sizeof(m_buffer));
61 eDebug("eFilePushThread *read error* - not yet handled");
65 eDebug("FILEPUSH: end-of-file! (currently unhandled)");
66 if (!lseek(m_fd_source, 0, SEEK_SET))
73 // printf("FILEPUSH: read %d bytes\n", m_buf_end);
76 eDebug("FILEPUSH THREAD STOP");
79 void eFilePushThread::start(int fd_source, int fd_dest)
81 m_fd_source = fd_source;
87 void eFilePushThread::stop()