posix_port_rep Class Reference

#include <posix_port.hpp>

Inheritance diagram for posix_port_rep:
port_rep rep_struct file_port_rep pipe_port_rep socket_port_rep

List of all members.

Public Member Functions

Public Attributes

Protected Attributes


Detailed Description

Definition at line 26 of file posix_port.hpp.


Constructor & Destructor Documentation

posix_port_rep ( int  kind2,
int  fd2 
)

Definition at line 35 of file posix_port.cpp.

References posix_port_rep::fd, mmx::in_count, posix_port_rep::kind, and mmx::out_count.

00035                                                  :
00036   kind (kind2), fd (fd2),
00037   buffer (""), pos (0), alive (true)
00038 {
00039   if ((kind & 1) != 0) out_count[fd]= out_count[fd] + 1;
00040   if ((kind & 2) != 0) in_count [fd]= in_count [fd] + 1;
00041 }

~posix_port_rep (  ) 

Definition at line 43 of file posix_port.cpp.

References posix_port_rep::fd, mmx::in_count, posix_port_rep::kind, mmx::out_count, and mmx::reset().

00043                                  {
00044   if ((kind & 1) != 0) {
00045     out_count[fd]= out_count[fd] - 1;
00046     if (out_count[fd] == 0) reset (out_count, fd);
00047   }
00048   if ((kind & 2) != 0) {
00049     in_count [fd]= in_count [fd] - 1;
00050     if (in_count[fd] == 0) reset (in_count, fd);
00051   }
00052 }


Member Function Documentation

port accept (  )  [virtual, inherited]

Reimplemented in socket_port_rep.

Definition at line 88 of file port.cpp.

References ERROR, port_rep::expression(), mmx::lf, and mmx::mmerr.

00088                   {
00089   mmerr << "port= " << expression () << lf;
00090   ERROR ("socket server port expected");
00091 }

virtual bool busy (  )  [inline, virtual]

Reimplemented from port_rep.

Reimplemented in file_port_rep.

Definition at line 41 of file posix_port.hpp.

References posix_port_rep::alive, posix_port_rep::buffer, posix_port_rep::feed(), mmx::N(), and posix_port_rep::pos.

00041 { feed (); return alive || pos < N(buffer); }

virtual nat can_read (  )  [inline, virtual]

Reimplemented from port_rep.

Reimplemented in file_port_rep.

Definition at line 43 of file posix_port.hpp.

References posix_port_rep::buffer, posix_port_rep::feed(), mmx::N(), and posix_port_rep::pos.

00043 { feed (); return N(buffer) - pos; }

virtual nat can_write (  )  [inline, virtual]

Reimplemented from port_rep.

Reimplemented in file_port_rep.

Definition at line 42 of file posix_port.hpp.

References posix_port_rep::alive.

00042 { return alive? (nat) (-1): 0; }

port component ( const string name  )  [virtual, inherited]

Reimplemented in composite_port_rep, and formatting_port_rep.

Definition at line 94 of file port.cpp.

References ERROR, port_rep::expression(), mmx::lf, and mmx::mmerr.

00094                                        {
00095   mmerr << "port= " << expression () << lf;
00096   ERROR ("composite port expected");
00097 }

bool error_flag (  )  [virtual, inherited]

Reimplemented in composite_port_rep, formatting_port_rep, and error_port_rep.

Definition at line 39 of file port.cpp.

00039                       {
00040   return false;
00041 }

string error_message (  )  [virtual, inherited]

Reimplemented in composite_port_rep, formatting_port_rep, and error_port_rep.

Definition at line 44 of file port.cpp.

00044                          {
00045   return "";
00046 }

virtual syntactic expression (  )  const [pure virtual, inherited]
void feed (  )  [virtual]

Reimplemented in socket_port_rep.

Definition at line 67 of file posix_port.cpp.

References posix_port_rep::alive, posix_port_rep::buffer, ERROR, posix_port_rep::fd, posix_port_rep::read(), and posix_port_rep::wait().

Referenced by posix_port_rep::busy(), posix_port_rep::can_read(), and posix_port_rep::read().

00067                       {
00068   while (alive && wait (0)) {
00069     int r;
00070     char tempout[1024];
00071     r = ::read (fd, tempout, 1024);
00072     if (r == -1) {
00073 #if defined(__MINGW__) || defined(__MINGW32__)
00074       _cwait (NULL, 0, _WAIT_CHILD);
00075 #else
00076       ::wait (NULL);
00077 #endif
00078       ERROR ("read failed");
00079     }
00080     else if (r == 0) alive= false;
00081     else buffer << string (tempout, r);
00082   }
00083 }

void flush (  )  [virtual, inherited]

Reimplemented in composite_port_rep, file_port_rep, and formatting_port_rep.

Definition at line 84 of file port.cpp.

00084                  {
00085 }

void format ( const print_format fm  )  [virtual, inherited]

Reimplemented in formatting_port_rep.

Definition at line 100 of file port.cpp.

References ERROR, port_rep::expression(), mmx::lf, and mmx::mmerr.

00100                                         {
00101   mmerr << "port= " << expression () << lf;
00102   ERROR ("formatting port expected");  
00103 }

virtual bool is_input_port (  )  [inline, virtual]

Reimplemented from port_rep.

Definition at line 40 of file posix_port.hpp.

References posix_port_rep::kind.

00040 { return (kind & 2) != 0; }

virtual bool is_output_port (  )  [inline, virtual]

Reimplemented from port_rep.

Definition at line 39 of file posix_port.hpp.

References posix_port_rep::kind.

00039 { return (kind & 1) != 0; }

virtual void read ( char *  s,
nat  n 
) [inline, virtual]

Reimplemented from port_rep.

Reimplemented in file_port_rep.

Definition at line 45 of file posix_port.hpp.

References posix_port_rep::buffer, posix_port_rep::feed(), mmx::inside(), mmx::mem_copy(), mmx::N(), and posix_port_rep::pos.

Referenced by posix_port_rep::feed().

00045                                             {
00046     while (pos + n > N(buffer)) feed ();
00047     mem_copy (s, inside (buffer, pos), n);
00048     pos += n; }

virtual void send ( const char *  s,
nat  n 
) [virtual]

Referenced by posix_port_rep::write().

bool wait ( int  msecs  )  [virtual]

Reimplemented from port_rep.

Definition at line 86 of file posix_port.cpp.

References posix_port_rep::alive, posix_port_rep::fd, and posix_port_rep::kind.

Referenced by socket_port_rep::accept(), socket_port_rep::feed(), and posix_port_rep::feed().

00086                                {
00087   //mmout << "Wait " << msecs << " ms on " << expression () << "\n";
00088   if ((kind & 2) == 0 || !alive) return false;
00089   fd_set in_fds;
00090   FD_ZERO (&in_fds);
00091   FD_SET (fd, &in_fds);
00092   
00093   nat nr;
00094   struct timeval tv;
00095   tv.tv_sec  = msecs / 1000;
00096   tv.tv_usec = 1000 * (msecs % 1000);
00097   if (msecs < 0) nr= select (fd + 1, &in_fds, NULL, NULL, NULL);
00098   else nr= select (fd + 1, &in_fds, NULL, NULL, &tv);
00099   //mmout << "Received " << nr << " on " << fd << "\n";
00100   return nr > 0;
00101 }

virtual void write ( const char *  s,
nat  n 
) [inline, virtual]

Reimplemented from port_rep.

Reimplemented in file_port_rep.

Definition at line 44 of file posix_port.hpp.

References posix_port_rep::send().

00044 { send (s, n); }


Member Data Documentation

bool alive [protected]
string buffer [protected]
int fd [protected]
int kind [protected]
nat pos [protected]
MMX_ALLOCATORS int ref_count [inherited]

Definition at line 164 of file basix.hpp.


The documentation for this class was generated from the following files:

Generated on 6 Dec 2012 for basix by  doxygen 1.6.1