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);
37 eDebug("wrote %d bytes", w);
42 eDebug("eFilePushThread *write error* - not yet handled");
43 // ... we would stop the thread
46 /* this should flush all written pages to disk. */
47 posix_fadvise(m_fd_dest, dest_pos, w, POSIX_FADV_DONTNEED);
50 // printf("FILEPUSH: wrote %d bytes\n", w);
55 /* now fill our buffer. */
57 m_buf_end = read(m_fd_source, m_buffer, sizeof(m_buffer));
63 eDebug("eFilePushThread *read error* - not yet handled");
67 eDebug("FILEPUSH: end-of-file! (currently unhandled)");
68 if (!lseek(m_fd_source, 0, SEEK_SET))
75 // printf("FILEPUSH: read %d bytes\n", m_buf_end);
78 eDebug("FILEPUSH THREAD STOP");
81 void eFilePushThread::start(int fd_source, int fd_dest)
83 m_fd_source = fd_source;
88 void eFilePushThread::stop()
95 void eFilePushThread::pause()
100 void eFilePushThread::seek(off_t where)
102 ::lseek(m_fd_source, where, SEEK_SET);
105 void eFilePushThread::resume()