basix_doc 0.1
socket_port_rep Class Reference
Inheritance diagram for socket_port_rep:
posix_port_rep port_rep rep_struct

List of all members.

Public Member Functions

Public Attributes

Protected Attributes


Detailed Description

Definition at line 31 of file socket_port.cpp.


Constructor & Destructor Documentation

socket_port_rep ( const string host2,
int  pnr2,
int  role2,
int  fd 
) [inline]

Definition at line 76 of file socket_port.cpp.

                                                                           :
    posix_port_rep (3, fd),
    host (host2), pnr (pnr2), role (role2) {}
~socket_port_rep ( ) [inline]

Definition at line 79 of file socket_port.cpp.

References posix_port_rep::fd.

                             {
    close (this->fd); }

Member Function Documentation

port accept ( ) [virtual]

Reimplemented from port_rep.

Definition at line 126 of file socket_port.cpp.

References posix_port_rep::alive, ASSERT, mmx::error_port(), posix_port_rep::fd, mmx::socket_port(), and posix_port_rep::wait().

                         {
  ASSERT (role == 0, "socket server port expected");
  if (!this->alive || !wait (0)) return error_port ("no incoming connection");
  struct sockaddr_in remote_address;
  socklen_t addrlen= sizeof (remote_address);
  int client=
    ::accept (this->fd, (struct sockaddr *) &remote_address, &addrlen);
  if (client == -1)
    return error_port ("Call to 'accept' failed");
  else {
    string addr= inet_ntoa (remote_address.sin_addr);
    return socket_port (host, pnr, 1, client);
  }
}
virtual bool busy ( ) [inline, virtual, inherited]

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, inherited]

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, inherited]

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 "";
}
syntactic expression ( ) const [inline, virtual]

Implements port_rep.

Definition at line 37 of file socket_port.cpp.

References mmx::syn().

                                {
    if (role == 0)
      return syn ("socket_server_port", syntactic (host), syntactic (pnr));
    else if (role == 1)
      return syn ("socket_accept_port", syntactic (host), syntactic (pnr));
    else
      return syn ("socket_client_port", syntactic (host), syntactic (pnr));
  }
void feed ( ) [inline, virtual]

Reimplemented from posix_port_rep.

Definition at line 60 of file socket_port.cpp.

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

               {
    if (this->pos > ((N(this->buffer) >> 1) + 1024)) {
      this->buffer= this->buffer (this->pos, N(this->buffer));
      this->pos= 0;
    }
    while (this->alive && wait (0)) {
      char tempout[1024];
      int r= recv (this->fd, tempout, 1024, 0);
      if (r <= 0) { this->alive= false; break; }
      else this->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, inherited]

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, inherited]

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, inherited]

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  len 
) [inline, virtual]

Reimplemented from posix_port_rep.

Definition at line 46 of file socket_port.cpp.

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

                                     {
    if (this->alive) {
      nat total= 0;          // how many bytes we've sent
      nat bytes_left= len;   // how many we have left to send
      nat n= 0;
      while (total < len) {
        n= ::send (this->fd, s+total, bytes_left, 0);
        if (n == ((nat) -1)) break;
        total += n;
        bytes_left -= n;
      }
    }
  }
bool wait ( int  msecs) [virtual, inherited]

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, inherited]

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

nat pos [protected, inherited]
MMX_ALLOCATORS int ref_count [inherited]

Definition at line 138 of file basix.hpp.


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