2 #include <lib/base/filepush.h>
3 #include <lib/base/eerror.h>
10 eFilePushThread::eFilePushThread(): m_messagepump(eApp, 0)
15 CONNECT(m_messagepump.recv_msg, eFilePushThread::recvEvent);
18 static void signal_handler(int x)
22 void eFilePushThread::thread()
26 int already_empty = 0;
27 eDebug("FILEPUSH THREAD START");
28 // this is a race. FIXME.
30 /* we set the signal to not restart syscalls, so we can detect our signal. */
32 act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR
34 sigaction(SIGUSR1, &act, 0);
36 dest_pos = lseek(m_fd_dest, 0, SEEK_CUR);
37 /* m_stop must be evaluated after each syscall. */
40 /* first try flushing the bufptr */
41 if (m_buf_start != m_buf_end)
43 // TODO: take care of boundaries.
44 int w = write(m_fd_dest, m_buffer + m_buf_start, m_buf_end - m_buf_start);
45 // eDebug("wrote %d bytes", w);
50 eDebug("eFilePushThread *write error* (%m) - not yet handled");
51 // ... we would stop the thread
54 /* this should flush all written pages to disk. */
55 posix_fadvise(m_fd_dest, dest_pos, w, POSIX_FADV_DONTNEED);
58 // printf("FILEPUSH: wrote %d bytes\n", w);
63 /* now fill our buffer. */
65 m_buf_end = read(m_fd_source, m_buffer, sizeof(m_buffer));
71 eDebug("eFilePushThread *read error* - not yet handled");
75 /* on EOF, try COMMITting once. */
76 if (m_send_pvr_commit && !already_empty)
78 eDebug("sending PVR commit");
80 if (::ioctl(m_fd_dest, PVR_COMMIT) == EINTR)
82 eDebug("commit done");
83 /* well check again */
89 eDebug("FILEPUSH: end-of-file! (currently unhandled)");
90 if (!lseek(m_fd_source, 0, SEEK_SET))
99 // printf("FILEPUSH: read %d bytes\n", m_buf_end);
102 eDebug("FILEPUSH THREAD STOP");
105 void eFilePushThread::start(int fd_source, int fd_dest)
107 m_fd_source = fd_source;
112 void eFilePushThread::stop()
114 if (!thread_running()) /* FIXME: races */
121 void eFilePushThread::pause()
126 void eFilePushThread::seek(int whence, off_t where)
128 ::lseek(m_fd_source, where, whence);
131 void eFilePushThread::resume()
137 void eFilePushThread::flush()
139 m_buf_start = m_buf_end = 0;
142 void eFilePushThread::enablePVRCommit(int s)
144 m_send_pvr_commit = s;
147 void eFilePushThread::sendEvent(int evt)
149 m_messagepump.send(evt);
152 void eFilePushThread::recvEvent(const int &evt)