32# include <sys/ioctl.h>
38# include <sys/filio.h>
52#define BYTES_LEFT_IN_SOCKBUF(s) ((s).eof () ? -1 : (s).in_avail ())
59#define BYTES_LEFT_IN_SIN (cin.eof () ? -1 : cin.rdbuf ()->in_avail ())
294 operator void* ()
const;
345 return (4 +
s_.length () +
s_.length () % 4);
396 return (*
this) << (
char)
c_;
402 return (*
this) << (
char)
c_;
558Socket::operator
void*()
const
560 return fail() ? (
void *)0 : (
void *)(-1);
Address is an abstraction for INET or UNIX-domain address data type.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
#define BAD_HANDLER
Sort out WIN32/mingw oddities.
Streambuf class is based on Standard C++ iostream streambuf class.
A wrapper class to provide AutoPtr with reference semantics.
bool fail() const
Indicates that earlier extraction opeartion has failed to match the required pattern of input.
int clear_fd_options(long flags_)
Gateway method for clearing file descriptor options.
Socket & operator>>(char &c)
Input of built-in char type. The value will be XDR-decoded.
virtual Streambuf * rdbuf()
Return a pointer to the Streambuf associated with the stream.
virtual const int getDomain() const =0
Get socket domain.
int m_type
Socket domain type.
void dumpState() const
Write state bits of the socket to the log file.
static size_t xdr_length(const std::string &s_)
Give the true length of the XDR-encoded STL string.
void setstate(iostate flag_)
Set socket state to flag_ by adding flag_ to the existing state.
static string decode_fcntl_flags(long mask_)
Decipher flags packed into mask_ used in fcntl() call.
virtual handler_t getHandler() const =0
Get file descriptor.
virtual bool connect(const Address &address_)
Make a connection.
static void close_handler(handler_t &socket_)
Close socket endpoint in a portable way.
virtual bool close()=0
Close socket.
Socket(const Socket &)
The copy constructor and assignment operator are private to prevent copying of Socket objects,...
Socket & operator=(const Socket &)
iostate rdstate() const
Retrieve state of the socket.
int set_fd_options(long flags_)
Gateway method for setting file descriptor options.
bool turnOptionOff(opt_t opt_)
Disable socket option.
virtual int read(char *buf_, const u_int size_)
Read expected number of bytes from the socket.
int set_option(int level_, int optname_, int val_)
Gateway method of setting socket options.
bool turnOptionOn(opt_t opt_)
Enable socket option.
@ reuseaddr
Allow local address reuse.
@ sndlowat
The send low-water mark si the amount of available space that must exist in the socket send buffer fo...
@ rcvlowat
The receiver low-water mark is the amount of data that must be in the socket receive buffer for selec...
@ nonblocking
Set Socket to a non-blocking mode (O_RDWR|O_NONBLOCK).
static bool is_little_endian()
Determine the endianess of the platform we are on.
bool eof() const
An earlier extraction operation has encountered the end of file of the input stream (peer closed its ...
handler_t m_fd
File descriptor.
bool bad() const
Socket fd == -1 or read/write error occured or some loss of integrity on assosiated stream buffer.
int getOption(opt_t opt_) const
Get current value of a socket option.
virtual bool bind(const Address &my_address_)=0
Server binds listening socket to its local well-known port.
bool good() const
Indicates no error on the socket.
int ignore(int n_=INT_MAX, int delim_=EOF)
Extracts bytes and discards them.
void clear(iostate state_=Socket::goodbit)
Clear the socket state. Closed socket remains in bad state.
Socket & operator<<(char c)
Output of built-in char type. The value will be XDR-encoded.
virtual ~Socket()
Destructor.
virtual bool open(const int domain_)=0
Open socket.
virtual Streambuf * rdbuf(Streambuf *)
Virtual function that sets new socket buffer and returns the old one.
virtual Socket & flush()
This function simply calls the public "synchronizing" function rdbuf()->pubsync() (assuming the assoc...
io_state_t
State bits: goodbit, eofbit, failbit, badbit.
@ eofbit
indicates that an input operation reached the end of an input sequence
@ goodbit
indicates that socket is ready for use
@ badbit
indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...
@ failbit
indicates that an input operation failed to read the expected characters, or that an output operation...
static const int PGSIZE
Size of bytes of a kernel page.
IOState m_state
Control state of the socket.
bool setOption(opt_t opt_, int arg_)
Set socket option to value required.
virtual int write(const char *buf_, const u_int size_)
Write specified number of bytes to the socket.
bool operator!() const
Alias to fail()
virtual int in_avail() const =0
This function returns the number of characters immediately available in the get area of the underly...
int getBytesAvail(void) const
Return number of bytes available in socket receive buffer.
Socket & ends(Socket &os_)
ends manipulator.
Socket & endl(Socket &os_)
endl manipulator.
@ SOCKTRACE
Extended Socket & friends messages
Socket & flush(Socket &os_)
flush manipulator.
bool is_valid_handler(handler_t socket_)
Detect socket() error in a portable way.
void disable_handler(handler_t &socket_)
Set socket descriptor to invalid value in a portable way.