Definition at line 35 of file socket_port.cpp.
socket_port_rep | ( | const string & | host2, | |
int | pnr2, | |||
int | role2, | |||
int | fd | |||
) | [inline] |
Definition at line 80 of file socket_port.cpp.
00080 : 00081 posix_port_rep (3, fd), 00082 host (host2), pnr (pnr2), role (role2) {} inline ~socket_port_rep () {
~socket_port_rep | ( | ) | [inline] |
Definition at line 83 of file socket_port.cpp.
References posix_port_rep::fd.
00083 { 00084 close (this->fd); }
port accept | ( | ) | [virtual] |
Reimplemented from port_rep.
Definition at line 135 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().
00135 { 00136 ASSERT (role == 0, "socket server port expected"); 00137 if (!this->alive || !wait (0)) return error_port ("no incoming connection"); 00138 struct sockaddr_in remote_address; 00139 #if defined(__MINGW__) || defined(__MINGW32__) 00140 int addrlen= sizeof (remote_address); 00141 #else 00142 socklen_t addrlen= sizeof (remote_address); 00143 #endif 00144 int client= 00145 ::accept (this->fd, (struct sockaddr *) &remote_address, &addrlen); 00146 if (client == -1) 00147 return error_port ("Call to 'accept' failed"); 00148 else { 00149 string addr= inet_ntoa (remote_address.sin_addr); 00150 return socket_port (host, pnr, 1, client); 00151 } 00152 }
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.
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.
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.
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.
string error_message | ( | ) | [virtual, inherited] |
Reimplemented in composite_port_rep, formatting_port_rep, and error_port_rep.
syntactic expression | ( | ) | const [inline, virtual] |
Implements port_rep.
Definition at line 41 of file socket_port.cpp.
References mmx::syn().
00041 { 00042 if (role == 0) 00043 return syn ("socket_server_port", syntactic (host), syntactic (pnr)); 00044 else if (role == 1) 00045 return syn ("socket_accept_port", syntactic (host), syntactic (pnr)); 00046 else 00047 return syn ("socket_client_port", syntactic (host), syntactic (pnr)); 00048 }
void feed | ( | ) | [inline, virtual] |
Reimplemented from posix_port_rep.
Definition at line 64 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().
00064 { 00065 if (this->pos > ((N(this->buffer) >> 1) + 1024)) { 00066 this->buffer= this->buffer (this->pos, N(this->buffer)); 00067 this->pos= 0; 00068 } 00069 while (this->alive && wait (0)) { 00070 char tempout[1024]; 00071 int r= recv (this->fd, tempout, 1024, 0); 00072 if (r <= 0) { this->alive= false; break; } 00073 else this->buffer << string (tempout, r); 00074 } 00075 }
void flush | ( | ) | [virtual, inherited] |
Reimplemented in composite_port_rep, file_port_rep, and formatting_port_rep.
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, inherited] |
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, inherited] |
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, 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(), mmx::N(), and posix_port_rep::pos.
Referenced by posix_port_rep::feed().
virtual void send | ( | const char * | s, | |
nat | n | |||
) | [virtual, inherited] |
Referenced by posix_port_rep::write().
void send | ( | const char * | obj->lex_string, | |
nat | len | |||
) | [inline] |
Definition at line 50 of file socket_port.cpp.
References posix_port_rep::alive, posix_port_rep::fd, and n.
00050 { 00051 if (this->alive) { 00052 nat total= 0; // how many bytes we've sent 00053 nat bytes_left= len; // how many we have left to send 00054 nat n= 0; 00055 while (total < len) { 00056 n= ::send (this->fd, s+total, bytes_left, 0); 00057 if (n == ((nat) -1)) break; 00058 total += n; 00059 bytes_left -= n; 00060 } 00061 } 00062 }
bool wait | ( | int | msecs | ) | [virtual, inherited] |
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, inherited] |
Reimplemented from port_rep.
Reimplemented in file_port_rep.
Definition at line 44 of file posix_port.hpp.
References posix_port_rep::send().
bool alive [protected, inherited] |
Definition at line 32 of file posix_port.hpp.
Referenced by socket_port_rep::accept(), posix_port_rep::busy(), posix_port_rep::can_write(), socket_port_rep::feed(), posix_port_rep::feed(), socket_port_rep::send(), and posix_port_rep::wait().
Definition at line 30 of file posix_port.hpp.
Referenced by posix_port_rep::busy(), posix_port_rep::can_read(), socket_port_rep::feed(), posix_port_rep::feed(), and posix_port_rep::read().
int fd [protected, inherited] |
Definition at line 29 of file posix_port.hpp.
Referenced by socket_port_rep::accept(), socket_port_rep::feed(), posix_port_rep::feed(), posix_port_rep::posix_port_rep(), socket_port_rep::send(), posix_port_rep::wait(), pipe_port_rep::~pipe_port_rep(), posix_port_rep::~posix_port_rep(), and socket_port_rep::~socket_port_rep().
int kind [protected, inherited] |
Definition at line 28 of file posix_port.hpp.
Referenced by file_port_rep::busy(), file_port_rep::can_read(), file_port_rep::can_write(), file_port_rep::expression(), posix_port_rep::is_input_port(), posix_port_rep::is_output_port(), posix_port_rep::posix_port_rep(), posix_port_rep::wait(), and posix_port_rep::~posix_port_rep().
Definition at line 31 of file posix_port.hpp.
Referenced by posix_port_rep::busy(), posix_port_rep::can_read(), socket_port_rep::feed(), and posix_port_rep::read().