basix_doc 0.1
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 30 of file posix_port.cpp.

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

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

Definition at line 38 of file posix_port.cpp.

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

                                 {
  if ((kind & 1) != 0) {
    out_count[fd]= out_count[fd] - 1;
    if (out_count[fd] == 0) reset (out_count, fd);
  }
  if ((kind & 2) != 0) {
    in_count [fd]= in_count [fd] - 1;
    if (in_count[fd] == 0) reset (in_count, fd);
  }
}

Member Function Documentation

port accept ( ) [virtual, inherited]

Reimplemented in socket_port_rep.

Definition at line 87 of file port.cpp.

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

                  {
  mmerr << "port= " << expression () << lf;
  ERROR ("socket server port expected");
}
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.

{ 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.

{ 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.

{ return alive? (nat) (-1): 0; }
port component ( const string name) [virtual, inherited]

Reimplemented in composite_port_rep, and formatting_port_rep.

Definition at line 93 of file port.cpp.

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

                                       {
  mmerr << "port= " << expression () << lf;
  ERROR ("composite port expected");
}
bool error_flag ( ) [virtual, inherited]

Reimplemented in composite_port_rep, formatting_port_rep, and error_port_rep.

Definition at line 38 of file port.cpp.

                      {
  return false;
}
string error_message ( ) [virtual, inherited]

Reimplemented in composite_port_rep, formatting_port_rep, and error_port_rep.

Definition at line 43 of file port.cpp.

                         {
  return "";
}
void feed ( ) [virtual]

Reimplemented in socket_port_rep.

Definition at line 62 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().

                      {
  while (alive && wait (0)) {
    int r;
    char tempout[1024];
    r = ::read (fd, tempout, 1024);
    if (r == -1) {
      ::wait (NULL);
      ERROR ("read failed");
    }
    else if (r == 0) alive= false;
    else buffer << string (tempout, r);
  }
}
void flush ( ) [virtual, inherited]

Reimplemented in composite_port_rep, file_port_rep, and formatting_port_rep.

Definition at line 83 of file port.cpp.

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

Reimplemented in formatting_port_rep.

Definition at line 99 of file port.cpp.

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

                                        {
  mmerr << "port= " << expression () << lf;
  ERROR ("formatting port expected");  
}
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.

{ 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.

{ 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(), n, mmx::N(), and posix_port_rep::pos.

Referenced by posix_port_rep::feed().

                                            {
    while (pos + n > N(buffer)) feed ();
    mem_copy (s, inside (buffer, pos), n);
    pos += n; }
void send ( const char *  s,
nat  n 
) [virtual]

Reimplemented in socket_port_rep.

Definition at line 54 of file posix_port.cpp.

References posix_port_rep::alive, posix_port_rep::fd, n, s, and posix_port_rep::write().

Referenced by posix_port_rep::write().

                                          {
  if (alive) {
    int err= ::write (fd, s, n);
    (void) err;
  }
}
bool wait ( int  msecs) [virtual]

Reimplemented from port_rep.

Definition at line 77 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().

                               {
  //mmout << "Wait " << msecs << " ms on " << expression () << "\n";
  if ((kind & 2) == 0 || !alive) return false;
  fd_set in_fds;
  FD_ZERO (&in_fds);
  FD_SET (fd, &in_fds);
  
  nat nr;
  struct timeval tv;
  tv.tv_sec  = msecs / 1000;
  tv.tv_usec = 1000 * (msecs % 1000);
  if (msecs < 0) nr= select (fd + 1, &in_fds, NULL, NULL, NULL);
  else nr= select (fd + 1, &in_fds, NULL, NULL, &tv);
  //mmout << "Received " << nr << " on " << fd << "\n";
  return nr > 0;
}
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().

Referenced by posix_port_rep::send().

{ send (s, n); }

Member Data Documentation

MMX_ALLOCATORS int ref_count [inherited]

Definition at line 138 of file basix.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines