- sdl is now default output
[enigma2.git] / lib / base / message.cpp
1 #include <lib/base/message.h>
2 #include <unistd.h>
3 #include <lib/base/eerror.h>
4
5 eMessagePump::eMessagePump(int mt): content(1024*1024), ismt(mt)
6 {
7         pipe(fd);
8 }
9
10 eMessagePump::~eMessagePump()
11 {       
12         if (ismt)
13                 content.lock(); // blocks until all messages are processed.
14         close(fd[0]);
15         close(fd[1]);
16 }
17
18 int eMessagePump::send(const void *data, int len)
19 {
20         if (ismt)
21                 content.lock(len);
22         return ::write(fd[1], data, len)<0;
23 }
24
25 int eMessagePump::recv(void *data, int len)
26 {
27         unsigned char*dst=(unsigned char*)data;
28         while (len)
29         {
30                 if (ismt)
31                         content.unlock(len);
32                 int r=::read(fd[0], dst, len);
33                 if (r<0)
34                         return r;
35                 dst+=r;
36                 len-=r;
37         }
38         return 0;
39 }
40
41 int eMessagePump::getInputFD() const
42 {
43         return fd[1];
44 }
45
46 int eMessagePump::getOutputFD() const
47 {
48         return fd[0];
49 }