basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/include/basix/posix_port.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : posix_port.hpp
00004 * DESCRIPTION: Ports from file descriptors
00005 * COPYRIGHT  : (C) 2010  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00011 ******************************************************************************/
00012 
00013 #ifndef __POSIX_PORT_HPP
00014 #define __POSIX_PORT_HPP
00015 #include <basix/port.hpp>
00016 #include <basix/table.hpp>
00017 
00019 
00020 namespace mmx {
00021 
00022 /******************************************************************************
00023 * The posix_port class
00024 ******************************************************************************/
00025 
00026 class posix_port_rep: public port_rep {
00027 protected:
00028   int    kind;
00029   int    fd;
00030   string buffer;
00031   nat    pos;
00032   bool   alive;
00033 
00034 public:
00035   virtual void send (const char* s, nat n);
00036   virtual void feed ();
00037   virtual bool wait (int msecs);
00038 
00039   virtual inline bool is_output_port () { return (kind & 1) != 0; }
00040   virtual inline bool is_input_port () { return (kind & 2) != 0; }
00041   virtual inline bool busy () { feed (); return alive || pos < N(buffer); }
00042   virtual inline nat  can_write () { return alive? (nat) (-1): 0; }
00043   virtual inline nat  can_read () { feed (); return N(buffer) - pos; }
00044   virtual inline void write (const char* s, nat n) { send (s, n); }
00045   virtual inline void read (char* s, nat n) {
00046     while (pos + n > N(buffer)) feed ();
00047     mem_copy (s, inside (buffer, pos), n);
00048     pos += n; }
00049 
00050 public:
00051   posix_port_rep (int kind2, int fd2);
00052   ~posix_port_rep ();
00053 };
00054 
00055 } // namespace mmx
00056 #endif // __POSIX_PORT_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines