#include <network.hh>
Inheritance diagram for atoms::StreamSocket:


Stream sockets are reliable, character-based, connection-based sockets. Every packet sent will be received exactly once, in order. If the connection is lost, an error will (eventually) be signalled. The boundaries of packets is unimportant; they're all combined into the stream.
There's once exception to this rule: out-of-band data. This is not yet supported.
Definition at line 357 of file network.hh.
[NOHEADER] | |
| StreamSocket (int _fd, int _flags) | |
| boost::shared_ptr< StreamSocket > | create (int _fd, int _flags) |
Public Types | |
| typedef boost::function< void(boost::shared_ptr< StreamSocket >) | AcceptFunction ) |
| enum | ShutdownType { sRead = SHUT_RD, sWrite = SHUT_WR, sReadWrite = SHUT_RDWR } |
| enum | OpenFlags { oRead = O_RDONLY, oWrite = O_WRONLY, oReadWrite = O_RDWR, oCreate = O_CREAT, oExclusive = O_EXCL, oNoctty = O_NOCTTY, oTrunc = O_TRUNC, oAppend = O_APPEND, oNonBlock = O_NONBLOCK, oSync = O_SYNC, oDataSync = O_DSYNC, oReadSync = O_RSYNC } |
| enum | State { sClosed, sCreated, sConnecting, sOpen, sListening } |
| All possible states. More... | |
| enum | Type { tUnspecified = 0, tStream = SOCK_STREAM, tDatagram = SOCK_DGRAM, tSequentialPacket = SOCK_SEQPACKET, tRaw = SOCK_RAW, tReliableDatagram = SOCK_RDM } |
| The type of a socket. More... | |
| enum | Protocol { pUnspecified = 0 } |
Public Member Functions | |
| void | close () |
| Closes the stream if it is not already closed. | |
| void | listen (uint numListen=5) |
| Listens for connections. | |
| boost::shared_ptr< StreamSocket > | accept (SocketAddress &a) |
| Accepts a connection. | |
| void | acceptContinuously (const boost::shared_ptr< IOPoller > &p, const AcceptFunction &onAccept, const boost::function< void(const IOError &)> &onError) |
| Asynchronously accepts connections. | |
| void | shutdown (ShutdownType t) |
| Shuts down part of the connection. | |
| virtual bool | isOpen () const |
| Returns true iff the stream is fully open. | |
| virtual bool | isClosed () const |
| Returns true iff the stream is fully closed. | |
| virtual bool | isReadable () const |
| Returns true iff the stream is readable. | |
| virtual bool | isWritable () const |
| Returns true iff the stream is writable. | |
| virtual bool | isSeekable () const |
| Returns true iff the stream is seekable. | |
| virtual void | close (bool ignoreError=false) |
| Close the descriptor. | |
| size_t | read (void *buf, size_t count) |
| Reads one to count bytes into buf. | |
| size_t | write (const void *buf, size_t count) |
| Writes one to count bytes from buf. | |
| State | getState () const |
| Gets the current state of the descriptor. | |
| bool | isBlocking () const |
| Returns true iff blocking mode is set. | |
| void | setBlocking (bool newval) |
| Set the blocking status. | |
| void | setCloseOnExec (bool newval) |
| Sets whether or not this descriptor will be closed on Process::exec(). | |
| void | pollForReadAvailability (const boost::shared_ptr< IOPoller > &poller, const boost::function< void()> &onReadAvailable, const boost::function< void(const IOError &)> &onError) |
| Calls a function when read operations are likely to not block. | |
| void | pollForWriteAvailability (const boost::shared_ptr< IOPoller > &poller, const boost::function< void()> &onWriteAvailable, const boost::function< void(const IOError &)> &onError) |
| Calls a function when write operations are likely to not block. | |
| void | cancelPoll (const boost::shared_ptr< IOPoller > &poller) |
| Cancels a poll for read or write availability. | |
| int | getFD () const |
| Returns the actual file descriptor, or -1 if the stream is closed. | |
| virtual int | detach () |
| Detaches from the file without closing. | |
| void | setTimeout (const Timespan &ts) |
| Sets a timeout for read and write operations. | |
| void | setReuse (bool reuse=true) |
| Allows multiple uses of the same socket address. | |
| void | getAddress (SocketAddress &a) |
| Gets this socket's address. | |
| void | getPeerAddress (SocketAddress &a) |
| Gets peer's address. | |
| void | bind (const SocketAddress &a) |
| Binds the socket to the given address. | |
| bool | connect (const SocketAddress &s) |
| Opens a connection. | |
| void | connect (const SocketAddress &s, const boost::shared_ptr< IOPoller > &poller, const boost::function< void()> &onConnect, const boost::function< void(const IOError &)> &onError) |
| Opens a connection asynchronously. | |
| bool | connectAgain () |
| Checks on a connection in progress. | |
Static Public Member Functions | |
| boost::shared_ptr< StreamSocket > | create (SocketAddress::Domain domain, Protocol p=pUnspecified) |
| Creates a new stream socket in the given domain. | |
| std::pair< boost::shared_ptr< StreamSocket >, boost::shared_ptr< StreamSocket > > | createPair () |
| Creates a pair of indistinguishable mutually-connected stream sockets. | |
| boost::shared_ptr< UNIXStream > | open (const char *path, OpenFlags f, mode_t mode=0666) |
| Opens a stream from the filesystem. | |
| void | createFIFO (const char *path, mode_t mode) |
| Creates a FIFO. | |
| template<typename DescriptorType> boost::shared_ptr< DescriptorType > | attach (int fd) |
| Attaches to an open file descriptor. | |
Static Public Attributes | |
| const size_t | MAX_ATOMIC_SIZE = PIPE_BUF |
Protected Member Functions | |
| virtual Type | getType () |
| void | setupFlags () |
Protected Attributes | |
| boost::weak_ptr< IOHandle > | thisWeak |
| A weak pointer to 'this' for source in IOError. | |
| State | state |
| The state of this descriptor. | |
| int | fd |
| The file descriptor (-1 if closed). | |
| int | flags |
Descriptor flags, retrieved with fcntl(fd,F_GETFL). | |
Private Member Functions | |
| StreamSocket (int fd, State state) | |
| StreamSocket (SocketAddress::Domain domain, Protocol p) | |
| void | tryAccept (const AcceptFunction &, const boost::function< void(const IOError &)> &) |
Static Private Attributes | |
| DebugLogger | LOGGER |
Friends | |
| class | Socket |
| Attach needs access to our private constructors. | |
|
|
Definition at line 429 of file network.hh. Referenced by acceptContinuously(), and tryAccept(). |
|
|
|
|
|
Definition at line 173 of file network.hh. |
|
|
Definition at line 439 of file network.hh. |
|
|
All possible states.
Definition at line 41 of file unixio.hh. Referenced by atoms::UNIXDescriptor::getState(). |
|
|
The type of a socket. Bad values are below zero; good values above zero. Definition at line 164 of file network.hh. |
|
||||||||||||
|
Definition at line 364 of file network.hh. References atoms::UNIXDescriptor::setupFlags(). Referenced by create(). |
Here is the call graph for this function:

|
||||||||||||
|
For internal use only.
Definition at line 375 of file network.hh. |
|
||||||||||||
|
Definition at line 388 of file network.hh. |
|
|
Accepts a connection. The blocking status of the new socket will be inherited from this one. It is otherwise as the operating system creates it.
Definition at line 244 of file network.cc. References create(), atoms::SocketAddress::getAddr(), atoms::SocketAddress::getAllocatedSize(), atoms::UNIXDescriptor::isBlocking(), listen(), atoms::DebugLogger::log(), and LOGGER. Referenced by tryAccept(). |
Here is the call graph for this function:

|
||||||||||||||||
|
Asynchronously accepts connections.
Definition at line 374 of file network.cc. References AcceptFunction, listen(), and atoms::UNIXDescriptor::pollForReadAvailability(). |
Here is the call graph for this function:

|
||||||||||
|
Attaches to an open file descriptor.
Definition at line 420 of file unixio.hh. References atoms::UNIXDescriptor::attachInt(). |
Here is the call graph for this function:

|
|
Binds the socket to the given address.
Definition at line 199 of file network.cc. References atoms::SocketAddress::getAddr(), atoms::SocketAddress::getUsedSize(), atoms::DebugLogger::log(), atoms::DebugLogger::logFatal(), and atoms::Socket::LOGGER. |
Here is the call graph for this function:

|
|
Cancels a poll for read or write availability.
Definition at line 175 of file unixio.cc. References atoms::UNIXDescriptor::fd, atoms::DebugLogger::log(), atoms::UNIXDescriptor::LOGGER, atoms::UNIXDescriptor::pollers, atoms::UNIXDescriptor::sClosed, and atoms::UNIXDescriptor::state. Referenced by atoms::BufferedStreamFilter::tryFlush(). |
Here is the call graph for this function:

|
|
Close the descriptor.
Definition at line 41 of file unixio.cc. References atoms::UNIXDescriptor::disassociateFromPollers(), atoms::UNIXDescriptor::fd, atoms::DebugLogger::log(), atoms::DebugLogger::logFatal(), atoms::UNIXDescriptor::LOGGER, atoms::UNIXDescriptor::sClosed, and atoms::UNIXDescriptor::state. Referenced by atoms::UNIXDescriptor::~UNIXDescriptor(). |
Here is the call graph for this function:

|
|
Closes the stream if it is not already closed.
Reimplemented from atoms::UNIXStream. Definition at line 392 of file network.hh. |
|
||||||||||||||||||||
|
Opens a connection asynchronously. This functions like connect(const SocketAddress&) but automatically handles the connectAgain() and passes success or failure to a callback.
Definition at line 320 of file network.cc. References atoms::Socket::connect(), atoms::DebugLogger::log(), atoms::Socket::LOGGER, and atoms::UNIXDescriptor::pollForWriteAvailability(). |
Here is the call graph for this function:

|
|
Opens a connection. For a stream socket, a connection will be negotiated. For datagram or raw sockets, this merely restricts what can be received and sets the default destination.
Definition at line 270 of file network.cc. References atoms::Socket::connectError(), atoms::SocketAddress::getAddr(), and atoms::SocketAddress::getUsedSize(). Referenced by atoms::Socket::connect(). |
Here is the call graph for this function:

|
|
Checks on a connection in progress.
Definition at line 283 of file network.cc. References atoms::Socket::connectError(). Referenced by atoms::Socket::tryConnect(). |
Here is the call graph for this function:

|
||||||||||||
|
Creates a new stream socket in the given domain.
Definition at line 395 of file network.hh. References StreamSocket(). |
Here is the call graph for this function:

|
||||||||||||
|
For internal use only.
Reimplemented from atoms::UNIXStream. Definition at line 381 of file network.hh. References StreamSocket(). Referenced by accept(), and createPair(). |
Here is the call graph for this function:

|
||||||||||||
|
Creates a FIFO. Use UNIXStream::open to actually open it.
|
|
|
Creates a pair of indistinguishable mutually-connected stream sockets. The sockets will be in the dUnix domain, which is most broadly supported. Definition at line 363 of file network.cc. References create(), atoms::DebugLogger::log(), atoms::DebugLogger::logFatal(), LOGGER, and std::make_pair(). |
Here is the call graph for this function:

|
|
Detaches from the file without closing.
Definition at line 65 of file unixio.cc. References atoms::UNIXDescriptor::disassociateFromPollers(), atoms::UNIXDescriptor::fd, atoms::UNIXDescriptor::sClosed, and atoms::UNIXDescriptor::state. |
Here is the call graph for this function:

|
|
Gets this socket's address.
Definition at line 169 of file network.cc. References atoms::SocketAddress::getAddr(), atoms::SocketAddress::getAllocatedSize(), atoms::DebugLogger::logFatal(), and atoms::Socket::LOGGER. |
Here is the call graph for this function:

|
|
Returns the actual file descriptor, or -1 if the stream is closed. Use this with caution. UNIXDescriptor doesn't like to share the descriptor with the other chidlren.
Definition at line 183 of file unixio.cc. References atoms::UNIXDescriptor::fd, atoms::UNIXDescriptor::sClosed, and atoms::UNIXDescriptor::state. |
|
|
Gets peer's address.
|
|
|
Gets the current state of the descriptor.
Definition at line 103 of file unixio.hh. References atoms::UNIXDescriptor::state, and atoms::UNIXDescriptor::State. |
|
|
Definition at line 457 of file network.hh. |
|
|
Returns true iff blocking mode is set.
Definition at line 103 of file unixio.cc. References atoms::UNIXDescriptor::flags, atoms::UNIXDescriptor::sClosed, and atoms::UNIXDescriptor::state. Referenced by accept(), atoms::UNIXStream::read(), and atoms::UNIXStream::write(). |
|
|
Returns true iff the stream is fully closed. Streams may be an intermediate state. For example, stream sockets can be in a 'connecting' state.
Implements atoms::Stream. |
|
|
Returns true iff the stream is fully open. Streams may be an intermediate state. For example, stream sockets can be in a 'connecting' state.
Implements atoms::Stream. |
|
|
Returns true iff the stream is readable.
Implements atoms::Stream. Definition at line 196 of file unixio.cc. Referenced by atoms::UNIXStream::read(). |
|
|
Returns true iff the stream is seekable.
Implements atoms::Stream. Reimplemented in atoms::SeekableUNIXStream. |
|
|
Returns true iff the stream is writable.
Implements atoms::Stream. Definition at line 203 of file unixio.cc. Referenced by atoms::UNIXStream::write(). |
|
|
Listens for connections.
Definition at line 237 of file network.cc. Referenced by accept(), and acceptContinuously(). |
|
||||||||||||||||
|
Opens a stream from the filesystem.
Definition at line 292 of file unixio.cc. References atoms::DebugLogger::logFatal(), and atoms::UNIXStream::LOGGER. |
Here is the call graph for this function:

|
||||||||||||||||
|
Calls a function when read operations are likely to not block. "Read operations" includes indicating end of stream and, for listening stream sockets, accepting new connections. It will call the function when reads are likely to succeed. If the function throws an IOBlockError, it will be called again. Definition at line 135 of file unixio.hh. References atoms::UNIXDescriptor::pollForAvailability(). Referenced by acceptContinuously(), and atoms::BufferedStreamFilter::pollForReadAvailability2(). |
Here is the call graph for this function:

|
||||||||||||||||
|
Calls a function when write operations are likely to not block. It will call the function when writes are likely to succeed. If the function throws an IOBlockError, it will be called again. Definition at line 147 of file unixio.hh. References atoms::UNIXDescriptor::pollForAvailability(). Referenced by atoms::Socket::connect(), and atoms::BufferedStreamFilter::tryFlush(). |
Here is the call graph for this function:

|
||||||||||||
|
Reads one to count bytes into buf.
Implements atoms::Stream. Definition at line 209 of file unixio.cc. References std::count(), atoms::UNIXDescriptor::isBlocking(), atoms::UNIXStream::isReadable(), atoms::DebugLogger::log(), atoms::UNIXStream::LOGGER, and atoms::UNIXStream::rwError(). |
Here is the call graph for this function:

|
|
Set the blocking status.
Definition at line 108 of file unixio.cc. References atoms::UNIXDescriptor::fd, atoms::UNIXDescriptor::flags, atoms::UNIXDescriptor::sClosed, and atoms::UNIXDescriptor::state. |
|
|
Sets whether or not this descriptor will be closed on Process::exec(). This is a per-descriptor status (not per underlying object.)
Definition at line 119 of file unixio.cc. References atoms::UNIXDescriptor::fd, atoms::DebugLogger::logFatal(), atoms::UNIXDescriptor::LOGGER, atoms::UNIXDescriptor::sClosed, and atoms::UNIXDescriptor::state. |
Here is the call graph for this function:

|
|
Allows multiple uses of the same socket address.
Sets the Definition at line 229 of file network.cc. |
|
|
Sets a timeout for read and write operations. This is used in servers to prune inactive connections. It provides the same concept with two different implementations:
Definition at line 75 of file network.cc. References atoms::DebugLogger::logFatal(), atoms::Socket::LOGGER, and NULL. |
Here is the call graph for this function:

|
|
Definition at line 97 of file unixio.cc. References atoms::UNIXDescriptor::fd, and atoms::UNIXDescriptor::flags. Referenced by atoms::Socket::Socket(), StreamSocket(), and atoms::UNIXDescriptor::UNIXDescriptor(). |
|
|
Shuts down part of the connection. It's recommended for servers to shut down the write half of the connection and wait for the other end to close its write half. See the note at close. All subsequent operations of this type will fail with a StreamEndError.
Definition at line 404 of file network.cc. References atoms::DebugLogger::logFatal(), and LOGGER. |
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 385 of file network.cc. References accept(), and AcceptFunction. |
Here is the call graph for this function:

|
||||||||||||
|
Writes one to count bytes from buf.
Implements atoms::Stream. Definition at line 233 of file unixio.cc. References std::count(), atoms::UNIXDescriptor::isBlocking(), atoms::UNIXStream::isWritable(), atoms::DebugLogger::log(), atoms::UNIXStream::LOGGER, and atoms::UNIXStream::rwError(). |
Here is the call graph for this function:

|
|
Attach needs access to our private constructors.
Definition at line 359 of file network.hh. |
|
|
|
Descriptor flags, retrieved with
Definition at line 183 of file unixio.hh. Referenced by atoms::UNIXDescriptor::isBlocking(), atoms::UNIXDescriptor::setBlocking(), and atoms::UNIXDescriptor::setupFlags(). |
|
|
Reimplemented from atoms::Socket. Referenced by accept(), createPair(), and shutdown(). |
|
|
|
|
|
|
A weak pointer to 'this' for source in IOError.
|
1.3.5