Abstract interface for all socket connections. More...
Inherits BDataIO.
Inherited by BDatagramSocket, and BSocket.
Public Member Functions | |
| BAbstractSocket () | |
| Default constructor. | |
| BAbstractSocket (const BAbstractSocket &other) | |
| Copy constructor. | |
| virtual | ~BAbstractSocket () |
| Destructor. | |
| virtual void | Disconnect () |
| Close the connection. | |
| status_t | InitCheck () const |
| Check connection status. | |
| virtual bool | IsBound () const |
| virtual bool | IsConnected () const |
| virtual const BNetworkAddress & | Local () const |
| gets the local address for this socket | |
| virtual size_t | MaxTransmissionSize () const |
| Return the maximal size of a transmission on this socket. | |
| virtual const BNetworkAddress & | Peer () const |
| gets the peer address | |
| virtual status_t | SetTimeout (bigtime_t timeout) |
| sets the read and write timeout | |
| int | Socket () const |
| get the underlying socket descriptor | |
| virtual bigtime_t | Timeout () const |
| gets the socket timeout | |
| virtual status_t | WaitForReadable (bigtime_t timeout=B_INFINITE_TIMEOUT) const |
| wait for incoming data | |
| virtual status_t | WaitForWritable (bigtime_t timeout=B_INFINITE_TIMEOUT) const |
| wait until writing is possible | |
Public Member Functions inherited from BDataIO | |
| BDataIO () | |
| This constructor does nothing. | |
| virtual | ~BDataIO () |
| This destructor does nothing. | |
| virtual status_t | Flush () |
| Writes pending data to underlying storage. | |
| virtual ssize_t | Read (void *buffer, size_t size) |
| Reads data from the object into a buffer. | |
| status_t | ReadExactly (void *buffer, size_t size, size_t *_bytesRead=NULL) |
| Reads an exact amount of data from the object into a buffer. | |
| virtual ssize_t | Write (const void *buffer, size_t size) |
| Writes data from a buffer to the object. | |
| status_t | WriteExactly (const void *buffer, size_t size, size_t *_bytesWritten=NULL) |
| Writes an exact amount of data from a buffer to the object. | |
Protected Member Functions | |
| status_t | Bind (const BNetworkAddress &local, bool reuseAddr, int type) |
| binds the socket to the given address | |
| status_t | Connect (const BNetworkAddress &peer, int type, bigtime_t timeout=B_INFINITE_TIMEOUT) |
| Connect the socket to the given peer. | |
Abstract interface for all socket connections.
BAbstractSocket provides a common interface for all socket-based communication streams. These include BDatagramSocket, BSocket, BSecureSocket and BServerSocket.
BAbstractSocket implements common behavior between these different socket types. This includes management of a BSD socket integer handle, knowledge of the local and remote network addresses, as well as the connection state.
| BAbstractSocket::BAbstractSocket | ( | ) |
Default constructor.
Creates an uninitialized socket in disconnected and unbound state.
| BAbstractSocket::BAbstractSocket | ( | const BAbstractSocket & | other | ) |
Copy constructor.
The copied object accesses the same underlying socket.
|
virtual |
Destructor.
|
protected |
binds the socket to the given address
If the socket was already bound, the previous binding is removed.
| local | the local address to bind |
| reuseAddr | if true, non-zero requests reuse local address |
| type | the socket type |
|
protected |
Connect the socket to the given peer.
The socket is disconnected from any previous connections.
| peer | the peer to connect to |
| type | the socket type |
| timeout | The timeout in microseconds or B_INFINITE_TIMEOUT. This is used for subsequent reads and writes as well. |
|
virtual |
Close the connection.
The socket becomes disconnected and unbound. You can Connect or Bind it again, either to the same or another peer.
| status_t BAbstractSocket::InitCheck | ( | ) | const |
Check connection status.
|
virtual |
A socket becomes bound when Bind succeeds, and stops being bound when Disconnect is called.
|
virtual |
A socket becomes connected when Connect succeeds, and disconnected when Disconnect is called.
|
virtual |
gets the local address for this socket
This gives useful results only if the socket is either connected or bound. Otherwise, an uninitialized address is returned.
|
virtual |
Return the maximal size of a transmission on this socket.
The default implementation always returns SSIZE_MAX, but subclasses may restrict this to a smaller size.
Reimplemented in BDatagramSocket.
|
virtual |
gets the peer address
This gives useful results only if the socket is either connected or bound. Otherwise, an uninitialized address is returned.
sets the read and write timeout
A negative value disables timeouts, so the Read and Write calls will wait until data is available or can be sent.
| timeout | The timeout in microseconds, or B_INFINITE_TIMEOUT. |
| int BAbstractSocket::Socket | ( | ) | const |
get the underlying socket descriptor
The BSD socket descriptor can be used to modify advanced connection paramters using the POSIX socket API.
|
virtual |
gets the socket timeout
wait for incoming data
Wait until data comes in, or the timeout expires. After this function returns B_OK, Read can be called without blocking.
| timeout | the timeout in microseconds, or B_INFINITE_TIMEOUT |
wait until writing is possible
Wait until the socket becomes ready for writing, or the timeout expires. After this function returns B_OK, Write can be called without blocking.
| timeout | the timeout in microseconds, or B_INFINITE_TIMEOUT |