#include <UPIPE_Stream.h>
Inheritance diagram for ACE_UPIPE_Stream:


Public Types | |
| typedef ACE_UPIPE_Addr | PEER_ADDR |
Public Methods | |
| ACE_UPIPE_Stream (void) | |
| virtual | ~ACE_UPIPE_Stream (void) |
| int | close (void) |
| Shut down the UPIPE and release resources. More... | |
| ACE_HANDLE | get_handle (void) const |
| Return the underlying I/O handle. More... | |
| int | send (ACE_Message_Block *mb_p, ACE_Time_Value *timeout=0) |
| Send a message through the message queue. Returns -1 on error, else 0. More... | |
| int | recv (ACE_Message_Block *&mb_p, ACE_Time_Value *timeout=0) |
| Recv a message from the message queue. Returns -1 on error, else 0. More... | |
| ssize_t | send (const char *buffer, size_t n, ACE_Time_Value *timeout=0) |
| Send a buffer of <n> bytes through the message queue. Returns -1 on error, else number of bytes sent. More... | |
| ssize_t | recv (char *buffer, size_t n, ACE_Time_Value *timeout=0) |
| Recv a buffer of upto <n> bytes from the message queue. Returns -1 on error, else number of bytes read. More... | |
| ssize_t | send_n (const char *buffer, size_t n, ACE_Time_Value *timeout=0) |
| Send a buffer of exactly <n> bytes to the message queue. Returns -1 on error, else number of bytes written (which should == n). More... | |
| ssize_t | recv_n (char *buffer, size_t n, ACE_Time_Value *timeout=0) |
| Recv a buffer of exactly <n> bytes from the message queue. Returns -1 on error, else the number of bytes read. More... | |
| int | control (int cmd, void *val) const |
| Perform control operations on the UPIPE_Stream. More... | |
| int | get_remote_addr (ACE_UPIPE_Addr &remote_sap) const |
| Return the remote address we are connected to. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Private Attributes | |
| ACE_Message_Block * | mb_last_ |
| To hold the last ACE_Message_Block read out of the stream. Thus allowing subsequent reads from one ACE_Message_Block. More... | |
| ACE_UPIPE_Addr | remote_addr_ |
| Address of who we are connected to. More... | |
| MT_Stream | stream_ |
| Stream component used by the <UPIPE_Acceptor> and <UPIPE_Connector> to link together two UPIPE_Streams. More... | |
| int | reference_count_ |
| Keep track of whether the sender and receiver have both shut down. More... | |
Friends | |
| class | ACE_UPIPE_Acceptor |
| class | ACE_UPIPE_Connector |
Definition at line 40 of file UPIPE_Stream.h.
|
|
Definition at line 107 of file UPIPE_Stream.h. |
|
|
Definition at line 18 of file UPIPE_Stream.cpp. References ACE_TRACE.
00019 : mb_last_ (0), 00020 reference_count_ (0) 00021 { 00022 ACE_TRACE ("ACE_UPIPE_Stream::ACE_UPIPE_STREAM"); 00023 } |
|
|
Definition at line 25 of file UPIPE_Stream.cpp. References mb_last_, and ACE_Message_Block::release.
|
|
|
Shut down the UPIPE and release resources.
Reimplemented from ACE_SPIPE. Definition at line 51 of file UPIPE_Stream.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, ACE_Stream< ACE_SYNCH >::close, ACE_SPIPE::close, ACE_IPC_SAP::get_handle, reference_count_, and stream_.
00052 {
00053 ACE_TRACE ("ACE_UPIPE_Stream::close");
00054 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00055
00056 this->reference_count_--;
00057
00058 if (this->reference_count_ == 0)
00059 {
00060 // Since the UPIPE should have been closed earlier we won't bother
00061 // checking to see if closing it now fails.
00062
00063 if (this->ACE_SPIPE::get_handle () != ACE_INVALID_HANDLE)
00064 this->ACE_SPIPE::close ();
00065
00066 // Close down the ACE_stream.
00067 return this->stream_.close ();
00068 }
00069 return 0;
00070 }
|
|
||||||||||||
|
Perform control operations on the UPIPE_Stream.
Reimplemented from ACE_IPC_SAP. Definition at line 35 of file UPIPE_Stream.cpp. References ACE_TRACE.
00037 {
00038 ACE_TRACE ("ACE_UPIPE_Stream::control");
00039
00040 return ((ACE_UPIPE_Stream *) this)->stream_.control
00041 ((ACE_IO_Cntl_Msg::ACE_IO_Cntl_Cmds) cmd, val);
00042 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_SPIPE. Definition at line 45 of file UPIPE_Stream.cpp. References ACE_TRACE.
00046 {
00047 ACE_TRACE ("ACE_UPIPE_Stream::dump");
00048 }
|
|
|
Return the underlying I/O handle.
Reimplemented from ACE_IPC_SAP. Definition at line 7 of file UPIPE_Stream.i. References ACE_TRACE, and ACE_IPC_SAP::get_handle. Referenced by ACE_UPIPE_Acceptor::accept, and ACE_UPIPE_Connector::connect.
00008 {
00009 ACE_TRACE ("ACE_UPIPE_Stream::get_handle");
00010 return this->ACE_SPIPE::get_handle ();
00011 }
|
|
|
Return the remote address we are connected to.
Definition at line 73 of file UPIPE_Stream.cpp. References ACE_TRACE, and remote_addr_.
00074 {
00075 ACE_TRACE ("ACE_UPIPE_Stream::get_remote_addr");
00076 remote_sap = this->remote_addr_;
00077 return 0;
00078 }
|
|
||||||||||||||||
|
Recv a buffer of upto <n> bytes from the message queue. Returns -1 on error, else number of bytes read.
Definition at line 117 of file UPIPE_Stream.cpp. References ACE_TRACE, EWOULDBLOCK, ACE_Stream< ACE_SYNCH >::get, ACE_Message_Block::length, mb_last_, ACE_OS_String::memcpy, ACE_Message_Block::rd_ptr, ACE_Message_Block::release, and stream_.
00120 {
00121 ACE_TRACE ("ACE_UPIPE_Stream::recv");
00122 // Index in buffer.
00123 size_t bytes_read = 0;
00124
00125 while (bytes_read < n)
00126 if (this->mb_last_ != 0)
00127 {
00128 // We have remaining data in our last read Message_Buffer.
00129 size_t this_len = this->mb_last_->length ();
00130 if (this_len < n)
00131 {
00132 // The remaining data is not enough.
00133
00134 ACE_OS::memcpy ((void *) &buffer[bytes_read],
00135 this->mb_last_->rd_ptr (),
00136 this_len);
00137 bytes_read += this_len;
00138 this->mb_last_ = this->mb_last_->release (); // mb_last_ now 0
00139 return bytes_read;
00140 }
00141 else
00142 {
00143 // The remaining data is at least enough. If there's
00144 // more, we'll get it the next time through.
00145 ACE_OS::memcpy (&buffer[bytes_read],
00146 this->mb_last_->rd_ptr (),
00147 n);
00148 bytes_read += n;
00149
00150 // Advance rd_ptr.
00151 this->mb_last_->rd_ptr (n);
00152
00153 if (this->mb_last_->length () == 0)
00154 // Now the Message_Buffer is empty.
00155 this->mb_last_ = this->mb_last_->release ();
00156 }
00157 }
00158 else
00159 {
00160 // We have to get a new Message_Buffer from our stream.
00161 int result = this->stream_.get (this->mb_last_, timeout);
00162
00163 if (result == -1)
00164 {
00165 if (errno == EWOULDBLOCK && bytes_read > 0)
00166 // Return the number of bytes read before we timed out.
00167 return bytes_read;
00168 else
00169 return -1;
00170 }
00171 }
00172
00173 return bytes_read;
00174 }
|
|
||||||||||||
|
Recv a message from the message queue. Returns -1 on error, else 0.
Definition at line 88 of file UPIPE_Stream.cpp. References ACE_Stream< ACE_SYNCH >::get, and stream_. Referenced by ACE_UPIPE_Connector::connect, and recv_n.
|
|
||||||||||||||||
|
Recv a buffer of exactly <n> bytes from the message queue. Returns -1 on error, else the number of bytes read.
Definition at line 202 of file UPIPE_Stream.cpp. References ACE_TRACE, recv, and ssize_t.
00205 {
00206 ACE_TRACE ("ACE_UPIPE_Stream::recv_n");
00207 size_t bytes_read;
00208 ssize_t len = 0;
00209
00210 for (bytes_read = 0;
00211 bytes_read < n;
00212 bytes_read += len)
00213 {
00214 len = this->recv (buf + bytes_read,
00215 n - bytes_read,
00216 timeout);
00217 if (len == -1)
00218 return -1;
00219 else if (len == 0)
00220 break;
00221 }
00222
00223 return bytes_read;
00224 }
|
|
||||||||||||||||
|
Send a buffer of <n> bytes through the message queue. Returns -1 on error, else number of bytes sent.
Definition at line 97 of file UPIPE_Stream.cpp. References ACE_NEW_RETURN, ACE_TRACE, ACE_Message_Block::copy, ACE_Stream< ACE_SYNCH >::put, ssize_t, and stream_.
00100 {
00101 ACE_TRACE ("ACE_UPIPE_Stream::send");
00102
00103 ACE_Message_Block *mb_p;
00104 ACE_NEW_RETURN (mb_p,
00105 ACE_Message_Block (n),
00106 -1);
00107 mb_p->copy (buffer, n);
00108 return
00109 this->stream_.put (mb_p, timeout) == -1
00110 ? -1
00111 : ACE_static_cast (ssize_t, n);
00112 }
|
|
||||||||||||
|
Send a message through the message queue. Returns -1 on error, else 0.
Definition at line 81 of file UPIPE_Stream.cpp. References ACE_TRACE, ACE_Stream< ACE_SYNCH >::put, and stream_. Referenced by ACE_UPIPE_Acceptor::accept, and send_n.
|
|
||||||||||||||||
|
Send a buffer of exactly <n> bytes to the message queue. Returns -1 on error, else number of bytes written (which should == n).
Definition at line 177 of file UPIPE_Stream.cpp. References ACE_TRACE, send, and ssize_t.
00180 {
00181 ACE_TRACE ("ACE_UPIPE_Stream::send_n");
00182
00183 size_t bytes_written;
00184 ssize_t len = 0;
00185
00186 for (bytes_written = 0;
00187 bytes_written < n;
00188 bytes_written += len)
00189 {
00190 len = this->send (buf + bytes_written,
00191 n - bytes_written,
00192 timeout);
00193
00194 if (len == -1)
00195 return -1;
00196 }
00197
00198 return bytes_written;
00199 }
|
|
|
Definition at line 43 of file UPIPE_Stream.h. |
|
|
Definition at line 44 of file UPIPE_Stream.h. |
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_SPIPE. Definition at line 104 of file UPIPE_Stream.h. |
|
|
To hold the last ACE_Message_Block read out of the stream. Thus allowing subsequent reads from one ACE_Message_Block.
Definition at line 112 of file UPIPE_Stream.h. Referenced by recv, and ~ACE_UPIPE_Stream. |
|
|
Keep track of whether the sender and receiver have both shut down.
Definition at line 123 of file UPIPE_Stream.h. Referenced by ACE_UPIPE_Acceptor::accept, close, and ACE_UPIPE_Connector::connect. |
|
|
Address of who we are connected to.
Definition at line 115 of file UPIPE_Stream.h. Referenced by ACE_UPIPE_Acceptor::accept, ACE_UPIPE_Connector::connect, and get_remote_addr. |
|
|
Stream component used by the <UPIPE_Acceptor> and <UPIPE_Connector> to link together two UPIPE_Streams.
Definition at line 119 of file UPIPE_Stream.h. Referenced by ACE_UPIPE_Acceptor::accept, close, recv, and send. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002