2 #include <lib/base/filepush.h>
3 #include <lib/base/eerror.h>
7 eFilePushThread::eFilePushThread(): m_messagepump(eApp, 0)
11 CONNECT(m_messagepump.recv_msg, eFilePushThread::recvEvent);
14 static void signal_handler(int x)
18 void eFilePushThread::thread()
21 eDebug("FILEPUSH THREAD START");
22 // this is a race. FIXME.
24 /* we set the signal to not restart syscalls, so we can detect our signal. */
26 act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR
28 sigaction(SIGUSR1, &act, 0);
30 dest_pos = lseek(m_fd_dest, 0, SEEK_CUR);
31 /* m_stop must be evaluated after each syscall. */
34 /* first try flushing the bufptr */
35 if (m_buf_start != m_buf_end)
37 // TODO: take care of boundaries.
38 int w = write(m_fd_dest, m_buffer + m_buf_start, m_buf_end - m_buf_start);
39 // eDebug("wrote %d bytes", w);
44 eDebug("eFilePushThread *write error* (%m) - not yet handled");
45 // ... we would stop the thread
48 /* this should flush all written pages to disk. */
49 posix_fadvise(m_fd_dest, dest_pos, w, POSIX_FADV_DONTNEED);
52 // printf("FILEPUSH: wrote %d bytes\n", w);
57 /* now fill our buffer. */
59 m_buf_end = read(m_fd_source, m_buffer, sizeof(m_buffer));
65 eDebug("eFilePushThread *read error* - not yet handled");
72 eDebug("FILEPUSH: end-of-file! (currently unhandled)");
73 if (!lseek(m_fd_source, 0, SEEK_SET))
81 // printf("FILEPUSH: read %d bytes\n", m_buf_end);
84 eDebug("FILEPUSH THREAD STOP");
87 void eFilePushThread::start(int fd_source, int fd_dest)
89 m_fd_source = fd_source;
94 void eFilePushThread::stop()
101 void eFilePushThread::pause()
106 void eFilePushThread::seek(int whence, off_t where)
108 ::lseek(m_fd_source, where, whence);
111 void eFilePushThread::resume()
117 void eFilePushThread::flush()
119 m_buf_start = m_buf_end = 0;
123 void eFilePushThread::sendEvent(int evt)
125 m_messagepump.send(evt);
128 void eFilePushThread::recvEvent(const int &evt)