GNU CommonC++
unix.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_UNIX_H_
44 #define CCXX_UNIX_H_
45 
46 #ifndef CCXX_MISSING_H_
47 #include <cc++/missing.h>
48 #endif
49 
50 #ifndef CCXX_SOCKET_H_
51 #include <cc++/socket.h>
52 #endif
53 
54 #ifdef CCXX_NAMESPACES
55 namespace ost {
56 #endif
57 
58 #ifndef WIN32
59 
73  class UnixSocket : protected Socket {
74  protected:
75  friend class UnixStream;
76  friend class SocketPort;
77  friend class unixstream;
78 
79  void close(void);
80  char *path;
81 
82  public:
91  UnixSocket(const char* pathname, int backlog = 5);
92 
96  inline bool isPendingConnection(timeout_t timeout = TIMEOUT_INF)
97  {return Socket::isPending(pendingInput, timeout);}
98 
102  virtual ~UnixSocket();
103  };
104 
118  class UnixStream : public Socket, public std::streambuf, public std::iostream {
119  private:
120  int doallocate();
121 
122  protected:
124  int bufsize;
125  char *gbuf, *pbuf;
126 
131  UnixStream(bool throwflag = true);
132 
139  void allocate(int size);
140 
145  void endStream(void);
146 
153  virtual int underflow(void);
154 
163  int uflow(void);
164 
172  int overflow(int ch);
173 
180  void connect(const char* pathname, int size);
181 
189  std::iostream *unixstr(void)
190  {return ((std::iostream *)this);};
191 
192  public:
203  UnixStream(UnixSocket &server, int size = 512, bool throwflag = true, timeout_t timeout = 0);
204 
213  UnixStream(const char* pathname, int size = 512, bool throwflag = true, timeout_t to = 0);
214 
220  inline void setTimeout(timeout_t to)
221  {timeout = to;};
222 
229  UnixStream(const UnixStream &source);
230 
235  virtual ~UnixStream();
236 
243  int sync(void);
244 
253 
259  int getBufferSize(void) const
260  {return bufsize;};
261  };
262 
271  class unixstream : public UnixStream {
272  public:
276  unixstream();
277 
285  unixstream(const char *pathname, int buffer = 512);
286 
294  unixstream(UnixSocket &unixsock, int buffer = 512);
295 
303  void open(const char *pathname, int buffer = 512)
304  { UnixStream::connect( pathname, buffer ); }
305 
312  void open(UnixSocket &unixsock, int buffer = 512);
313 
317  void close(void);
318 
322  bool operator!() const;
323  };
324 
335  class __EXPORT UnixSession : public Thread, public UnixStream {
336  protected:
349  int waitConnection(timeout_t timeout = TIMEOUT_INF);
350 
357  void initial(void);
358 
359  public:
369  UnixSession(const char* pathname, int size = 512, int pri = 0, int stack = 0);
370 
380  UnixSession(UnixSocket &server, int size = 512,
381  int pri = 0, int stack = 0);
382 
386  virtual ~UnixSession();
387  };
388 
389 #endif // ndef WIN32
390 
391 #ifdef CCXX_NAMESPACES
392 }
393 #endif
394 
395 #endif
396 
397 
398