Debian Codegraph @

protolib/include/protoPipe.h

raw
1 #ifndef _PROTO_PIPE
2 #define _PROTO_PIPE
3
4 #include "protoSocket.h"
5 #include "protoDefs.h"
6 /**
7 * @class ProtoPipe
8 *
9 * @brief Provides a cross-platform interprocess communication
10 * mechanism for Protolib using Unix-domain sockets (UNIX) or
11 * named pipe/mailslot mechanisms (WIN32). This class
12 * extends the "ProtoSocket" class to support "LOCAL"
13 * domain interprocess communications.
14 */
15 class ProtoPipe : public ProtoSocket
16 {
17 public:
18 enum Type {MESSAGE, STREAM};
19
20 ProtoPipe(Type theType = MESSAGE);
21 ~ProtoPipe();
22
23 Type GetType() {return ((UDP == GetProtocol()) ? MESSAGE : STREAM);}
24 const char* GetName() {return path;}
25 bool Connect(const char* serverName);
26 bool Listen(const char* theName);
27 bool Accept(ProtoPipe* thePipe = NULL);
28 void Close();
29
30 bool Send(const char* buffer, unsigned int& numBytes)
31 {return ProtoSocket::Send(buffer, numBytes);}
32 bool Recv(char* buffer, unsigned int& numBytes)
33 {return ProtoSocket::Recv(buffer, numBytes);}
34
35 private:
36 bool Open(const char* theName);
37 #ifndef WIN32
38 void Unlink(const char* theName);
39 bool unlink_tried;
40 #else
41 #ifdef _NEVER_
42 virtual bool SetBlocking(bool blocking);
43 HANDLE pipe_handle;
44 bool is_mailslot;
45 // These member facilitate Win32 overlapped I/O
46 // which we use for async I/O
47 enum {BUFFER_MAX = 8192};
48 char read_buffer[BUFFER_MAX];
49 unsigned int read_count;
50 unsigned int read_index;
51 char write_buffer[BUFFER_MAX];
52 OVERLAPPED read_overlapped;
53 OVERLAPPED write_overlapped;
54 #endif
55 HANDLE named_event_handle;
56 #endif // if/else !WIN32
57 char path[PATH_MAX];
58 };
59
60 #endif // !_PROTO_PIPE